Navigation

twilioService.send()

On this page

Definition

twilioService.send(args)

Sends a text message to a specified phone number.

The send method has the following parameter:

Parameter Type Description
args document

A document of the following form:

{
    "to": <string>,   // recipient phone #
    "from": <string>, // sender phone #
    "body": <string>  // message
}

The fields of args are as follows:

Argument Type Description
to string The recipient’s phone number. This must be in E. 164 format
from string A phone number owned by your Twilio account. This must be in E. 164 format
body string The message to send.
Returns:Nothing.

Example

The following is an example using the twilioService.send function:

exports = function(message, recipient) {
    const twilio = context.services.get("my-twilio-service");
    twilio.send({
        to: recipient,
        from: "+15551234567",
        body: message
    });
};

This example assumes that a Twilio service has been created with the name “my-twilio-service”.

See also

Twilio examples.