Overview

Skill Level: Any Skill Level

A small understanding of Javascript and JSON will help

With the instructions given, you will learn how to create a simple chatbot, powered by Watson Assistant, which will then connect to virtually any API.

Ingredients

  1. Create an account on IBM Cloud via the following link: https://console.bluemix.net/registration/
  2. Download Telegram app on your phone, or PC, or run it directly from the browser
  3. Spotify account. You can regsiter from the following link: https://www.spotify.com/signup/

Step-by-step

  1. Create a new bot on Telegram's BotFather

    1. Run the Telegram app
    2. Search for @BotFather at the search bar on top and select it

      Search for @BotFather

    3. send /newbot command / message to BotFather
    4. Enter the name and username of your bot, for example:
      • name: Watson¬†Chat Bot
      • username: WatsonChat<your_initials>Bot¬†(Replace <your_initials> with your initials or any other names)
    5. Once created, you’ll be given a token string

      ChatBot Creation

    6. Save the token on your favorite text editor

    More info on Telegram’s BotFather
    BotFather is the one bot to rule them all. It will help you create new bots and change settings for existing ones.

  2. Create a Node-RED app using the Node-RED Starter boilerplate

    1. Login into the IBM Cloud console via the following link: https://console.bluemix.net
    2. Click Create Resources
    3. Search and select Node-RED Starter boilerplate
    4. Enter the App name and Host name
      • App name: WatsonChatBot
      • Host name: WatsonChat<your_initials>Bot

      Node-RED Starter Boilerplate

    5. Click Create
    6. Once the app has been started (it will take a few minutes for the Node-Red app to be started), click Visit App URL or go to the url of the app directly
    7. Next, before we are able to use the app, there are some minor setup need to be done. It will ask for the Username and Password for the app. Enter the Username and Password accordingly.


    8. Click Next then Finish

    More info on IBM Cloud’s Node-RED
    Node-RED is available on the IBM Cloud platform as one of the boilerplate applications in the catalog.
    We also provide a ‚ÄėDeploy To IBM Cloud‚Äô enabled repository.

  3. Install Telegram Nodes on Node-RED

    1. Once the app has been started, click Visit App URL or go to the url of the app directly
    2. Click on the Go to your Node-RED flow editor or add /red path to the url to view the Node-RED flow. For example:
      • https://WatsonChatSASBot.mybluemix.net/red/
    3. Click on the top-right menu and select Manage pallete


    4. Click on the Install tab
    5. Enter telegram on the search module textbox
    6. Click install for node-red-contrib-telegrambot


    7. Then click Install again to confirm
    8. Once the node has been installed, click Done
      • Note: There will be 4 telegram nodes installed
  4. Create a Simple Chat Flow

    For a simple chat flow, we will going to create an echo flow, which will only echo the command sent to the chatbot

    1. Drag the telegram command node from the pallete onto the workspace
    2. Double click the added Telegram Command node to edit it
    3. Enter /echo as the Command

      06-1

    4. Click the pencil icon to add the new telegram bot that we have created earlier
    5. Enter the following values:
      • Bot-Name: WatsonChatBot
      • Token:¬†<telegram_bot_token>


    6. We can ignore the Users and ChatIds fields for now
    7. Click Add and then Done
    8. Drag the telegram sender node from the pallete onto the workspace
    9. Double click the added Telegram Sender node to edit it
    10. At the dropdown Bot selection, select the bot you have configured earlier, WatsonChatBot
    11. Click Done
    12. Connect the first output from the Telegram Command node to the input of the Telegram Sender node


    13. Then, click the Deploy button
  5. Test the Simple Chat Flow

    1. On your Telegram app add the bot that you have created as a contact
    2. Send the following message:

      /echo <any_message_here>

    3. You should receive the same message back, without the /echo command


  6. Create and Configure Watson Assistant Service

    1. Open IBM Cloud console
    2. Click Create Resource
    3. Select Assistant under Watson

      Watson Assistant

    4. You can leave everything as default and click Create. However, if the region is not supported, just select US South
    5. Once created, click on the Connections tab and click on the Create Connection


    6. Select the WatsonChatBot app and click Connect
    7. Click Restage
    8. Go back to the Manage tab and click on the  button to launch the Watson Assistant portal
    9. Login with the same IBM ID & password if it asks for it
    10. Create a new workspace by clicking Create
    11. Enter Watson Chat Bot as the Name and click Create

      Watson Assistant

    12. Go back to the list of workspaces, click at the top-right of the newly created workspace card, and click View details
    13. Copy the Workspace ID onto your favorite text editor
    14. Open back your newly created workspace, click on the top-left menu, select Build then select Intents
    15. Click Create new to create a new intent
    16. Enter the following values then click Create:
      • Intent name: greetings
      • User example:
        • hello
        • hi
        • howdy
        • apa khabar
        • hey

      13-1

    17. Create another one with the following values:
      • Intent name:¬†farewells
      • User example:
        • goodbye
        • bye
        • so long
        • see you later
        • jumpa lagi


    18. Click on the Dialog tab to configure the dialog flow


    19. Click Add node button
    20. Enter the following, then click the X button at the top-right:
      • Name this node: Greetings
      • If bot recognizes:¬†#greetings
      • Then respond with:¬†hello


    21. Then, click the button on the right of the Greetings node and click Add node below to create another node. (You can also click Add node at the top)
      • Name this node: Farewells
      • If bot recognizes:¬†#farewells
      • Then respond with:¬†goodbye
    22. To test it, click on the btnDialog icon at the top-right, to open a chat box
    23. Try saying the user examples that we created earlier, and it should response accordingly
    24. Even with some minor typos, or missing words, it may recognize your intent and response accordingly


  7. Integrate Watson Assistant Service into Node-RED

    1. Open the Node-RED flow created earlier
    2. Add another flow with the following connection sequence of nodes and connect the output of the node to the input of the next node:
      1. telegram command
      2. function
      3. conversation
      4. function
      5. telegram sender


    3. Configure both telegram nodes to use the WatsonChatBot and set the Telegram Command to use the /watson command
    4. Double click the 1st function node to configure it
    5. Enter Prepare for Conversation as the Name
    6. Enter the following as the Function and click Done

      msg.chatId = msg.payload.chatId;
      msg.payload = msg.payload.content;
      return msg;


    7. Double click the Assistant node to configure it
    8. Enter the Workspace ID that you have copied earlier, then click Done
    9. Double click the 2nd Function node to configure it
    10. Enter Prepare for Telegram as the Name
    11. Enter the following as the Function and click Done

      msg.payload = {
        chatId : msg.chatId,
        type : "message",
        content : msg.payload.output.text[0]};
      return msg;


    12. Then click the button


  8. Test Watson Assistant Integration with Node-RED on Telegram

    1. On your Telegram app send the following message to the chat bot:

      /watson apa khabar

    2. You should receive hello message back
    3. Try with farewell messages instead
    4. You should receive goodbye message back


  9. Create and Configure Language Translator Service

    1. Open IBM Cloud console
    2. Click Create Resource
    3. Select Language Translator under Watson


    4. You can leave everything as default and click Create
    5. Once created, click on the Connections tab and click on the Create Connection
    6. Select the WatsonChatBot app and click Connect
    7. Click Restage
  10. Integrate Language Translator with Watson Assistant & Node-RED

    1. Go back to the Watson Assistant Tool or launch it back if it is closed
    2. Create a new intent with the following by clicking Create:
      • Intent name:¬†translate
      • User example:
        • Can you translate?
        • Please translate
        • Translate
        • Do you know how to translate?
        • Translate for me please


    3. Click on the Entities tab and click the Create new button
    4. Enter the following and click Create:
      • Entity name:¬†language
      • Values:
        1. English
        2. French
        3. Italian
        4. Spanish


    5. Click on the Dialog tab and add a new dialog node under #farewell
    6. Enter the following and click the X button:
      • Name this node: Translate
      • If bot recognizes: #translate
      • Then respond with:¬†What language do you want to translate from?


    7. Add a new child node under #translate
    8. Enter Source Language as the Name, @language on the Trigger, click on the button on the right under Then respond with, and click Open JSON Editor
    9. Enter the following text:

      {
      "context": { "source": "@language" },
      "output": {
      "text": {
      "values": [ "What language do you want to translate to?" ]}}}


    10. Add another child node
    11. Enter Destination Language as the Name, @language on the Trigger, click on the button on the right under Then respond with, and click Open JSON Editor
    12. Enter the following text:

      {
      "context": { "destination": "@language" },
      "output": {
      "text": {
      "values": [ "What is the text that you want to translate?" ]}}}


    13. Add another child node
    14. Enter Do Translate as the Name, true on the Trigger, click on the button on the right under Then respond with, and click Open JSON Editor
    15. Enter the following text:

      {
      "context": { "action" : "translate" },
      "output": {}
      }



    16. Go back to the Node-RED workspace
    17. Add the switch node and position it at the right of the conversation node
    18. Double click the switch node and set the Property to msg.payload.context.action
    19. At the option below it, select == and enter translate as the value
    20. Click +add and select otherwise then click Done


    21. Add a function node next to the switch node
    22. Double click the function node to configure it
    23. Enter Prepare for Translator as the Name
    24. Enter the following as the Function and click Done


      msg.srclang = getLanguage(msg.payload.context.source);
      msg.destlang = getLanguage(msg.payload.context.destination);
      msg.payload = msg.payload.input.text;

      return msg;

      function getLanguage(lang) {
      switch (lang.toLowerCase()) {
      case "french":
      return "fr";
      case "italian":
      return "it";
      case "spanish":
      return "es";
      }
      return "en";
      }

    25. Next, add the language translator node
    26. Double click the language translator node to configure it
    27. Set Domains to Conversational, leave other values to default and click Done


    28. Next, add another function node, name it as Prepare for Telegram 2 and put it to the right of the language translator node
    29. Enter the following as the Function and click Done


      msg.payload = {
      chatId : msg.chatId,
      type : "message",
      content : msg.payload
      };
      return msg;

    30. Add one more function node next to the language translator node and name it Clear Conversation Context
    31. Enter the following as the Function and click Done


      msg.payload = "hi";
      msg.params = {
      context : {}
      }
      return msg;

    32. Copy the conversation node, put it next to the Clear Conversation Context function node and name it conversation 2
    33. Disconnect the connection between the conversation and Prepare for Telegram node
    34. Connect the following nodes accordingly
      1. conversation > switch
      2. switch (1st output) > Prepare for Translator
      3. Prepare for Translator > language translator
      4. language translator > Prepare for Telegram 2
      5. Prepare for Telegram 2 > Telegram Sender
      6. language translator > Clear Conversation Context
      7. Clear Conversation Context > conversation 2
      8. switch (2nd output) > Prepare for Telegram
    35. Then, click the Deploy button


  11. Test Language Translator Integration with Node-RED on Telegram

    1. On your Telegram app send the following message to the chat bot:

      /watson please translate

    2. You should receive a reply asking for the source language. Reply:

      /watson english

    3. You should receive a reply asking for the target language. Reply:

      /watson french

    4. You should receive a reply asking for the text to be translated. Reply with the text you want to translate, for example:

      /watson Where is the nearest restroom?

    5. You should receive a reply with the translated text


  12. Create and Configure 3rd Party API, Spotify

    Since the endpoint of the Spotify API that we are going to use does not require any authorization, you won’t need to register with the service. Recently, Spotify has updated their API and it requires providing a token in order to use the search API. The method that we’re using to obtain the token will expire and not meant to be used on production or an actual chat bot, but for the sake of simplicity, we’ll use a “shortcut” method to obtain the token.

  13. Get Spotify's OAUTH Token

    1. Browse to the following link:
    2. Click GET OAUTH TOKEN


    3. Click REQUEST TOKEN since we’re just performing simple search


    4. Click LOGIN TO SPOTIFY if you’re already signed up


    5. Enter your username and passowrd, then click LOG IN


    6. Confirm access by clicking OKAY


    7. Your token will appear in the OAuth Token field. Copy it and paste it in a text editor to be used for later.
  14. Integrate Spotify REST API with Watson Assistant & Node-RED

    1. Go back to the Watson Assistant Tool or launch it back if it is closed
    2. Create a new intent with the following:
      • Intent name:¬†music
      • User example:
        • Play some music
        • Can you turn on the music
        • Music
        • Play song
        • Play some song


    3. Click on the Entities tab and click Create new
    4. Enter the following and click Create:
      • Entity name:¬†genre
      • Values:
        1. jazz
        2. pop
        3. classical
        4. rock


    5. Click on the Dialog tab and add a new node below Translate
    6. Enter the following:
      • Name this node: Music
      • If bot recognizes: #music
      • Then respond with:¬†What music genre¬†do you want me to play?


    7. Add a new child node under Music
    8. Enter Play Music as the Name, @genre on the Trigger, click on the button on the right under Then respond with, and click Open JSON Editor
    9. Enter the following text:

      {
      "context": {
      "genre": "@genre",
      "action" : "music"
      },
      "output": {}
      }



    10. Go back to the Node-RED workspace
    11. Double click the switch node
    12. Click +add and select otherwise
    13. For the 2nd argument, change to == and music then click Done


    14. Add a function node next to the switch node
    15. Double click the function node to configure it
    16. Enter Prepare for Spotify as the Name
    17. Enter the following as the Function and click Done


      msg.genre = msg.payload.context.genre;
      msg.headers = {
      "Authorization" : "Bearer <YOUR_TOKEN>"
      };
      return msg;

    18. Next, add the http request node and put it next to the Prepare for Spotify function node
    19. Double click the http request node to configure it
    20. Set the following fields and click Done:

    21. Add another function node, name it as Prepare for Telegram 3 and put it next to the Spotify Search API node
    22. Enter the following as the Function and click Done


      var items = msg.payload.tracks.items;
      var rndm = Math.floor((Math.random() * items.length));
      var item = items[rndm];
      var artists = [];
      for (var i in item.artists) {
      artists.push(item.artists[i].name);
      }
      title = item.name;
      content = "I have found " + title + " by " + artists.join(", ") + ".";
      if (item.external_urls && item.external_urls.spotify) {
      content += "\nClick on the following link to open it on Spotify:\n" + item.external_urls.spotify;
      }
      msg.payload = {
      chatId : msg.chatId,
      type : "message",
      content : content
      };
      return msg;

    23. Disconnect the 2nd output of the switch node
    24. Connect the following nodes accordingly
      1. switch (2nd output) > Prepare for Spotify
      2. Prepare for Spotify > Spotify Search API
      3. Spotify Search API > Prepare for Telegram 3
      4. Prepare for Telegram 3 > Telegram Sender
      5. Spotify Search API > Clear Conversation Context
      6. switch (3rd output) > Prepare for Telegram


    25. Then, click the Deploy button
  15. Test Spotify API Integration with Node-RED on Telegram

    1. On your Telegram app send the following message to the chat bot:

      /watson play some music

    2. You should receive a reply asking for the genre of the music. Reply:

      /watson rock

    3. You should receive a reply with a random song title and it’s artists.


37 comments on"How to create a Watson Chatbot on Node-RED"

  1. Hello, Shaharuddin. Is there any way not to use / command? I wanna use / command just first time like ‘/start’, not always.

    • Aiman Shaharuddin April 10, 2017

      Hi Hayun,

      Thanks for trying out the recipe!

      If you don’t want to use the /command (which uses the telegram command node), you can use the telegram receiver node instead.

      • Thanks, it works well!

        Also, i used ‘context’ and save some variables, but the telegram saved them when my bot was initialized(stop bot)

        Could you give me an advice to remove context variables when the bot stopped?

        • Aiman Shaharuddin April 11, 2017

          What do you mean by “bot stopped”? If you’re storing your own context, then basically, you can set the context to empty object {}. If you’re using conversation to store the context, at the end of the bot, you send end empty object to the conversation’s context as well.

          • I mean initializing ‘context’ when a chat-room is deleted. I used context node and delete msg.chatId & msg.payload, but it didn’t work.

  2. Great tutorial with clear instructions. I enjoyed playing and learning new things by going through this tutorial. Thanks for writing and sharing.

  3. Aiman Shaharuddin May 13, 2017

    Thanks gurdeep! Glad you enjoyed it. Will provide more similar recipes in the future.

  4. ASKC_Tony_Pigram May 22, 2017

    I’ve walked through the start of this recipe. works great. when I created the ‘Language Translator’, I added it as a Connection to the nodeJS app, but in Node Red when it gets executed, it throws the following error when it attempts to call ‘language translator’:
    22/05/2017, 13:17:31node: efaf2071.0b4e38msg : error
    “Error: cannot find service matching the request data”

    I’ve set it to ‘Conversational’ as recommended, but it just doesn’t seem to pickup the language service. The conversation service works fine, I can call /watson hello and /watson goodbye and they work as expected. I’ve restaged the nodeJS app also. any ideas?

    • Aiman Shaharuddin May 24, 2017

      what’s the source and target language that you’ve tried? Usually this error comes if the language is not supported

    • ASKC_Tony_Pigram May 24, 2017

      okay, looks like I resolved it. The country values are case sensitive. I created the Entities with all lowercase and the code to switch the language was 1st letter uppercase. Therefore, it was trying to translate en -> en, even if I entered english to spanish. After changing that, it works okay now.

  5. holger.wieprecht@de.ibm.com May 29, 2017

    Hello Aiman,

    great idea to use the Telegram messenger. This way one can use it with mobile devices too.

    However, I run into a problem. It seems that Spotify search – chapter (12) – requires OAuth Authorization: https://developer.spotify.com/web-api/console/get-search-item/ .
    Since I’m not a programmer I could do with your help to get a proper ‘curl -X GET’ request inserted in line (13/20) to properly address the Spotify API. A proper OAuth Token can be requested from Spotify after registration.

    Looking forward your answer
    Holger

    • Aiman Shaharuddin May 31, 2017

      Are you familiar with the HTTP Request node? Basically, you need to set the msg.headers with the appropriate headers. Here’s a sample request from the spotify search:
      =============================
      curl -X GET “https://api.spotify.com/v1/search?q=Muse&type=track,artist&market=US” -H “Accept: application/json” -H “Authorization: Bearer abscasdasdasd”
      =============================

      so, you need to set the msg.headers in a function node as the following:
      =============================
      msg.headers = {
      “Authorization”: “Bearer abscasdasdasd”
      }
      =============================

      Since the json response can be set directly on the HTTP request node, you don’t have to set it in the headers

  6. OkeletsangPalesaTsheole June 06, 2017

    please help
    i would like to connect this chat bot wit discovery

  7. IgorMonteiro August 25, 2017

    I can’t pass msg.payload value as query into Watson Discovery Node:
    [{“id”:”55eb8b15.4ac8b4″,”type”:”tab”,”label”:”Flow 4″},{“id”:”c2e12406.2e9708″,”type”:”watson-discovery-v1″,”z”:”55eb8b15.4ac8b4″,”name”:”List Environments”,”environmentname”:””,”environment_id”:”9a79288d-6756-45d2-94f1-40e2452d2c20″,”collection_id”:””,”configurationname”:””,”configuration_id”:””,”collection_name”:””,”count”:””,”passages”:false,”nlp_query”:false,”query”:””,”filter”:””,”aggregation”:””,”return”:””,”description”:””,”size”:””,”discovery-method”:”listCollections”,”x”:610.4000854492187,”y”:977.5999450683594,”wires”:[[“6a405cfc.c06b6”]]},{“id”:”71318728.bd29bc”,”type”:”debug”,”z”:”55eb8b15.4ac8b4″,”name”:””,”active”:true,”console”:”false”,”complete”:”true”,”x”:908.10009765625,”y”:974.4000244140625,”wires”:[]},{“id”:”652495c9.a5953″,”type”:”watson-discovery-v1-query-builder”,”z”:”55eb8b15.4ac8b4″,”name”:””,”password”:”T3clado!”,”environment”:”9a79288d-6756-45d2-94f1-40e2452d2c20″,”environmenthidden”:”9a79288d-6756-45d2-94f1-40e2452d2c20″,”collection”:”fc0b072b-8932-4d79-b68b-27fb12c0a9d1″,”collectionhidden”:”fc0b072b-8932-4d79-b68b-27fb12c0a9d1″,”nlp_query”:true,”nlp_queryhidden”:”true”,”querynlp”:””,”querynlphidden”:””,”query1″:””,”query1hidden”:””,”queryvalue1″:””,”queryvalue1hidden”:””,”query2″:””,”query2hidden”:””,”queryvalue2″:””,”queryvalue2hidden”:””,”query3″:””,”query3hidden”:””,”queryvalue3″:””,”queryvalue3hidden”:””,”passages”:false,”passageshidden”:”false”,”x”:621.300048828125,”y”:912.89990234375,”wires”:[[“c2e12406.2e9708”]]},{“id”:”f66eacc3.0d53d”,”type”:”http response”,”z”:”55eb8b15.4ac8b4″,”name”:””,”statusCode”:””,”headers”:{},”x”:912.989990234375,”y”:1059.5299224853515,”wires”:[]},{“id”:”77a1a225.eb1fc”,”type”:”http in”,”z”:”55eb8b15.4ac8b4″,”name”:””,”url”:”/tutor”,”method”:”get”,”upload”:false,”swaggerDoc”:””,”x”:116.39999389648437,”y”:599.2000122070312,”wires”:[[“526e5320.c16b78”]]},{“id”:”849a55a3.e63998″,”type”:”http in”,”z”:”55eb8b15.4ac8b4″,”name”:””,”url”:”/searchpost”,”method”:”post”,”upload”:false,”swaggerDoc”:””,”x”:118,”y”:803.1999816894531,”wires”:[[“9979d4ad.80549″,”920ca369.a835f”]]},{“id”:”526e5320.c16b78″,”type”:”function”,”z”:”55eb8b15.4ac8b4″,”name”:”msg.url = \”searchpost\”;”,”func”:”msg.url = \”searchpost\”;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:376.3999938964844,”y”:599.2000122070312,”wires”:[[“dfb13d3d.2e7db8”]]},{“id”:”9979d4ad.80549″,”type”:”debug”,”z”:”55eb8b15.4ac8b4″,”name”:””,”active”:false,”console”:”false”,”complete”:”payload”,”x”:786.3999938964844,”y”:799.2000122070312,”wires”:[]},{“id”:”821cc224.88a84″,”type”:”http response”,”z”:”55eb8b15.4ac8b4″,”name”:””,”x”:806.3999938964844,”y”:759.2000122070312,”wires”:[]},{“id”:”bf6ea79a.72cb88″,”type”:”template”,”z”:”55eb8b15.4ac8b4″,”name”:”CSS”,”field”:”payload.style”,”fieldType”:”msg”,”format”:”html”,”syntax”:”mustache”,”template”:”input[type=text], select {\n width: 100%;\n padding: 12px 20px;\n margin: 8px 0;\n display: inline-block;\n border: 1px solid #ccc;\n border-radius: 4px;\n box-sizing: border-box;\n}\n\ninput[type=submit] {\n width: 100%;\n background-color: #4CAF50;\n color: white;\n padding: 14px 20px;\n margin: 8px 0;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n}\n\ninput[type=submit]:hover {\n background-color: #45a049;\n}\n\ndiv {\n border-radius: 5px;\n background-color: #f2f2f2;\n padding: 20px;\n}”,”output”:”str”,”x”:526.3999938964844,”y”:699.2000122070312,”wires”:[[“4e9e6c65.c2d9d4”]]},{“id”:”dfb13d3d.2e7db8″,”type”:”template”,”z”:”55eb8b15.4ac8b4″,”name”:”JavaScript”,”field”:”payload.script”,”fieldType”:”msg”,”format”:”javascript”,”syntax”:”plain”,”template”:”$(document).ready(function(e) {\n \n $(\”form[ajax=true]\”).submit(function(e) {\n \n e.preventDefault();\n \n var form_data = $(this).serialize();\n var form_url = $(this).attr(\”action\”);\n var form_method = $(this).attr(\”method\”).toUpperCase();\n \n $(\”#loadingimg\”).show();\n \n $.ajax({\n url: form_url, \n type: form_method, \n data: form_data, \n cache: false,\n success: function(returnhtml){ \n $(\”#result\”).html(returnhtml); \n $(\”#loadingimg\”).hide(); \n } \n }); \n \n });\n \n});”,”output”:”str”,”x”:366.3999938964844,”y”:699.2000122070312,”wires”:[[“bf6ea79a.72cb88”]]},{“id”:”1e9245dc.77cd46″,”type”:”http response”,”z”:”55eb8b15.4ac8b4″,”name”:””,”statusCode”:””,”headers”:{},”x”:806.3999938964844,”y”:699.2000122070312,”wires”:[]},{“id”:”4e9e6c65.c2d9d4″,”type”:”template”,”z”:”55eb8b15.4ac8b4″,”name”:”HTML”,”field”:”payload”,”fieldType”:”msg”,”format”:”handlebars”,”syntax”:”mustache”,”template”:”\n \n Watson Tutor\n \n \n http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js\n {{{payload.style}}}\n \n \n\n \n \n \n \n \n\n\n \n\n\n\n\n\n{{{payload.script}}}\n”,”output”:”str”,”x”:666.3999938964844,”y”:699.2000122070312,”wires”:[[“1e9245dc.77cd46”]]},{“id”:”a2bca170.9d05f”,”type”:”comment”,”z”:”55eb8b15.4ac8b4″,”name”:”Login Form”,”info”:””,”x”:311.1999816894531,”y”:656.8000183105469,”wires”:[]},{“id”:”8df3f3fb.c3e168″,”type”:”function”,”z”:”55eb8b15.4ac8b4″,”name”:”return msg.payload to client”,”func”:”msg.payload = ‘Submitted msg.payload: ‘+msg.payload;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:598.0000610351562,”y”:745.6000061035156,”wires”:[[“821cc224.88a84”]]},{“id”:”7179687c.28a6e”,”type”:”comment”,”z”:”55eb8b15.4ac8b4″,”name”:”Inject msg object properties”,”info”:””,”x”:336.3999938964844,”y”:559.2000122070312,”wires”:[]},{“id”:”920ca369.a835f”,”type”:”json”,”z”:”55eb8b15.4ac8b4″,”name”:”igor”,”pretty”:false,”x”:327.1999816894531,”y”:762.4000244140625,”wires”:[[“652495c9.a5953”]]},{“id”:”4fd2b6ba.6914d8″,”type”:”comment”,”z”:”55eb8b15.4ac8b4″,”name”:”Website”,”info”:””,”x”:106.39999389648437,”y”:519.2000122070312,”wires”:[]},{“id”:”4b1fc65a.6eed”,”type”:”comment”,”z”:”55eb8b15.4ac8b4″,”name”:”Form Submission”,”info”:””,”x”:136.39999389648437,”y”:739.2000122070312,”wires”:[]},{“id”:”6a405cfc.c06b6″,”type”:”function”,”z”:”55eb8b15.4ac8b4″,”name”:”msg.payload”,”func”:”msg.payload = ‘Submitted msg.payload: ‘+msg.payload;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:658.0000610351562,”y”:1064.1998901367187,”wires”:[[“f66eacc3.0d53d”,”71318728.bd29bc”]]},{“id”:”1899b2cf.22b811″,”type”:”function”,”z”:”55eb8b15.4ac8b4″,”name”:”msg.discoveryparams “,”func”:”msg.payload;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:443.199951171875,”y”:852.9999694824219,”wires”:[[]]}]

  8. Aiman Shaharuddin December 06, 2017

    Updated some of the screenshots and wording to reflect on the changes on IBM Cloud and Watson Conversation. But not all screenshots have been updated. ūüėÄ

  9. @Aiman Shaharuddin, is there any official document for connecting watson conversation+node-red with facebook messenger or Line bot ? Thanks

  10. under node-red->language translater->there a error message: model not found, and the debug said: 2017/12/13 šłčŚćą5:05:39node: 5e3ed9e5.915d98
    msg : string[16]
    “Model not found.”
    2017/12/13 šłčŚćą5:05:39node: conversation 2
    msg : string[24]
    “Overridden saved context”
    2017/12/13 šłčŚćą5:07:08node: 95f55e31.1f60a
    msg : string[29]
    “Missing property: msg.payload”
    2017/12/13 šłčŚćą5:33:24node: 5e3ed9e5.915d98
    msg : string[16]
    “Model not found.”

    any advice would be appreciated

    • Aiman Shaharuddin December 16, 2017

      hi @Joe_Yang, sorry for the late reply, what’s the source and destination language that you were trying to translate?

  11. TurtleBotBot December 21, 2017

    @Aiman Shaharuddin, I went through your tutorial – it’s great and I really enjoyed learining that way. However, I got stuck on deploying the Watson Conversation in Node-RED. I copied commands, everything seems to be connected successfully. The /echo command worked, however, the bot doesn’t reply to /watson. What could I do to find out what’s the error?

    • Aiman Shaharuddin December 21, 2017

      hi @TurtleBotBot, glad that you’re enjoying it. For a start, you may want to check if there’s any output coming from the conversation node. You can add a “debug” node, link it to the output of conversation and test if it receives any messages.

  12. great tutorial! very clear and up to date. Could you share the source code, i.e. for conversation flow, and node red flow?

  13. hi, i encountered a problem when node-red process to “Prepare for Telegram 3” node and the debug show
    2018/1/4 šłčŚćą4:10:17node: Prepare for Telegram3
    function : (error)
    “TypeError: Cannot read property ‘items’ of undefined”

    looking forward your answer. thanks!

  14. verena.bierig@ibm.com January 23, 2018

    Hi Aiman, really good Recipe! One question: when /watson selected a song and artist, is it possible to actually open spotify and play that song?
    Thank you in advance!

    • Aiman Shaharuddin January 23, 2018

      I’ve updated my code on step 22 for the Prepare for Telegram 3 node. So, basically if you use the item.external_urls.spotify and click on the link from your mobile (or desktop), it’ll open up the Spotify for that particular song track.

  15. Hi Aiman,
    Thanks for posting this. Is there a way to call a API through node red if a certain string is entered in telegram? For the sake of this example if the user entered “1234” then a external API GET would be triggered.

    • Aiman Shaharuddin February 23, 2018

      you can add a switch node to check if the message/payload contains 1234 before the WCS node. Then route the message to the HTTP node to make a GET request to the intended API

  16. Hi Mr. Aiman,

    Thank you for the useful tutorial . I’ve walked through this tutorial, works great.

    I would like to check if you have tutorial the step by step instructions on how to create a simple Watson Chatbot on Node-Red, integrated with Watson tone analyzer using Telegram?

  17. ronakjain539 June 21, 2018

    Hey Aiman sir,
    I am getting this error in debug “TypeError: Cannot read property ‘toLowerCase’ of undefined” for “prepare for translator” node.
    please help

    • Stefan Sander March 21, 2019

      Hi, ronakjain539,
      I also had the error message ‚ÄúTypeError: Cannot read property ‚ÄėtoLowerCase‚Äô of undefined‚ÄĚ for ‚Äúprepare for translator‚ÄĚ node.
      What I did to solve the problem was to delete the ‘toLowerCase’ from the code so you can continue.
      But later then when I got to the Language Translator I got the error message “Model not found” at the Language Translator node and “overridden context” at the conversation 2 node.
      To solve this i wrote the ‘toLowerCase’ back in the code and it worked.

  18. Ruofan Li July 09, 2019

    Great job !!!
    but i have a question , in Part 2 How should i stop the translation, back to the conversation ? or which command should i type into ?

Join The Discussion