Send SMS via Twilio

The f451 Communications module allows you to send SMS via the Twilio SMS service using a unified interface. In it’s simplest for form, you can send a plain text message to a given recipient. But you can also send a more complex message with attached images.

In order to use this service, you’ll need to set up an account with Twilio. Once that is done, you get your API key and other relevant account credentials.

Note

Please refer to the “Configuration files” section for more detailed information on configuration requirements for the Twilio messaging service.

Core features

  • Send SMSMessages can be text-only as well as include images.

  • Supports multiple ‘to’ phone numbersAllows you to send text messages to multiple recipients

Examples

Note

These examples use the send_message_via_sms() method. But you can also use the generic send_message() method with the same arguments.

Example – send simple SMS

1 comms = Comms(secrets, config)              # Initialize ``Comms`` with credentials
2                                             # and optional default settings
3 msg = "Hello world!"
4 attribs = {
5     "channels": "f451_twilio",
6     "to_phone": "+12125550000",
7 }
8
9 comms.send_message_via_sms(msg, attribs)    # Send SMS

Example – send SMS with attachments

 1 comms = Comms(secrets, config)              # Initialize ``Comms`` with credentials
 2                                             # and optional default settings
 3 msg = "Hello world!"
 4 attribs = {
 5     "channels": "f451_twilio",
 6     "to_phone": "+12125550000",
 7     "attachments": ["path/to/joker.jpg", "path/to/riddler.jpg"],
 8 }
 9
10 comms.send_message_via_sms(msg, attribs)    # Send SMS

Example – send SMS to multiple recipients

1 comms = Comms(secrets, config)              # Initialize ``Comms`` with credentials
2                                             # and optional default settings
3 msg = "Hello world!"
4 attribs = {
5     "channels": "f451_twilio",
6     "to_phone": ["+12125550000", "+12125551111"],
7 }
8
9 comms.send_message_via_sms(msg, attribs)    # Send SMS

Additional references