Nexmo SMS Autoresponder

This flow responds to incoming SMS messages with a predefined message. To achive this, first you'll need to be able to receive the incoming messages. Then, as a second step, you'll have to set up the outbound messges by using the sendsms node.

Prerequisites

Before getting started, you’ll need a few things:

  • The Nexmo Node-RED Module
  • A Nexmo account—create one for free if you haven't already
  • A way to expose your local server to the internet. A convenient way would be using ngrok or similar tunnelling services - skip this if you’re running Node-RED on a public webserver instead of your local machine.

For this flow, you'll also need a Nexmo number—and you can get one under Numbers > Buy numbers.

There are two tutorials that explain the concepts used more in depth:

Useful Links

[{"id":"835d23cf.67263","type":"tab","label":"SMS Autoresponder with Nexmo","disabled":false,"info":""},{"id":"35cd1184.030ede","type":"http in","z":"835d23cf.67263","name":"","url":"/inbound-sms","method":"get","upload":false,"swaggerDoc":"","x":210,"y":280,"wires":[["7b50952c.f7f95c","13ace54b.656b9b","9366d72.0efa728"]]},{"id":"13ace54b.656b9b","type":"http response","z":"835d23cf.67263","name":"","statusCode":"200","headers":{},"x":680,"y":280,"wires":[]},{"id":"b8eef4a4.959318","type":"comment","z":"835d23cf.67263","name":"❓About this path - Receive ans Send SMS Messages","info":"This flow responds to incoming SMS messages with a predefined message.\nTo achive this, first you'll need to be able to receive the incoming messages. Then, as a second step, you'll have to set up the outbound messges by using the *`sendsms`* node.\n\n# Receiving SMS Messages\n\nIn order to receive SMS messages with Nexmo, you need to associate a webhook endpoint with a virtual number that you have rented from Nexmo. Inbound Messages to that number will then be sent to your webhook endpoint.\n\n## Defining a Webhook Endpoint\n\nFirst, set up this webhook endpoint in your Node-RED editor. Connect a `http` input node to a `http response` node, as well as to a `debug` node, so that you can view your inbound messages in the debug area. \nIn the `http` input node, select `GET` as a `Method` and fill in the `URL` field with something like `/inbound-sms`.\nThe `http response` node should have `200` set as `Status code`, but don't worry about it, this is the default value.\n\n## Exposing Your Local Server to the Internet\n\nNext you'll have to expose your local server to the internet, so that Nexmo can access it. If you’re running Node-RED on a public webserver instead of your local machine, you can skip this stage. \nOtherwise, a convenient way to do this is by using a tunneling service like [ngrok](https://ngrok.com).\n\n[Download](https://ngrok.com/download) and install **ngrok**, then run it in the terminal to start a tunnel on port `1880`.\n```bash\n$ ./ngrok http 1880\n```\n\n## Setting Up the Endpoint with Nexmo\n\nThe last step is letting the Nexmo SMS API know where it should forward the inbound messages.\n\nAssociate a webhook endpoint with one of your virtual numbers by going to [Your numbers](https://dashboard.nexmo.com/your-numbers), then clicking the settings icon next to the number you'd like to configure. \nNext, fill in the _Inbound Webhook URL_ field with `YOUR_NGROK_URL/inbound-sms` and `Save changes`.\n\nNow, if you send a text message to your Nexmo number, you should see the message object appear in the debug sidebar.\nThe message payload will contain a couple of key values that should be noted:\n\n| KEY           | DESCRIPTION |\n| --------------- | --- |\n| **`msisdn`**   | The sender's number in E.164 format. For example 447401234567. |\n| **`to`**  | Your Nexmo number that the SMS was sent to, in E.164 format.    |\n| **`text`**     | The content of the received SMS message.|\n| **`type`**     | The type of the message body received (**`text`** key). Possible values are `text`, `unicode` and `binary`.| \n| **`keyword`**     | The first word in the message body. This is typically used with short codes.| \n| **`message-timestamp`**     | The time when Nexmo started to push this Delivery Receipt to your webhook endpoint.\n\nFind out more about these parameters in the [Nexmo API Reference for Inbound SMS](https://developer.nexmo.com/api/sms#inbound-sms).\n\n\n# Sending SMS messages\n\nTo respond to the inbound messages, you'll need to wire a *`sendsms`* node to the `http` input node.\nYou can set this node up by double clicking on it and filling in the parameters below. You'll find `API KEY` and `API SECRET` by clicking on the edit button next to `Nexmo Credentials`. Get these from your [Nexmo account](https://dashboard.nexmo.com/getting-started-guide).\n\nNext to the `TO`,`FROM` and `TEXT` parameters there is a `{}` sign, which means that [Mustache templating](https://mustache.github.io/) is supported for those fields. This comes in handy when passing certain values dynamically to the **`sendsms`** node.\n\n| KEY           | DESCRIPTION |\n| --------------- | --- |\n| `API KEY`     | Your Nexmo API key, shown in your [account overview](https://dashboard.nexmo.com/getting-started-guide). |\n| `API SECRET`  | Your Nexmo API secret, shown in your [account overview](https://dashboard.nexmo.com/getting-started-guide).    |\n| `TO`     | The number you are sending the SMS to in E.164 format. In this case, you'll need to answer to an incoming SMS, so you'll need to use templating to reference the sender's number: **{{msg.payload.msisdn}}**|\n| `FROM`     | The number or text shown on a handset when it displays your message. You can set a custom alphanumeric FROM to better represent your brand, if this feature is [supported in your country](https://help.nexmo.com/hc/en-us/articles/115011781468). Alternatively, you can reference your Nexmo number that received the inbound SMS: **{{msg.payload.to}}**.| \n| `TEXT`     | The content of your message. Feel free to get creative, and make use of the {{mustache}} templating.\n\nTo have a bit more insight into what's happening when you send an SMS, the **`sendsms`**' output is wired into a **`debug`** node. Double click on it and set the `Output` to `complete msg object`.\n\nOnce you hit **Deploy**, your SMS autoresponder should be up and running! \n","x":280,"y":140,"wires":[]},{"id":"6773d04e.88cfa","type":"comment","z":"835d23cf.67263","name":"📖 Check out the tutorials","info":"This flow is based on two concepts, [sending](https://www.nexmo.com/blog/2019/04/17/send-sms-messages-node-red-dr/) and [receiving](https://www.nexmo.com/blog/2019/04/24/receive-sms-messages-node-red-dr/) SMS messages.\nClick the links above to go to the respective tutorials.","x":190,"y":60,"wires":[]},{"id":"7b50952c.f7f95c","type":"debug","z":"835d23cf.67263","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":200,"wires":[]},{"id":"9366d72.0efa728","type":"sendsms","z":"835d23cf.67263","creds":"47e82daf.b07814","to":"{{msg.payload.msisdn}}","fr":"{{msg.payload.to}}","text":"This is an automated response message :)","unicode":false,"x":510,"y":460,"wires":[["dec3a27.a0c756"]]},{"id":"dec3a27.a0c756","type":"debug","z":"835d23cf.67263","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":460,"wires":[]},{"id":"bc73ddf4.d3706","type":"http in","z":"835d23cf.67263","name":"","url":"/receipt","method":"get","upload":false,"swaggerDoc":"","x":210,"y":640,"wires":[["65697ca3.d6e5f4","4cd9072c.3abcc8"]]},{"id":"65697ca3.d6e5f4","type":"http response","z":"835d23cf.67263","name":"","statusCode":"","headers":{},"x":550,"y":640,"wires":[]},{"id":"4cd9072c.3abcc8","type":"debug","z":"835d23cf.67263","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":550,"y":720,"wires":[]},{"id":"26e9721f.8b513e","type":"comment","z":"835d23cf.67263","name":"❓ About this path - Handle Delivery Receipts","info":"When the message gets delivered, the mobile phone carrier returns a [**Delivery Receipt**](https://developer.nexmo.com/messaging/sms/guides/delivery-receipts) to Nexmo. This will contain the delivery status.\n\n## Receiving a Delivery Receipt from a Mobile Carrier\n\nTo find out the `status` of your outbound message, you'll need to set up a webhook endpoint that Nexmo can forward the **Delivery Receipt** to.\n\n### Defining a Webhook Endpoint\n\nFirst, connect a `http` input node to a `http response` node, as well as to a `debug` node, so that you can view your delivery receipt in the debug area.\n\nIn the `http` input node, select `GET` as a `Method` and fill in the `URL` field with something like `/receipt`.\nThe `http response` node should have `200` set as `Status code`, but don't worry about it, this is the default value as well.\n\n### Setting Up the Endpoint with Nexmo\n\nThe last step is letting the Nexmo SMS API know where it should forward the delivery receipts. You can do so under your [API settings](https://dashboard.nexmo.com/settings) in the **Default SMS Setting** section.\n\nSet the default webhook URL for delivery receipts to `YOUR_URL/receipt`, then `Save changes`.\n\nNow go ahead and send another SMS!\n\nLearn more about delivery receipt status messages and error codes in the Nexmo [docs](https://developer.nexmo.com/messaging/sms/guides/delivery-receipts).\n","x":260,"y":560,"wires":[]},{"id":"47e82daf.b07814","type":"nexmobasic","z":""}]

Flow Info

Created 6 years, 6 months ago
Updated 6 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x3)
  • debug (x3)
  • http in (x2)
  • http response (x2)
Other

Tags

  • SMS
  • autoresponder
  • messaging
  • Nexmo
  • inbound
  • outbound
  • send
  • receive
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option