How to Test Your Twilio App from India Using Twilio Dev Phone
Time to read: 6 minutes
There are few things more frustrating than sending a test message or call to your application and not getting through – especially if you check the Twilio logs and see that your call or message never reached the number. If you’re a developer in India, your development process might be running up against some special telephony restrictions.
It is important to understand India’s messaging limitations before you consider developing an app to send SMS to Indian mobile devices. However, if you just need to test an application that is being developed for deployment in other countries, the Twilio Dev Phone is a great solution.
Limitations of Twilio SMS to Indian mobile devices
When sending messages to India from Twilio, your Twilio phone number won’t appear as the sender of the message: the sender ID will be changed by the carrier before your SMS messages are delivered to end users. Usually if you are testing functionality from your own device, you will see a random short number between 5 and 9 digits long, e.g., 5NNNN - 5NNNNNNN.
Because of the sender ID change, a recipient can’t send a reply back to your Twilio phone number. If you’re building your app in production with the intent to utilise two-way messaging with mobile users in India, consider using the Twilio API for WhatsApp instead.
How Twilio Dev Phone can help you test your application
It is important to understand the above limitations before you consider deploying an app to send messages to Indian mobile users. However, if you are a developer in India working on an app and just need to to test what you’re building, you can do so using the Twilio Dev Phone. The Dev Phone is a virtual phone that uses a Twilio number to send/receive calls and SMS messages.
In this post, you will learn how to set up the Twilio Dev Phone, make a call from the dev phone to your application and send an(?) SMS to your application with an automated response using Twilio Studio.
Prerequisites
- A Twilio Account — sign up for a free one here and get $10 when you upgrade your account.
- Install the Twilio CLI
- Buy an additional Twilio phone number (US or UK number suggested to avoid regulatory documentation requirements)
Set up the Dev Phone
The Twilio Dev Phone allows you to test your voice and messaging applications without having to use your own device to do so. If you are in India and running into issues using your own device for testing purposes, you can use the Dev Phone instead. This will work by using the phone number you purchased to connect to code that runs the Dev Phone.
First, open up your terminal and check to make sure that you have installed or updated to the latest version of twilio-cli
.
If if is your first time using the CLI, you can create a new profile to store your Twilio Account credentials and configuration by running the following command
You will then be prompted to enter your Account SID and Auth Token, and to give your profile a shorthand identifier. To choose this profile, run the below command with the shorthand identifier you chose:
Next, add the Dev Phone plugin using the following command:
If you have run the Dev Phone previously on this profile, you may receive the following error:
If this happens, you may uninstall the plugin using the below command, and then re-install it.
Run the Dev Phone
To run the Dev Phone, enter the below command:
You should see the below in your terminal as the Dev Phone starts up.
If you already have something running on that port or wish to use a different port, you can:
- Define a port passed in as a flag
- Define a port passed in via the
TWILIO_DEV_PHONE_PORT
environment variable
Once this is running, it should auto-launch in your browser and you will see the below page. Notice in the upper right hand corner that there is no Twilio number yet selected for the Dev Phone.
Next, scroll down and you will see a configuration selection to choose a number. If you bought a number as a part of the prerequisites, you may choose that number from the drop down. If you haven’t purchased one yet, you can do so now, and then refresh the page. Click Use this phone number.
Now your Dev Phone is ready to use for incoming and outgoing calls and messages.
During the setup a few Twilio Functions were created and deployed that provide the functionality for the Dev Phone to make and receive calls and messages. If you open up the Services part of your console, you can see where these functions were auto-generated.
Your dev phone number is connected to these functions. As long as you use this number as your Dev Phone number, you will not want to change anything in the configuration.
In the screenshots below, you can see the number is already connected to your functions service. Do not change this, or else your Dev Phone will break. Buy a new number in order to connect it to the app you are building.
If it will help you to remember – and you plan to use this number for the dev phone again in the future – you can also rename the “friendly name” for your Dev Phone number to something like dev-phone
, which will render in the dev phone UI the next time you see the phone number selection screen.
Next, you will set up your new number to use for your application. Then you will test calling and messaging it from your Dev Phone
Call Your App from the Dev Phone
Buy a new number that you will use for your app (and feel free to change the friendly name to keep them distinct). Then, go to the Studio part of your console and create a new flow.
Choose Start from scratch.
Now input a greeting message using the Say/Play widget. Connect it to the Incoming Call option from the Trigger widget. Hit Publish.
Navigate back to the Active Numbers part of your console and choose your app number. Scroll down to the Voice configuration. From the A Call Comes In dropdown, choose Studio. In the dropdown next to it, choose the flow you just created.
Go back to the localhost window running your Dev Phone. Paste in the app number and test out a call. You should hear your greeting playback, and you will see call information in the Call History section.
Message Your App from the Dev Phone
Go back to your same Studio flow. This time, add a Send Message widget with a greeting and connect it to the Incoming Message section of the Trigger widget. Hit Publish.
Navigate to the Messaging configuration in your app number. Follow the same steps as we did for Voice: Choose Studio from the dropdown and your flow in the subsequent dropdown. Hit Save.
If you get an error like the below, be sure to check your SMS geo permissions and update them accordingly. For example, since I set up my Twilio account in the UK, I was not opted in to receive messages from a US number, even if the country code for the number that I purchased was a US number.
Go back to your Dev Phone and try sending a SMS message. It should look like the image below. Now your dev phone and application are working together!
Conclusion
If you are building with Twilio in India or another country with SMS restrictions, using the dev phone could help you get around regulatory hurdles that make it hard to test your app. When you are setting up your application, be sure to keep the dev phone separate from your application number; use the friendly names to your advantage.
In the next post you will learn how you can trigger an outbound message from your application to the dev phone using Postman and the REST API Trigger widget in Twilio Studio. This will also help with mocking up what an automated or scheduled call or message could look like.
If you’re building something and use the dev phone to test, we want to hear about it! Email me lmoy[at]twilio.com to let me know, and send me a tweet of your messages.
Liz Moy is a Developer Evangelist on the Enterprise Evangelism team. She loves to talk to developers at hackathons, conferences, and on the Build and Deploy with Liz Moy podcast. You can find her at lmoy [at] twilio.com or on Twitter @ecmoy.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.