How to receive SMS inbound messages

With the numbers API, you are able to rent a new number, use it as the sender in your campaigns and receive the inbound messages from your clients.

When you rent or update a number, you are able to define a callback Url ("inboundSmsCallbackUrl") that will receive the inbound SMS messages.

Your callback service will receive a POST HTTP request with the following request body:

{
  "messageId": string,
  "from": string,
  "to": string,
  "message": string,
  "parts": integer,
  "originatingService": "Sms",
  "direction": "Inbound",
  "receivedDate": string
}

Also, your inbound messages can be tracked through the SMS tracking resource.
You can see all your inbound messages at the Logs menu in Routee Platform with direction: inbound.

See an example of how to use a Number with your SMS Campaign How to use a Number with your SMS Campaign

If you want to gather the inbound messages and save them into a file, you should build a server-side script.

Example:

Using the following example server-side code, you will save the message, messageId and the receivedDate of inbound messages into a file.

<?php

// read input data from POST
$request = json_decode(file_get_contents('php://input'), true);

// set file name
$log_file_name = "my-inbound-logs.log";

// check if log file already exists
if (!file_exists($log_file_name)) {
    //create a file in not exists
    $log_file_create = fopen($log_file_name, 'w');
    fclose($log_file_create);
    chmod($log_file_name, 0755);
}

// Check for null request
if ($request == null) {
    //save message to a specific log file
    error_log("Request is null\n", 3, $log_file_name);
    return;
}

// Check that this is an inbound message
if (!isset($request['direction']) == 'Inbound') {
    //save message to a specific log file
    error_log("This is not an inbound message\n", 3, $log_file_name);
    return;
}

// Write data to log file
   error_log("The following inbound message: ".$request['message']." with messageId: ".$request['messageId']." was received at: ".$request['receivedDate']."\n", 3, $log_file_name);

What’s Next