Integrating delivery feedback with Node.js

There are two endpoints we'll put into play to integrate delivery feedback:

  1. First, we'll prepare a batch for delivery feedback by enabling it in our /batches POST Send request.
  2. 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 is feeback_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 called allowDelivery.mjs.

Fill in your parameters

  1. Assign your values to the following parameters:
ParameterYour value
SERVICE_PLAN_IDThe service plan ID found on your Sinch Customer Dashboard. SMS > APIs > REST configuration.
API_TOKENThe API token found on your Sinch Customer dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token.
SINCH_NUMBERA 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_NUMBERYour 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_enabledHere is where you'll set the feedback status to true. This parameter is a boolean value and by default it is set to false.
  1. Save the file.

Run the code

  1. Run the following command in your terminal/command prompt to create a group:
Copy
Copied
node allowDelivery.mjs
  1. Copy the batch ID value in the response.

Successful Response

A successful response will look like this:

Copy
Copied
{
  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
We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.