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.
Set up your Node.js application
To quickly get started setting up a simple client application using the Node SDK:
- If you haven't already, clone the sinch-sdk-node-quickstart repository.
- Navigate to the
getting-started/sms/respond-to-incoming-message/server
folder. - Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm install
- Open the
.env
file. Using the access key credentials from your Sinch Customer Dashboard, add your values:
Field | Description |
---|---|
SINCH_PROJECT_ID | The unique ID of your Project. |
SINCH_KEY_ID | The unique ID of your access key. |
SINCH_KEY_SECRET | The secret that goes with your access key. Note: For security reasons, this secret is only visible right after access key creation. |
SMS_REGION | The region in which you are send and receiving SMS traffic. Use us for US traffic and eu for European traffic. |
- Save the file.
Start your web server and set up a tunnel
- Start the server by executing the following command:
npm start
- 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:
npm install ngrok -g
- Open a terminal or command prompt and enter:
ngrok http 3001
- You should see a screen in your console that shows the running tunnel. Copy the address ending in
.ngrok.io
.
Configure your Callback URL
- To configure a callback URL for your Sinch account, login to your dashboard.
- 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 likehttps://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 theserverBusinessLogic.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.- Explore the API specification to test more endpoints.
Additional resources
- Click here to read more about the batches endpoint.