U
    h                     @   sH   d Z ddlmZmZmZ ddlmZmZ ddlm	Z	 G dd deZ
dS )zUtil that calls Twilio.    )AnyDictOptional)	BaseModelroot_validator)get_from_dict_or_envc                   @   s   e Zd ZU dZeed< dZee ed< dZ	ee ed< dZ
ee ed< G dd dZed	d
eedddZeeedddZdS )TwilioAPIWrappera  Messaging Client using Twilio.

    To use, you should have the ``twilio`` python package installed,
    and the environment variables ``TWILIO_ACCOUNT_SID``, ``TWILIO_AUTH_TOKEN``, and
    ``TWILIO_FROM_NUMBER``, or pass `account_sid`, `auth_token`, and `from_number` as
    named parameters to the constructor.

    Example:
        .. code-block:: python

            from langchain_community.utilities.twilio import TwilioAPIWrapper
            twilio = TwilioAPIWrapper(
                account_sid="ACxxx",
                auth_token="xxx",
                from_number="+10123456789"
            )
            twilio.run('test', '+12484345508')
    clientNaccount_sid
auth_tokenfrom_numberc                   @   s   e Zd ZdZdZdS )zTwilioAPIWrapper.ConfigFZforbidN)__name__
__module____qualname__Zarbitrary_types_allowedextra r   r   H/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/utilities/twilio.pyConfig.   s   r   T)pre)valuesreturnc                 C   sh   zddl m} W n tk
r,   tdY nX t|dd}t|dd}t|dd	|d< ||||d
< |S )z?Validate that api key and python package exists in environment.r   )ClientzTCould not import twilio python package. Please install it with `pip install twilio`.r
   ZTWILIO_ACCOUNT_SIDr   ZTWILIO_AUTH_TOKENr   ZTWILIO_FROM_NUMBERr	   )Ztwilio.restr   ImportErrorr   )clsr   r   r
   r   r   r   r   validate_environment2   s    
  z%TwilioAPIWrapper.validate_environment)bodytor   c                 C   s   | j jj|| j|d}|jS )a  Run body through Twilio and respond with message sid.

        Args:
            body: The text of the message you want to send. Can be up to 1,600
                characters in length.
            to: The destination phone number in
                [E.164](https://www.twilio.com/docs/glossary/what-e164) format for
                SMS/MMS or
                [Channel user address](https://www.twilio.com/docs/sms/channels#channel-addresses)
                for other 3rd-party channels.
        )from_r   )r	   messagescreater   Zsid)selfr   r   messager   r   r   runD   s    zTwilioAPIWrapper.run)r   r   r   __doc__r   __annotations__r
   r   strr   r   r   r   r   r   r"   r   r   r   r   r   	   s   
r   N)r#   typingr   r   r   Zlangchain_core.pydantic_v1r   r   Zlangchain_core.utilsr   r   r   r   r   r   <module>   s   