Integrating delivery feedback with Node.js
There are two endpoints we'll put into play to integrate delivery feedback:
- First, we'll prepare a batch for delivery feedback by enabling it in our
/batches
POST Send request. - Then, we'll send another POST request to
/delivery_feedback
using the batch ID.
Add delivery feedback to a batch
The parameter we are concerned with for this first step isfeeback_enabled
in the POST Send request for the /batches
endpoint.By setting feedback_enabled
to true
we are telling the API that we would like to allow feedback on this particular batch to be sent back to Sinch for routing optimization.Add the code to your file
Copy and paste the "Set delivery feedback to true" code into a new file calledallowDelivery.mjs
.Fill in your parameters
- Assign your values to the following parameters:
Parameter | Your value |
---|---|
SERVICE_PLAN_ID | The service plan ID found on your Sinch Customer Dashboard. SMS > APIs > REST configuration. |
API_TOKEN | The API token found on your Sinch Customer dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token. |
SINCH_NUMBER | A free test number or any Sinch virtual number you've rented. Find the number on your Sinch Customer Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. |
TO_NUMBER | Your receipient number(s). The phone number(s) to which you want to send the test SMS message. Even if you only send to one number, it is inside an array. |
feedback_enabled | Here is where you'll set the feedback status to true . This parameter is a boolean value and by default it is set to false . |
- Save the file.
Run the code
- Run the following command in your terminal/command prompt to create a group:
node allowDelivery.mjs
- Copy the batch ID value in the response.
Successful Response
A successful response will look like this:
{
id: '01000008YAZ00000TMJ000005W',
to: [ '12065551234' ],
from: '12065555678',
canceled: false,
body: 'Only the best route for this message.',
type: 'mt_text',
created_at: '2022-08-03T20:15:49.706Z',
modified_at: '2022-08-03T20:15:49.706Z',
delivery_report: 'full',
expire_at: '2022-08-06T20:15:49.706Z',
feedback_enabled: true,
flash_message: false
}
Once the user has received a message on their device and you have received a successful reponse, you've now given permission to send delivery feedback for this batch to Sinch for optimal message routing.
Let's go one step further and configure your batch to send feedback.
Go Back