Send SMS Messages with Nexmo

This flow sends SMS messages and handles delivery receipts received from a mobile carrier.

Prerequisites

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

  • A Nexmo account - create one for free if you haven't already
  • ngrok or other tunnelling services - if you're not using a cloud-hosted option

There is a tutorial associated with this flow, you can check out the step-by-step guide for more help.

[{"id":"6967cd61.ab44a4","type":"tab","label":"Send SMS Messages and Handle Delivery Receipts","disabled":false,"info":""},{"id":"4e7f6ca1.513034","type":"http response","z":"6967cd61.ab44a4","name":"","statusCode":"","headers":{},"x":770,"y":220,"wires":[]},{"id":"9c3eb96c.495f88","type":"debug","z":"6967cd61.ab44a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":770,"y":140,"wires":[]},{"id":"83595ef2.25cf7","type":"sendsms","z":"6967cd61.ab44a4","creds":"","to":"","fr":"","text":"The timestamp is: {{msg.payload}}","unicode":false,"x":510,"y":220,"wires":[["4e7f6ca1.513034","9c3eb96c.495f88"]]},{"id":"fc05aac9.eebb78","type":"http in","z":"6967cd61.ab44a4","name":"","url":"/receipt","method":"post","upload":false,"swaggerDoc":"","x":280,"y":380,"wires":[["48d1472e.7b5a98","59d1579e.7b2cf8"]]},{"id":"48d1472e.7b5a98","type":"http response","z":"6967cd61.ab44a4","name":"","statusCode":"200","headers":{},"x":660,"y":380,"wires":[]},{"id":"59d1579e.7b2cf8","type":"debug","z":"6967cd61.ab44a4","name":"DLR","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":620,"y":480,"wires":[]},{"id":"1451d574.e9e2fb","type":"comment","z":"6967cd61.ab44a4","name":"❓ About this path - Send SMS","info":"## Sending an SMS with Nexmo\n\n### The **`sendsms`** node\n\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\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. For example 447401234567.|\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).| \n| `TEXT`     | The content of your message. Feel free to get creative, but a 'Hello World!' will do just as well.\n\n\n### The **`inject`** node \n\nIt is wired as an input for **`sendsms`**. \n\nThis is quite a powerful one, it can initiate the flow with a specific payload value. It supports injecting strings, numbers, booleans, JavaScript objects, or flow/global context values, having the timestamp of the current time in millisecs since January 1st, 1970 as default.\n\nYou could simply use it to set off your flow, while hardcoding all parameters in the **`sendsms`** node, or you could take it a step further.\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\nKnowing that the timestamp is injected, let's add this value to the message text by referencing **{{msg.payload}}**, for example:\n```\nHello World! The timestamp is {{msg.payload}}.\n```\n\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\nHit **Deploy** and click the **`inject`** node's button - your SMS should be on its way!\n","x":190,"y":140,"wires":[]},{"id":"abaf83e2.eb359","type":"comment","z":"6967cd61.ab44a4","name":"❓ About this path - Handle Delivery Receipt","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 `POST` 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### 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. 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```\nYour local server now has a ngrok URL that can be used as your webhook endpoint.\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_NGROK_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":230,"y":320,"wires":[]},{"id":"b657ac79.831de","type":"inject","z":"6967cd61.ab44a4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":220,"wires":[["83595ef2.25cf7"]]},{"id":"f2551c29.cf631","type":"comment","z":"6967cd61.ab44a4","name":"📖 Check out the tutorial","info":"🔗Go to the step-by-step [tutorial](https://www.nexmo.com/blog/2019/04/17/send-sms-messages-node-red-dr/)","x":170,"y":40,"wires":[]}]

Flow Info

Created 6 years, 2 months ago
Updated 5 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

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

Tags

  • SMS
  • send-sms
  • delivery-receipt
  • messaging
  • nexmo
  • API
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option