I've got
- a US number
- a well functioning Messaging Service (
MG...
) - and a properly configured Alphanumeric Sender
through which I'm sending out programmatic SMSs to various European countries. Some of these countries apparently don't support Alphanumeric IDs (e.g. Belgium).
So, assuming my code looks like this:
import twilio from "twilio";
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const messagingServiceSid = process.env.TWILIO_MESSAGING_SID;
const twilioClient = twilio(accountSid, authToken);
// https://www.twilio.com/docs/errors/21211 etc
const PhoneRelatedTwilioErrorCodes = [
21211, 20023, 21217, 21401, 21407, 21421, 21601, 21612, 22102
];
// ... more code
try {
messageResponse = await twilioClient.messages.create({
messagingServiceSid,
to: '123',
body: 'xyz'
});
} catch (twexc: any) {
// ...
}
I've got the following questions:
- Is there a sender ID fallback mechanism / sender pool built into the Node.js SDK?
- Is there a specific error code for these types of SMS errors? Should I catch this particular exception and try again with the standard sender ID?
- Any other best practices?
There's no need to fall back programmatically. The Messaging Service's Sender Pool needs a long code number to fall back to so you'll need to manually add a "Phone Number Sender" alongside your Alpha Sender ID:
Note for the discerning reader: the order of these senders doesn't really matter. Quoting the docs: