Implementing the Full SMS Lifecycle
A complete SMS integration does more than send. Every message goes through a lifecycle, and Connect records an event at each stage so your application can react to it.
You can build and test every stage for free, before your workspace goes live, using the Phone Simulator.
The lifecycle at a glance
Section titled “The lifecycle at a glance”- Send: You send a message and Connect accepts it:
sms.queued. - Delivery: The message is handed to the network (
sms.sent), then delivered (sms.delivered) or not (sms.failed, with a reason). - Reply: The recipient replies:
sms.received. See Replies for how recipients can reply. - Opt-out: The recipient replies
STOPor unsubscribes, and Connect adds their number to your suppression list:suppression.created. Future messages to them are not sent.
Every sms.* event carries the full message, so one handler can deal with all of them.
Testing with the Phone Simulator
Section titled “Testing with the Phone Simulator”The Phone Simulator is a set of fake phones that never touch a mobile network. Messages to them are free, work before your workspace goes live, and produce real events. The walkthrough below uses its three simulated handsets:
| Number | Behaviour |
|---|---|
+447700900001 | Delivered a couple of seconds after sending |
+447700900002 | Fails as an invalid number |
+447700900003 | Delivered, then replies |
Walkthrough: a complete test integration
Section titled “Walkthrough: a complete test integration”-
Choose how to receive events. Either create a webhook for
sms.delivered,sms.failed,sms.receivedandsuppression.created, or poll the events feed. -
Test a delivered message. Send a message to
+447700900001. You getsms.queued,sms.sentand thensms.delivered, with the message’sstatusofdelivered. -
Test a failed message. Send a message to
+447700900002. You getsms.failed, with areasonof categoryinvalid, codeinvalid_destination_addressandretryableoffalse. Make sure your application handles it, for example by flagging the number as invalid. -
Test a reply. Send a message to
+447700900003with a reply link. You getsms.delivered, thensms.receivedwith the simulator’s reply and achannelofweb. -
Test an opt-out. Open the reply link from your message to
+447700900003(shown on the Phone Simulator page) in your browser, and replySTOP. You getsms.receivedwith the contentSTOP, thensuppression.createdwith asourceofstop. Any further messages to the number are not sent.
Going live
Section titled “Going live”When your workspace goes live you can send to real phone numbers, and messages are billed. Your integration does not need to change, as real messages produce the same events as the simulator.
If you want recipients to be able to reply by text message rather than through a reply link, you can add a dedicated virtual number once you are live. Replies to it arrive with a channel of sms.