# Receive replies

Receiving a messsage reply is almost the same as receiving a status update.

To do so, you have to register a webhook. This webhook will then be called with the reply to your message..

Beware that in order to receive message response you have to send the sms with the default "from" value; Leave the field empty when sending your SMS. That way the recipient will receive the sms from what's known as a shortcode (e.g: 36789) and will then be able to respond to that short code.


# Register a webhook to receive a response

You can create an api endpoint on your system or use a no-code solution to receive webhooks. You need to have an api url to provide when creating a webhook resource. Once created, the webhook will receive all responses. You can unregister your webhook at a later point if your url has changed for example.

You can then create a Webhook by calling the /webhooks endpoint.

For example if your url is https://yourdomain.com/api/sofyReplies

curl -X 'POST' \
  'https://api.sofy.fr/v1/webhooks' \
  -H 'accept: application/json' \
  -H 'X-API-KEY-ID: xxxxx' \
  -H 'X-API-KEY-SECRET: yyyyy' \
  -H 'Content-Type: application/json' \
  -d '{
	"url": "https://yourdomain.com/api/sofyReplies",
	"events": ["sms.reply"]
  }'
import axios from 'axios';

axios.post(
  'https://api.sofy.fr/v1/webhooks',
  {
    url: 'https://yourdomain.com/api/sofyReplies',
    events: ['sms.reply'],
  },
  {
    headers: {
      'X-API-KEY-ID': 'xxxxx',
      'X-API-KEY-SECRET': 'yyyyy',
    },
  },
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sofy.fr/v1/webhooks");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "X-API-KEY-ID: " . $ID,
    "X-API-KEY-SECRET: " . $SECRET,
	"Content-Type: application/json"
));

$payload = json_encode(array("events" => array('sms.reply'), "url" => "https://myapiurl.com/sofyReplies"));

echo $payload;
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

# Examples

SMS reply webhook
{
  "data": [
     {
      "originSms": {
        "body": "Sent message !",
        "from": "36789",
        "to": "590690112233",
        "createdAt": "2022-12-29T18:24:27.000Z",
        "updatedAt": "2022-12-29T18:24:44.938Z",
        "id": "zzzzz",
        "status": "received",
        "statusReason": "",
        "price": 0.08,
        "parts": 1
      },
      "body": "received message",
      "from": "590690112233",
      "to": "36789"
     }
  ],
  "webhookId": "xxxxx",
  "id": "yyyyy",
  "type": "sms.status"
}