Class MessageCreator

    • Constructor Detail

      • MessageCreator

        public MessageCreator​(PhoneNumber to,
                              PhoneNumber from,
                              String body)
        Construct a new MessageCreator.
        Parameters:
        to - The destination phone number
        from - The phone number that initiated the message
        body - The text of the message you want to send. Can be up to 1,600 characters in length.
      • MessageCreator

        public MessageCreator​(String pathAccountSid,
                              PhoneNumber to,
                              PhoneNumber from,
                              String body)
        Construct a new MessageCreator.
        Parameters:
        pathAccountSid - The SID of the Account that will create the resource
        to - The destination phone number
        from - The phone number that initiated the message
        body - The text of the message you want to send. Can be up to 1,600 characters in length.
      • MessageCreator

        public MessageCreator​(PhoneNumber to,
                              PhoneNumber from,
                              List<URI> mediaUrl)
        Construct a new MessageCreator.
        Parameters:
        to - The destination phone number
        from - The phone number that initiated the message
        mediaUrl - The URL of the media to send with the message
      • MessageCreator

        public MessageCreator​(String pathAccountSid,
                              PhoneNumber to,
                              PhoneNumber from,
                              List<URI> mediaUrl)
        Construct a new MessageCreator.
        Parameters:
        pathAccountSid - The SID of the Account that will create the resource
        to - The destination phone number
        from - The phone number that initiated the message
        mediaUrl - The URL of the media to send with the message
      • MessageCreator

        public MessageCreator​(PhoneNumber to,
                              String messagingServiceSid,
                              String body)
        Construct a new MessageCreator.
        Parameters:
        to - The destination phone number
        messagingServiceSid - The SID of the Messaging Service you want to associate with the message.
        body - The text of the message you want to send. Can be up to 1,600 characters in length.
      • MessageCreator

        public MessageCreator​(String pathAccountSid,
                              PhoneNumber to,
                              String messagingServiceSid,
                              String body)
        Construct a new MessageCreator.
        Parameters:
        pathAccountSid - The SID of the Account that will create the resource
        to - The destination phone number
        messagingServiceSid - The SID of the Messaging Service you want to associate with the message.
        body - The text of the message you want to send. Can be up to 1,600 characters in length.
      • MessageCreator

        public MessageCreator​(PhoneNumber to,
                              String messagingServiceSid,
                              List<URI> mediaUrl)
        Construct a new MessageCreator.
        Parameters:
        to - The destination phone number
        messagingServiceSid - The SID of the Messaging Service you want to associate with the message.
        mediaUrl - The URL of the media to send with the message
      • MessageCreator

        public MessageCreator​(String pathAccountSid,
                              PhoneNumber to,
                              String messagingServiceSid,
                              List<URI> mediaUrl)
        Construct a new MessageCreator.
        Parameters:
        pathAccountSid - The SID of the Account that will create the resource
        to - The destination phone number
        messagingServiceSid - The SID of the Messaging Service you want to associate with the message.
        mediaUrl - The URL of the media to send with the message
    • Method Detail

      • setStatusCallback

        public MessageCreator setStatusCallback​(URI statusCallback)
        The URL we should call using the `status_callback_method` to send status information to your application. If specified, we POST these message status changes to the URL: `queued`, `failed`, `sent`, `delivered`, or `undelivered`. Twilio will POST its [standard request parameters](https://www.twilio.com/docs/sms/twiml#request-parameters) as well as some additional parameters including `MessageSid`, `MessageStatus`, and `ErrorCode`. If you include this parameter with the `messaging_service_sid`, we use this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/sms/services/api). URLs must contain a valid hostname and underscores are not allowed..
        Parameters:
        statusCallback - The URL we should call to send status information to your application
        Returns:
        this
      • setStatusCallback

        public MessageCreator setStatusCallback​(String statusCallback)
        The URL we should call using the `status_callback_method` to send status information to your application. If specified, we POST these message status changes to the URL: `queued`, `failed`, `sent`, `delivered`, or `undelivered`. Twilio will POST its [standard request parameters](https://www.twilio.com/docs/sms/twiml#request-parameters) as well as some additional parameters including `MessageSid`, `MessageStatus`, and `ErrorCode`. If you include this parameter with the `messaging_service_sid`, we use this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/sms/services/api). URLs must contain a valid hostname and underscores are not allowed..
        Parameters:
        statusCallback - The URL we should call to send status information to your application
        Returns:
        this
      • setApplicationSid

        public MessageCreator setApplicationSid​(String applicationSid)
        The SID of the application that should receive message status. We POST a `message_sid` parameter and a `message_status` parameter with a value of `sent` or `failed` to the [application](https://www.twilio.com/docs/usage/api/applications)'s `message_status_callback`. If a `status_callback` parameter is also passed, it will be ignored and the application's `message_status_callback` parameter will be used..
        Parameters:
        applicationSid - The application to use for callbacks
        Returns:
        this
      • setMaxPrice

        public MessageCreator setMaxPrice​(BigDecimal maxPrice)
        The maximum total price in US dollars that you will pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds `max_price`, the message will fail and a status of `Failed` is sent to the status callback. If `MaxPrice` is not set, the message cost is not checked..
        Parameters:
        maxPrice - The total maximum price up to 4 decimal places in US dollars acceptable for the message to be delivered.
        Returns:
        this
      • setProvideFeedback

        public MessageCreator setProvideFeedback​(Boolean provideFeedback)
        Whether to confirm delivery of the message. Set this value to `true` if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the [Message Feedback API](https://www.twilio.com/docs/sms/api/message-feedback). This parameter is `false` by default..
        Parameters:
        provideFeedback - Whether to confirm delivery of the message
        Returns:
        this
      • setValidityPeriod

        public MessageCreator setValidityPeriod​(Integer validityPeriod)
        How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds..
        Parameters:
        validityPeriod - The number of seconds that the message can remain in our outgoing queue.
        Returns:
        this
      • setForceDelivery

        public MessageCreator setForceDelivery​(Boolean forceDelivery)
        Reserved.
        Parameters:
        forceDelivery - Reserved
        Returns:
        this
      • setSmartEncoded

        public MessageCreator setSmartEncoded​(Boolean smartEncoded)
        Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be: `true` or `false`..
        Parameters:
        smartEncoded - Whether to detect Unicode characters that have a similar GSM-7 character and replace them
        Returns:
        this
      • setFrom

        public MessageCreator setFrom​(PhoneNumber from)
        A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) that is enabled for the type of message you want to send. Phone numbers or [short codes](https://www.twilio.com/docs/sms/api/short-codes) purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty..
        Parameters:
        from - The phone number that initiated the message
        Returns:
        this
      • setFrom

        public MessageCreator setFrom​(String from)
        A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) that is enabled for the type of message you want to send. Phone numbers or [short codes](https://www.twilio.com/docs/sms/api/short-codes) purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty..
        Parameters:
        from - The phone number that initiated the message
        Returns:
        this
      • setMessagingServiceSid

        public MessageCreator setMessagingServiceSid​(String messagingServiceSid)
        The SID of the [Messaging Service](https://www.twilio.com/docs/sms/services#send-a-message-with-copilot) you want to associate with the Message. Set this parameter to use the [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) you have configured and leave the `from` parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select the `from` phone number for delivery..
        Parameters:
        messagingServiceSid - The SID of the Messaging Service you want to associate with the message.
        Returns:
        this
      • setBody

        public MessageCreator setBody​(String body)
        The text of the message you want to send. Can be up to 1,600 characters in length..
        Parameters:
        body - The text of the message you want to send. Can be up to 1,600 characters in length.
        Returns:
        this
      • setMediaUrl

        public MessageCreator setMediaUrl​(List<URI> mediaUrl)
        The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient's device. [Other types](https://www.twilio.com/docs/sms/accepted-mime-types) of media are also accepted. The media size limit is 5MB. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada..
        Parameters:
        mediaUrl - The URL of the media to send with the message
        Returns:
        this
      • setMediaUrl

        public MessageCreator setMediaUrl​(URI mediaUrl)
        The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient's device. [Other types](https://www.twilio.com/docs/sms/accepted-mime-types) of media are also accepted. The media size limit is 5MB. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada..
        Parameters:
        mediaUrl - The URL of the media to send with the message
        Returns:
        this
      • setMediaUrl

        public MessageCreator setMediaUrl​(String mediaUrl)
        The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient's device. [Other types](https://www.twilio.com/docs/sms/accepted-mime-types) of media are also accepted. The media size limit is 5MB. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada..
        Parameters:
        mediaUrl - The URL of the media to send with the message
        Returns:
        this
      • create

        public Message create​(TwilioRestClient client)
        Make the request to the Twilio API to perform the create.
        Specified by:
        create in class Creator<Message>
        Parameters:
        client - TwilioRestClient with which to make the request
        Returns:
        Created Message