Plivo supports receiving SMS text messages in 19 countries (see complete SMS API coverage). When an SMS is sent to a Plivo phone number, you can receive the text on your server by setting a Message URL in your Plivo app. Plivo will send the message along with other parameters to your Message URL.
Check out our server SDKs page and install the right helper based on the programming language you want to use.
Buy a Plivo phone number. A phone number is required to receive and reply to SMS text messages. You can buy a Plivo phone number in over 19 countries through the Buy Numbers tab on your Plivo account UI. Check the SMS API coverage page for all the supported countries.
Use a web hosting service to host your web application. There are many inexpensive cloud hosting providers that you can use for just a few dollars a month. Follow the instructions of your hosting provider to host your web application.
Note: If you are using a Plivo Trial account for this example, you can only send sms to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.
Set up a Web Server
Let’s assume your web server is located at http://example.com. Below is a snippet to set up a route on your webserver. Now when we send an HTTP request to http://example.com/receive_sms this route will be invoked.
Note: For PHP, the route will be example.com/receive_sms.php.
Copy the relevant code below into a text file and save it. Let’s call it receive_sms.
Note: Make sure to use the appropriate file extension for your code (e.g., `receive_sms.py` for Python).
Next you will now have to configure this URL in your Plivo application.
fromflaskimportFlask,request,make_response,Responseapp=Flask(__name__)@app.route('/receive_sms/',methods=['GET','POST'])definbound_sms():# Sender's phone number
from_number=request.values.get('From')# Receiver's phone number - Plivo number
to_number=request.values.get('To')# The text which was received
text=request.values.get('Text')# Print the message
print('Message received - From: %s, To: %s, Text: %s'%(from_number,to_number,text))return'Message Recevived'if__name__=='__main__':app.run(host='0.0.0.0',debug=True)
1
2
3
4
5
6
7
8
9
10
11
12
require"sinatra"post"/receive_sms/"do# Sender's phone numberfrom_number=params[:From]# Receiver's phone number - Plivo numberto_number=params[:To]# The text which was receivedtext=params[:Text]# Print the messageputs"Message received - From: #{from_number}, To: #{to_number}, Text: #{text}"end
varexpress=require('express');varbodyParser=require('body-parser');varapp=express();app.use(bodyParser.urlencoded({extended:true}));app.use(function(req,response,next){response.contentType('application/xml');next();});app.set('port',(process.env.PORT||5000));app.all('/receive_sms/',function(request,response){// Sender's phone numbervarfrom_number=request.body.From||request.query.From;// Receiver's phone number - Plivo numbervarto_number=request.body.To||request.query.To;// The text which was receivedvartext=request.body.Text||request.query.Text;//Print the messageconsole.log('Message received - From: '+from_number+', To: '+to_number+', Text: '+text);});app.listen(app.get('port'),function(){console.log('Node app is running on port',app.get('port'));});
1
2
3
4
5
6
7
8
9
10
11
<?phprequire'vendor/autoload.php';// Sender's phone numer$from_number=$_REQUEST["From"];// Receiver's phone number - Plivo number$to_number=$_REQUEST["To"];// The SMS text message which was received$text=$_REQUEST["Text"];// Prints the messageecho("Message received - From $from_number, To: $to_number, Text: $text");?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
importstaticspark.Spark.*;publicclassReceiveSms{publicstaticvoidmain(String[]args){get("/receive_sms",(request,response)->{// Sender's phone numberStringfrom_number=request.queryParams("From");// Receiver's phone number - Plivo numberStringto_number=request.queryParams("To");// The text which was receivedStringtext=request.queryParams("Text");// Print the messageSystem.out.println(from_number+" "+to_number+" "+text);return"Message Received";});}}
usingNancy;usingSystem;usingSystem.Collections.Generic;usingSystem.Reflection;namespaceNancyStandalone{publicclassFunctionsModule:NancyModule{publicFunctionsModule(){Post("/receive",parameters=>{// Sender's phone numberStringfrom_number=Request.Form["From"];// Receiver's phone numberStringto_number=Request.Form["To"];// The text which was receivedStringtext=Request.Form["Text"];// Print the messageConsole.WriteLine("Message received - From: {0}, To: {1}, Text: {2}",from_number,to_number,text);return"Message received";};}}}
Give your application a name. Let’s call it Receive SMS. Enter your server URL (e.g. http://example.com/receive_sms) in the Message URL field and set the method as POST. See our Application API docs to learn how to modify your application through our APIs.
Click on Create Application to save your application.
Assign a Plivo number to your app
Navigate to the Numbers page and select the phone number you want to use for this app.
Select Receive SMS (name of the app) from the Plivo App dropdown list.
Click on Update Number to save.
If you don’t have a number, go to the Buy Number page to purchase a Plivo phone number.
Test and validate
Send an SMS to your Plivo number using a regular mobile phone. Plivo will send a request to your Message URL with the parameters listed in the XML Request - Messages Documentation.
Rate this page
🥳 Thank you! It means a lot to us!
×
Help Us Improve
Thank you so much for rating the page, we would like to get your input for further improvements!