Skill Level: Beginner

Simply copy-and-paste and follow some directions, to create your first SMS Chatbot

Want to use the easy Watson Conversation service and share your invention? This recipe will help you connect Watson Conversation with SMS text messaging.


Bluemix account


  1. Create your Node-RED application

    Your Node-RED application is where you'll put your application's logic. It will receive SMS text messages from Twilio, and call the Watson Conversation service. 

    1. Log into Bluemix

    2. Create new application from the Node-RED Starter Boilerplate

    3. (Optional, for security) Update the username and password with Environment Variables

  2. Add the Watson Conversation service

    For reference, we are using this Watson Conversation demo. In this demo, imagine you're in the driver's seat and Watson is your co-pilot. Watson can understand your entries and respond accordingly.

    1. Go to your Node-RED application in Bluemix

    2. Add the Conversation service…Bluemix will probably ask you to restage the application. 

    3. Import the Workspace, using these instructions. Make sure to copy your Workspace ID.

    You won't need the Credentials, because of Watson Conversation integration in Node-RED on Bluemix

  3. Set up your Twilio SMS service

    Twilio provides telephone services over APIs. You'll use Twilio to send and receive SMS text messages. 

    1. In Bluemix, connect a new Twilio account (or your existing one). Follow directions to connect credentials. 

    2. Get a Twilio phone number. You don't need to pay for the account yet… you'll just see that Twilio adds a message into your texts

    3. Set up your Twilio account to forward SMS messages to your Bluemix service /twiliosms


    (Hat tip to these instructions)


  4. Import the Node-RED flow

    This Node-RED flow is the glue which connects all your services. 

    1. Copy the code below (it's longer than the box you see)
    2. In Node-RED, open the menu in the upper-right corner
    3. Select Import, then Clipboard. 
    4. Paste in this JSON

    Some people have trouble if the quotation marks are curly, instead of the plain-vanilla straight quotes. Please respond in the comments if you are having trouble with this step after August 29th 2016.

    [{"id":"c04f47b0.a09808","type":"http in","z":"b7e09aa9.bb171","name":"","url":"/twiliosms","method":"get","swaggerDoc":"","x":173,"y":135,"wires":[["337f80d0.e51418","d9fb8a2b.6e66c"]]},{"id":"337f80d0.e51418","type":"debug","z":"b7e09aa9.bb171","name":"Request Received","active":false,"console":"false","complete":"payload","x":389,"y":73,"wires":[]},{"id":"546c66d0.8e6d1","type":"cloudant out","z":"b7e09aa9.bb171","name":"log-requests","cloudant":"","database":"log-requests","service":"","payonly":true,"operation":"insert","x":595.5,"y":135,"wires":[]},{"id":"d9fb8a2b.6e66c","type":"function","z":"b7e09aa9.bb171","name":"ReceivedDate","func":"d = new Date();\n\nmsg.payload.ReceivedDate = d.valueOf();\nmsg.payload.ReceivedDateStr = d.toString();\n\nreturn msg;\n","outputs":1,"noerr":0,"x":379,"y":137,"wires":[["f096212d.cade9","546c66d0.8e6d1","d5b699be.e1907"]]},{"id":"f096212d.cade9","type":"debug","z":"b7e09aa9.bb171","name":"Outbound to Log","active":false,"console":"false","complete":"payload","x":616,"y":93,"wires":[]},{"id":"d5b699be.e1907","type":"function","z":"b7e09aa9.bb171","name":"Prepare Request for Conversation","func":"msg.params = {};\nmsg.params.context = {}\nif (flow.get(msg.payload.From)){\n msg.params.context = flow.get(msg.payload.From); \n}\n\n\nflow.set ('From', msg.payload.From);\n\nmsg.payload = msg.payload.Body;\n\nreturn msg;","outputs":1,"noerr":0,"x":557,"y":242,"wires":[["9360139d.f1c208","1f130a9c.98cab5"]]},{"id":"1f130a9c.98cab5","type":"watson-conversation-v1","z":"b7e09aa9.bb171","name":"Conversation","workspaceid":"","x":850,"y":243,"wires":[["284242df.e62d46","83563003.39681","6d6e1072.3ad238","167b02cc.c15c0d","306aca55.cf9536"]]},{"id":"284242df.e62d46","type":"debug","z":"b7e09aa9.bb171","name":"Conversation Response","active":false,"console":"false","complete":"payload","x":1142,"y":176,"wires":[]},{"id":"83563003.39681","type":"debug","z":"b7e09aa9.bb171","name":"Conversation Response.output","active":false,"console":"false","complete":"payload.output","x":1162,"y":218,"wires":[]},{"id":"9360139d.f1c208","type":"debug","z":"b7e09aa9.bb171","name":"Conversation Request","active":false,"console":"false","complete":"true","x":878,"y":190,"wires":[]},{"id":"167b02cc.c15c0d","type":"function","z":"b7e09aa9.bb171","name":"Output Text and Context","func":"var From = flow.get('From');\nmsg.topic = From;\nflow.set(From, msg.payload.context);\n\nmsg.payload = msg.payload.output.text.join();\nreturn msg;","outputs":1,"noerr":0,"x":1163,"y":411,"wires":[["998cb989.47508","225ca04c.3984d","194b7b8c.e6b484","f4ec3f28.0b13c"]]},{"id":"998cb989.47508","type":"debug","z":"b7e09aa9.bb171","name":"Responded via Twilio","active":false,"console":"false","complete":"true","x":1412,"y":348,"wires":[]},{"id":"225ca04c.3984d","type":"twilio out","z":"b7e09aa9.bb171","service":"","twilio":"","from":"","number":"","name":"","x":1377,"y":452,"wires":[]},{"id":"6d6e1072.3ad238","type":"debug","z":"b7e09aa9.bb171","name":"Conversation Response.input","active":false,"console":"false","complete":"payload.input","x":1165,"y":253,"wires":[]},{"id":"194b7b8c.e6b484","type":"debug","z":"b7e09aa9.bb171","name":"msg.payload","active":false,"console":"false","complete":"payload","x":1384.5,"y":384,"wires":[]},{"id":"f4ec3f28.0b13c","type":"debug","z":"b7e09aa9.bb171","name":"msg.topic","active":false,"console":"false","complete":"topic","x":1373.5,"y":418,"wires":[]},{"id":"306aca55.cf9536","type":"debug","z":"b7e09aa9.bb171","name":"Conversation msg","active":false,"console":"false","complete":"true","x":1123.5,"y":296,"wires":[]}]
  5. Make final tweaks before running

    1. In the log-requests node, change the Service name to your Cloudant service

    2. In the Conversation node, change the Workspace ID to your Workspace ID

    3. In the Twilio-live node

    • Change the Service to your service
    • Change the From to your Twilio phone number. The format must include + and country code. For example, in the US, +12125551212 not (212) 555-1212.
    • Leave the SMS to blank. The code will make sure people get their reply.
  6. Test it out!

    Try sending a text from your cellphone to your Twilio number. You should get back a conversational response from Watson. When you reply, Watson will carry on a conversation!

    If things aren't working perfectly, turn on the Debug nodes. You can also create a new Inject node to create fake text messages. 

  7. Recommended next steps

    Now that you have a fully working SMS Chatbot, I suggest you try giving it a more interesting brain. Go into your Watson Conversation service and create a new Workspace. Check out how easy it is to train Watson – simple configuration, no coding. Once you're happy with the new Workspace, just change the Workspace ID in your Node-RED flow, and press Deploy!

7 Comments on "Watson Conversation over SMS"

  1. Would you check that JSON text? I couldn’t import it on Node-RED.

    • danrohtbart August 22, 2016

      Thank you so much for telling me! I’ve fixed the JSON, and it should work now. (my function nodes had some // comments, and those caused a problem during import). If it’s still not working, please let me know!

    • danrohtbart August 29, 2016

      Hi @lockevi, I think I fixed the problem by putting the code into that code block. The curly “smart” quotes were causing Node-RED problems for another person.

  2. This is a great tutorial marred by some confusing instructions. #3 of Step 3 really throws a wrench in the experience. The blog post has very good information but I spent over an hour trying to comprehend it. Ultimately it turned out that I did not have to do anything suggested.

    I was able to import the given JSON (which is really really useful) and just had to use the http://my-node-red-app.mybluemix.net/twiliosms URL on TWILIO.

    Please update the instructions so others don’t go down rabbit holes.

    • danrohtbart October 31, 2016

      Thanks for taking the time to give feedback – this is tremendously helpful feedback. I’ll try to update that section later this week, and I’ll notify you when it’s updated.

  3. This tutorial is amazing, however #3 is extremely confusing. I am having trouble finding my /twiliosms url and where I put it. It appears Twilio has done a huge revamp on their website since the time of this tutorial. #1-2 are fairly self explanitory and I have connected the corrected to my application. However when I send a text message to the Twilio phone number I get their default demo text.

    • Thanks so much for the compliment and feedback. I’ve updated #3 with a screenshot of the new Twilio website. Is this enough help? Or is there something else that could be more helpful?

Join The Discussion