Sending SMS from a Private Stack
Instances on platformOS send text messages with SMS notifications, which are delivered through Twilio. On a private stack, the messages can be sent through your own Twilio account, so that they are billed to you and visible in your Twilio console.
This article explains what you need to provide, how platformOS uses your account, and how to verify the setup.
Choose how to connect your account
There are two ways to connect a Twilio account. Choose the one that matches how you manage phone numbers.
| Partner Portal account | Account per instance | |
|---|---|---|
| Who configures it | The platformOS team, once on the Partner Portal | You, in the configuration of each instance |
| Phone numbers | A new number is bought automatically for each instance | You use numbers you already own |
| Twilio structure | One subaccount per instance, inside your account | Messages are sent directly from your account (or any subaccount you choose) |
| Best for | Many instances, each with its own sender number and its own usage report | A few instances, or numbers that need regulatory approval, such as Australian numbers |
The Partner Portal account is configured on the Partner Portal, not on a single stack, so it is used for every instance that enables Twilio through that Partner Portal, on any of the private stacks it manages.
You can combine both: an instance that has its own Twilio configuration uses it, regardless of the Partner Portal account.
What you need to provide
Credentials
Twilio credentials come in two forms. The platformOS integration signs in with account credentials:
| Credential | Format | Where to find it |
|---|---|---|
| Account SID | Starts with AC, followed by 32 characters |
Twilio Console, Account Info on the dashboard |
| Auth Token | 32 characters | Twilio Console, Account Info on the dashboard (click Show) |
Warning
An API Key (a SID starting with SK and its secret) is not an Account SID, and cannot be used in place of one. If you send an SK key, every request to Twilio fails with an authentication error. Send the AC Account SID and its Auth Token instead.
Share credentials with the platformOS team only through the secure channel agreed for your engagement, never in plain email or in a support ticket.
Account requirements
- An upgraded (paid) account. Trial accounts can only send to verified phone numbers and prefix every message with a trial notice.
- For a Partner Portal account:
- Your account must be allowed to create subaccounts, and have enough balance to buy a phone number for each instance.
- Numbers bought automatically are US local numbers with SMS and voice capabilities. If your recipients are in another country, discuss the sender number with the platformOS team before go-live, or use the account per instance option with a local number you own.
- For an account per instance: a phone number in your account that can send SMS to your recipients' country. Many countries, including Australia, require a Regulatory Bundle to be approved in Twilio before you can buy a local number.
How it works
Partner Portal account
- You provide your Account SID and Auth Token. The platformOS team stores them in the secrets store of the Partner Portal that manages your private stacks. They are never stored in the code or in an instance's configuration.
- In the Partner Portal, open your instance, go to Integrations, and click Manage Twilio. Then click Enable Twilio Integration.
- In the background, the Partner Portal signs in to your account and:
- Finds or creates a subaccount named after the instance and the stack it runs on, in the form
<instance name>--<stack name>. - Uses the subaccount's existing phone number, or buys a new one.
- Saves the subaccount's SID and Auth Token, and the phone number as the sender, in the instance's configuration.
- Finds or creates a subaccount named after the instance and the stack it runs on, in the form
- After a few minutes, the Twilio integration page of the instance says that Twilio is set up. From then on, the instance's SMS notifications are sent through its subaccount.
Because each instance has its own subaccount, you can see the messages and costs of each instance separately in your Twilio console, and suspend one instance's subaccount without affecting the others.
If Twilio rejects a request, for example because the account cannot create subaccounts or no number is available, the integration is not saved, and the Twilio page of the instance keeps showing the Enable Twilio Integration button. Contact the platformOS team with the instance name, so they can check the error reported by Twilio.
Account per instance
-
In the Partner Portal, open your instance, click Update Configuration, and then click Switch to edit mode.
-
Add or update the
twiliosection underintegrations, with the SID and Auth Token of the account or subaccount to send from, and the sender phone number in E.164 format:{ "integrations": { "twilio": { "sid": "AC00000000000000000000000000000000", "auth_token": "your_auth_token", "from": "+61400000000" } } } -
Click Update Instance configuration. The instance's SMS notifications are sent with these credentials from now on.
Sending the messages
When an SMS notification is triggered, the instance renders the message and sends it through the Twilio account in its configuration, from the configured phone number. Each message part (segment) is recorded in the instance's usage.
Whether a real message is sent depends on the instance:
- Production instances send real messages.
- Staging instances also send real messages by default. To test without reaching real recipients or incurring Twilio costs, set
enable_sms_and_api_workflow_alerts_on_stagingtofalsein the instance's configuration. The instance then uses Twilio test credentials and does not send real messages.
Verify the setup
- Create an SMS notification on a production instance, or on a staging instance that has not disabled real messages, and send it to your own phone number.
- Check that the message arrives from the expected sender number.
- In the Twilio console, open Monitor > Logs > Messaging in the account (or the instance's subaccount) and check that the message is listed as delivered.
If the message does not arrive, check the instance logs with pos-cli logs, followed by the name of your environment. A common cause is a recipient number without a country code.
Rotating credentials
- Partner Portal account: if you rotate the Auth Token of your main account, send the new token to the platformOS team, so it is updated in the Partner Portal's secrets store. Instances that are already set up keep working, because they use their subaccounts' own tokens.
- Account per instance: after rotating a token in Twilio, update it in the instance's configuration.