Receive SMS push notifications
This guide shows how to configure and implement receiving push notifications to your web server when inbound messages are received on your Esendex virtual mobile number.
Receive SMS code via push
// You will need Visual Studio 2010 or later with C#
// Microsoft ASP.NET MVC 4 (https://www.asp.net/web-api)
// Internet Information Services (IIS) 7
// Create a new ASP.NET 4 Web Application using the Web API template
// Add the following code in a new Controller called InboundMessagesController in the Controllers folder.
// Compile the solution and deploy the project to IIS7 on an internet-connected server
using System;
using System.Web.Http;
namespace PushNotificationsWebAPI.Controllers {
public class InboundMessagesController : ApiController {
public void Post(InboundMessage inboundMessage) {
// do something with the inboundMessage that you have just received
}
}
public class InboundMessage
{
public Guid Id { get; set; }
public Guid MessageId { get; set; }
public Guid AccountId { get; set; }
public string MessageText { get; set; }
public string From { get; set; }
public string To { get; set; }
public DateTime Now { get; set; }
}
}
$postdata = file_get_contents("php://input");
$inboundMessage = simplexml_load_string($postdata);
$fp = fopen("inboundmessage.txt", "a") or die("Couldn't open file for writing!");
fwrite($fp, "Message received: ".date("Y-m-d H:i:s")."\n".
"Message Id: ".$inboundMessage->MessageId."\n".
"Account Id: ".$inboundMessage->AccountId."\n".
"Message Text: ".$inboundMessage->MessageText."\n".
"From: ".$inboundMessage->From."\n".
"To: ".$inboundMessage->To."\n\n")
or die("Couldn't write to file!");
fclose($fp);
You will need:
- Your Esendex account reference (EX0xxxxxx), username, password and virtual mobile number.
- Don't have an account yet? You'll need to create an account.
- Haven't got a virtual mobile number? If you already have an account but don’t have a virtual mobile number then please call our sales team on 0345 356 5758.
- Need an API password? You can generate one on your user profile.
- A web server that is publicly accessible on the internet.
- A mobile phone to send
SMS
into your account.
Step 1: Host the example code on your web server
Our push notifications are delivered across the internet as HTTP POST requests so you'll need to host the example code on a publicly accessible web server. This could be your own server or one provided by a hosting company. Make a note of the URL that your example code is hosted at as you'll need this for the next step.
Step 2: Tell us where to push the notification
Once you've made this code example accessible on your pubically accessible server you'll need to tell us where to send notifications to by configuring your push notifications handler's URL in our Developer Tools:
- Log in to Developer Tools.
- If you have more than one account with us, select the account you wish to configure push notifications for.
- Click the Configure button for the
SMS
received notification. - Enter your URL and click Save.
Step 3: Test your push notifications handler
Now send a test SMS
from a mobile phone to your Esendex account's virtual mobile number. You'll be able to check the message arrives in your inbox in Echo and that a notification is pushed to your server.
What you might want to do with the notification
- Store the inbound message in your database.
- Pass the message on to your other business systems.
What you might want to do next
- Find out more about push notifications including notifications for message delivered and message failed on our API reference.
- Acknowledge the message by sending a response to the sender.
- Delete the message from your inbox.