Lunar Flow | Twilio SMS API Switching based on Country Codes

This flow is useful for customers of the Twilio SMS API who want to route their API traffic to different providers based on the recipient country.

Relevant APIs:

  • https://api.twilio.com/2010-04-01/Accounts//$TWILIO_ACCOUNT_SID/Messages.json

  • 1

    [REQUEST] Filter - in this basic filter block, we filter out requests based on the receiver phone number. We use the first few digits of the phone number (the country code) to determine the recipient's country. In this example, we look for numbers starting with +81 – Japan's country code.

  • 2

    [REQUEST] Request Switch - for requests matching our filter - we perform a switch to use the Telesign API. Here we map the request details from the original Twilio request to the new Telesign request (most importantly - the phone number and the message body).

    You can modify this block to customize the request made to the Telesign API farther.Because we use the request switch processor it will treat the modified request as a new request - passing it through all the flows in your system. So if you have global flows / flows specific to the Anthropic API, they will be processed for this new modified request.

This may become necessary as different telecommunication API providers have different pricing structure and deliverability metrics in different geographies. Just as an example - Twilio charges $0.0079 per SMS sent to a U.S. based phone number - but $0.0840 for an SMS sent to a Japan based phone number - a more than 10x increase. This flow will allow you to capture and send requests made to Twilio with a Japanese recipient and route them to a different API provider - in this case Telesign.

As you scale you messaging and telecommunication capabilities, it may become necessary to leverage various providers for different countries to minimize costs and maximize message deliverability. This Lunar Flow let’s you do that with ease and without any code changes to your different service.

Prerequisites:

  • Have the Lunar proxy installed and configured in your environment.

  • You have the Lunar interceptor installed at the service from which you are consuming the OpenAI API.

About the Twilio API:

Twilio is a cloud communications platform that allows developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs. The Twilio API provides a simple, yet powerful interface for integrating communications into web and mobile applications.

The primary use case for the Twilio API is to enable the sending and receiving of SMS/text messages. Developers can use the Twilio API to send text messages to any phone number, receive incoming text messages, and build interactive text messaging applications. The API provides features such as message tracking, delivery notifications, and the ability to send messages in bulk.

To use the Twilio API for sending text messages, developers need to obtain a Twilio phone number and API credentials. They can then make HTTP requests to Twilio's servers to send messages, specifying the recipient's phone number, message content, and other optional parameters. Twilio handles the underlying complexity of interfacing with mobile carriers to deliver the messages.

The Twilio API is widely used by businesses and developers to add communications capabilities to their applications, such as sending alerts, notifications, and Two-Factor Authentication codes via SMS. Its simple and straightforward interface makes it easy to integrate Twilio's powerful messaging functionality into a wide range of software applications.

About the Telesign API:

Telesign is a leading provider of communication and security solutions for enterprises. The Telesign API offers a range of features and services that enable developers to enhance the security and communication capabilities of their applications.

The primary use cases for the Telesign API include:

  • SMS Verification: Developers can use the Telesign API to send one-time passcodes or verification codes to users via SMS, as a means of implementing two-factor authentication or account validation.

  • Voice Verification: The API also supports placing voice calls to users and delivering verification codes through an automated phone system, providing an alternative to SMS-based verification.

  • Phone Reputation and Risk Assessment: Telesign's API allows developers to analyze phone numbers and assess the risk associated with them, helping to detect and prevent fraud and abuse.

  • Phone Number Lookup and Validation: Developers can use the API to look up information about phone numbers, such as carrier details and geographic location, as well as validate the existence and formatting of phone numbers.

To use the Telesign API, developers need to obtain an API key and integrate the provided SDKs or make direct API calls from their applications. Telesign's documentation and developer resources provide guidance on implementing the various API features, integrating with popular platforms, and optimizing the user experience.

The Telesign API is widely used by businesses in industries such as e-commerce, financial services, and online gaming, where secure and reliable communication with users is of utmost importance. The API's versatile features and robust security measures make it a valuable tool for enhancing the overall user experience and mitigating the risk of fraud and unauthorized access.

About Lunar.dev:

Lunar.dev is your go to solution for Egress API controls and API consumption management at scale.
With Lunar.dev, engineering teams of any size gain instant unified controls to effortlessly manage, orchestrate, and scale API egress traffic across environments— all without the need for code changes.
Lunar.dev is agnostic to any API provider and enables full egress traffic observability, real-time controls for cost spikes or issues in production, all through an egress proxy, an SDK installation, and a user-friendly UI management layer.
Lunar.dev offers solutions for quota management across environments, prioritizing API calls, centralizing API credentials management, and mitigating rate limit issues.

Table of content

Talk to an Expert

Got a use case you want to get help with?

Book a Demo
By clicking “Accept”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.