Twilio alphanumeric sender ID fallback to standard number

110 views Asked by At

I've got

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:

  1. Is there a sender ID fallback mechanism / sender pool built into the Node.js SDK?
  2. 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?
  3. Any other best practices?
2

There are 2 answers

0
Joe - Check out my books On BEST ANSWER

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:

enter image description here

Note for the discerning reader: the order of these senders doesn't really matter. Quoting the docs:

If you add an Alpha Sender to your Twilio Messaging Service, Twilio will select the Alphanumeric Sender ID automatically when you send a message to a supported country, unless you also have a short code number in that same country.

1
IObert On
  1. Yes, the fallback order is mentioned here:

If you add an Alpha Sender to your Twilio Messaging Service, Twilio will select the Alphanumeric Sender ID automatically when you send a message to a supported country, unless you also have a short code number in that same country.

  1. see 3.
  2. My recommendation would be to avoid errors in the first place by adding a possible sender to all countries, you anticipate to send messages to, the messaging service. I.e. if you cannot message to country X, add a long code number of country X to the messaging service.