Receive an incoming SMS Message

Note:

Before you can get started, you need the following already set up:

  • Set all SMS API configuration settings.
  • NPM and a familiarity with how to install packages.
  • Node.js and a familiarity with how to create a new app.
  • ngrok. You'll use ngrok to open a tunnel to your local server.

Learn how to handle incoming SMS messages in a Node.js application with the Sinch Node.js SDK.

Steps:
  1. Set up your Node.js application
  2. Start your web server and set up a tunnel
  3. Send your SMS message

Set up your Node.js application

To quickly get started setting up a simple client application using the Node SDK:

  1. If you haven't already, clone the sinch-sdk-node-quickstart repository.
  2. Navigate to the getting-started/sms/respond-to-incoming-message/server folder.
  3. Open a command prompt or terminal and run the following command to install the necessary dependencies:
    Copy
    Copied
    npm install
  4. Open the .env file. Using the access key credentials from your Sinch Customer Dashboard, add your values:
FieldDescription
SINCH_PROJECT_IDThe unique ID of your Project.
SINCH_KEY_IDThe unique ID of your access key.
SINCH_KEY_SECRETThe secret that goes with your access key.
Note: For security reasons, this secret is only visible right after access key creation.
SMS_REGIONThe region in which you are send and receiving SMS traffic. Use us for US traffic and eu for European traffic.
  1. Save the file.

Start your web server and set up a tunnel

  1. Start the server by executing the following command:
    Copy
    Copied
    npm start
  2. Open a tunnel to the server you just set up. We are using ngrok for this. If you don't have ngrok installed already, install it with the following command:
    Copy
    Copied
    npm install ngrok -g
  3. Open a terminal or command prompt and enter:
    Copy
    Copied
    ngrok http 3001
  4. You should see a screen in your console that shows the running tunnel. Copy the address ending in .ngrok.io.

Configure your Callback URL

  1. To configure a callback URL for your Sinch account, login to your dashboard.
  2. Click on the service plan ID link and edit the Callback URL field with the ngrok.io domain URL from the previous section with /SmsEvent added to the end. The complete URL should look something like https://3b58-75-118-121-186.ngrok-free.app/SmsEvent.

Send your SMS message

Now send an SMS message to your Sinch number from your mobile phone and you will get an automatic reply.

Next steps

The code you used in the serverBusinessLogic.js file listens for a webhook sent from the Sinch servers and then sends a POST request to the Sinch API /batches endpoint to send the SMS message.

Additional resources

  • Click here to read more about the batches endpoint.
We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.