{"id":688,"date":"2016-06-08T17:10:12","date_gmt":"2016-06-08T11:40:12","guid":{"rendered":"http:\/\/new.codingislove.com\/?p=688"},"modified":"2017-01-17T21:05:13","modified_gmt":"2017-01-17T15:35:13","slug":"build-facebook-chat-bot-javascript","status":"publish","type":"post","link":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/","title":{"rendered":"Develop Facebook chat bot using Javascript \u2013 Part 2"},"content":{"rendered":"<p>Continued from <a href=\"https:\/\/codingislove.com\/build-facebook-messenger-bot-javascript\/\" target=\"_blank\">Develop Facebook chat bot using Javascript &#8211; Part 1<\/a><!--more--><\/p>\n<p>Basic verification is complete, Now lets test webhook and see if we are receiving messages sent to bot page to our webhook or not.<\/p>\n<h3>Receiving messages<\/h3>\n<p>Add the following code to server.js<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\napp.post('\/',handleMessage);\r\n<\/pre>\n<p>This code tells express to run handleMessage function whenever a POST request is made.<\/p>\n<p>And add handleMessage function<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction handleMessage(req, res) {\r\n  messaging_events = req.body.entry&#x5B;0].messaging;\r\n  for (i = 0; i &lt; messaging_events.length; i++) {\r\n    event = req.body.entry&#x5B;0].messaging&#x5B;i];\r\n    sender = event.sender.id;\r\n    if (event.message &amp;&amp; event.message.text) {\r\n      text = event.message.text;\r\n      console.log(text);\r\n    }\r\n  }\r\n  res.end('received!');\r\n}\r\n<\/pre>\n<p><strong><em>Note: Dont forget to restart server after making changes in code everytime. Use <a href=\"http:\/\/nodemon.io\/\" rel=\"nofollow\" target=\"_blank\">Nodemon<\/a> if you want to restart server automatically on file change<\/em><\/strong><\/p>\n<p>Messages sent to bot page are sent in an array named messaging with sender Id and message. Sender Id will be used to reply to the sender. Messenger platform may queue the messages sometime and send multiple messages in same POST request, so we make sure that all messages are captured by looping through the messaging array.<\/p>\n<p>We are using console.log(text) to log the message to console for testing.<\/p>\n<p>Subscribe to bot page in app dashboard and you should start receiving messages to webhook as shown in gif below.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.imgur.com\/61B3dcG.gif\" alt=\"Testing messenger bot\" \/><\/p>\n<p>We are building a wiki bot which searches wikipedia and sends relevant results. We will be using wikipedia REST API to search wikipedia and return results. Read more about <a href=\"https:\/\/www.mediawiki.org\/wiki\/API:Main_page\" target=\"_blank\" rel=\"nofollow\">wikipedia API here<\/a><\/p>\n<p>If user sends wiki space &#8216;search query&#8217; then bot should make a request to wikipedia API with search query, return results and send them to user using Facebook send API.<\/p>\n<p>If user sends anything else then bot should reply with a help message <em>Send Wiki space &#8216;Search query&#8217; to search wikipedia.<\/em><\/p>\n<h3>Send a basic Message to user<\/h3>\n<p>Messages can be sent using send API by making a POST request to <span style=\"color:#42b72a\">https:\/\/graph.facebook.com\/v2.6\/me\/messages?access_token=PAGE_ACCESS_TOKEN<\/span><\/p>\n<p>Page Access token can be accessed in messenger platform dashboard.<\/p>\n<p>I&#8217;m using <code>request<\/code>, a NodeJS module which helps in making HTTP requests easier. As we have to make GET requests to wikipedia API and POST requests to messenger send API. Read more about <a href=\"https:\/\/github.com\/request\/request\" target=\"_blank\" rel=\"nofollow\">request module here<\/a><\/p>\n<p>In command line type <code>npm install request --save<\/code><\/p>\n<p>This will install request module and adds it as a dependency in Package.json file. Now lets write some code to send a simple message to user.<\/p>\n<p>Note: Make sure to import request module wherever you are using it.<br \/>\n<code>var request = require('request');<\/code><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar url = &quot;https:\/\/graph.facebook.com\/v2.6\/me\/messages?access_token=&lt;PAGE_ACCESS_TOKEN&gt;&quot; \/\/replace with your page token\r\nfunction sendHelp(id) {\r\nvar options = {\r\n    uri: url,\r\n    method: 'POST',\r\n    json: {\r\n      &quot;recipient&quot;: {\r\n        &quot;id&quot;: id\r\n      },\r\n      &quot;message&quot;: {\r\n        &quot;text&quot;: &quot;Send wiki space 'Your query' to search wikipedia&quot;\r\n      }\r\n    }\r\n  }\r\n  request(options, function(error, response, body) {\r\n    if (error) {\r\n      console.log(error.message);\r\n    }\r\n  });\r\n};\r\n<\/pre>\n<p>This function takes a sender id as parameter and sends a JSON to send API. Read more about <a href=\"https:\/\/developers.facebook.com\/docs\/messenger-platform\/send-api-reference\" target=\"_blank\" rel=\"nofollow\">FB send API here<\/a><\/p>\n<p>Now replace the line <code>console.log(text);<\/code> with <code>sendHelp(sender);<\/code><\/p>\n<p>Now whenever someone sends a message to your bot page, bot replies them with a help message.<\/p>\n<h3>Structured messages in chat bot<\/h3>\n<p>Messenger platform allows 2 types of messages &#8211; Normal text messages and Structured messages. There are 3 types of templates in structured messages allowed by messenger platform. They are Button template, Generic template and receipt template.<\/p>\n<p>Read more about different templates <a href=\"https:\/\/developers.facebook.com\/docs\/messenger-platform\/implementation#send_message\" target=\"_blank\" rel=\"nofollow\">here<\/a><\/p>\n<p>Code examples for structured messages are availabe <a href=\"https:\/\/developers.facebook.com\/docs\/messenger-platform\/send-api-reference\" target=\"_blank\" rel=\"nofollow\">here<\/a><\/p>\n<p>I&#8217;m using generic template for wiki bot as shown in the demo video. Generic template can contain title, description and some buttons which is perfect for this case.<\/p>\n<p>To send a structured message, we just have to send JSON to send API in a specific format.<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-client=\"ca-pub-6724251756140624\"\n     data-ad-slot=\"7279630595\"\n     data-ad-format=\"auto\"><\/ins><\/p>\n<p><script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>Send wikipedia results<\/h3>\n<p>The final part where bot searches wikipedia and sends results. We&#8217;ll be making a GET request to <span style=\"color:#42B72A\">https:\/\/en.wikipedia.org\/w\/api.php?format=json&amp;action=query&amp;generator=search&amp;gsrnamespace=0&amp;gsrlimit=10&amp;prop=extracts&amp;exintro&amp;explaintext&amp;exsentences=5&amp;exlimit=max&amp;gsrsearch=searchquery<\/span><\/p>\n<p>After getting response fron API, results are stuffed into generic template and send to user using messenger bot send API.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction wikibot(query, userid) {\r\n  var queryUrl = &quot;https:\/\/en.wikipedia.org\/w\/api.php?format=json&amp;action=query&amp;generator=search&amp;gsrnamespace=0&amp;gsrlimit=10&amp;prop=extracts&amp;exintro&amp;explaintext&amp;exsentences=5&amp;exlimit=max&amp;gsrsearch=&quot; + query;\r\n  var myTemplate = {\r\n    recipient: {\r\n      id: userid\r\n    },\r\n    message: {\r\n      attachment: {\r\n        type: &quot;template&quot;,\r\n        payload: {\r\n          template_type: &quot;generic&quot;,\r\n          elements: &#x5B;]\r\n        }\r\n      }\r\n    }\r\n  };\r\n  var options = {\r\n    url: url,\r\n    method: 'POST',\r\n    body: myTemplate,\r\n    json: true\r\n  }\r\n  request(queryUrl, function(error, response, body) {\r\n    if (error) {\r\n      console.log(error);\r\n    }\r\n    try {\r\n      body = JSON.parse(body);\r\n      var pages = body.query.pages;\r\n      for (var i = 0 in pages) {\r\n        var myelement = {\r\n          title: &quot;&quot;,\r\n          subtitle: &quot;&quot;,\r\n          buttons: &#x5B;{\r\n            type: &quot;postback&quot;,\r\n            title: &quot;Read more&quot;,\r\n            payload: &quot;Nothing here, Please view in browser&quot;\r\n          }, {\r\n            type: &quot;web_url&quot;,\r\n            url: &quot;&quot;,\r\n            title: &quot;View in browser&quot;\r\n          }]\r\n        };\r\n        myelement.title = pages&#x5B;i].title;\r\n        myelement.subtitle = pages&#x5B;i].extract.substr(0, 80).trim();\r\n        myelement.buttons&#x5B;1].url = &quot;https:\/\/en.wikipedia.org\/?curid=&quot; + pages&#x5B;i].pageid;\r\n        if (pages&#x5B;i].extract != &quot;&quot;) {\r\n        myelement.buttons&#x5B;0].payload = pages&#x5B;i].extract.substr(0, 1000).trim();\r\n        }\r\n        myTemplate.message.attachment.payload.elements.push(myelement);\r\n      }\r\n      options.body = myTemplate;\r\n    }\r\n    catch (err) {\r\n      console.log(&quot;error : &quot; + err.message);\r\n      options = {\r\n        uri: url,\r\n        method: 'POST',\r\n        json: {\r\n          &quot;recipient&quot;: {\r\n            &quot;id&quot;: userid\r\n          },\r\n          &quot;message&quot;: {\r\n            &quot;text&quot;: &quot;Something went wrong, please try again.&quot;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    request(options, function(error, response, body) {\r\n      if (error) {\r\n        console.log(error.message);\r\n      }\r\n      console.log(body);\r\n    });\r\n  })\r\n};\r\n<\/pre>\n<h3>Code Explanation<\/h3>\n<ol>\n<li>This function takes search query and sender id as parameters. Makes a GET request to wikipedia API and returns an array of page results which are saved to <code>pages<\/code> variable.<\/p>\n<\/li>\n<li>\n<p>generic template JSON is saved to <code>mytemplate<\/code> variable. generic template contains <code>elements<\/code> in which page results should be pushed.<\/p>\n<\/li>\n<li>\n<p>Element&#8217;s format is saved in <code>myelement<\/code>. Loop through each page in <code>pages<\/code>, add title sub-title, description to payload button <code>Read more<\/code> and page URL to <code>View in browser<\/code> button and push <code>myelement<\/code> to <code>elements<\/code> array in mytemplate.<\/p>\n<\/li>\n<li>\n<p>Generic template with search results is ready. Now just send it using send API.<\/p>\n<\/li>\n<li>\n<p>If any error occurs with Wikipedia API then send a regular help message.<\/p>\n<\/li>\n<\/ol>\n<h4>Character Limits<\/h4>\n<p>Sending message using Send API has few limits. They are as follows :<\/p>\n<p>Normal message : 320 character limit<\/p>\n<p><strong>Generic Template limits :<\/strong><br \/>\nTitle: 80 characters<br \/>\nSubtitle: 80 characters<br \/>\nCall-to-action title: 20 characters<br \/>\nCall-to-action items: 3 buttons<br \/>\nBubbles per message (horizontal scroll): 10 elements<\/p>\n<p>Note : Message won&#8217;t be sent if these limits are exceeded, so make sure to trim messages to appropriate character limits before they are sent.<\/p>\n<h3> Chat bot payload button<\/h3>\n<p>Payload button is used when bot has to be notified with some data when user clicks a button. In wikibot, payload button is used to let the bot know that user wants to read more information about the search result when he clicks read more button.<\/p>\n<p>When user clicks read more button, a postback is sent to webhook. To identify whether the request is a message or post back, we can check the properties in messaging event. If its a message then there would be a message property else there would be a post back property in messaging event.<\/p>\n<h3>Utiliity functions<\/h3>\n<p>A format message function which is used to trim down page description to 320 characters.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction formatmsg(msg){\r\n    msg = msg.substr(0,320);\r\n    if(msg.lastIndexOf(&quot;.&quot;) == -1) {\r\n        return msg;\r\n    }\r\n    return msg.substr(0,msg.lastIndexOf(&quot;.&quot;)+1);\r\n}\r\n<\/pre>\n<p>One more sendMessage function which takes in sender id and message as parameters and sends message to that sender id. It is same as sendHelp function but takes message as a paramter. This function is used to reply to postbacks.<\/p>\n<h3>Putting it all together<\/h3>\n<p>Final <code>handleMessage<\/code> function looks like this<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction handleMessage(req, res) {\r\n    var messaging_events = req.body.entry&#x5B;0].messaging;\r\n    for (i = 0; i &lt; messaging_events.length; i++) {\r\n        event = req.body.entry&#x5B;0].messaging&#x5B;i];\r\n        var sender = event.sender.id;\r\n        console.log(sender);\r\n        if (event.message &amp;&amp; event.message.text) {\r\n            var text = event.message.text.toLowerCase().trim();\r\n            console.log(text);\r\n            if (text.toLowerCase().substr(0,4) == 'wiki') {\r\n                wikibot(text.replace(&quot;wiki &quot;, &quot;&quot;),sender)\r\n            }\r\n            else {\r\n                sendHelp(sender);\r\n            }\r\n        }\r\n        else if(event.postback &amp;&amp; event.postback.payload){\r\n           sendMessage(sender,event.postback.payload) ;\r\n        }\r\n    }\r\n    res.end('replied!');\r\n}\r\n<\/pre>\n<p>I&#8217;ll be uploading complete source code soon. Meanwhile, try building this chat bot and think about what else can be built using this technology. The same code can be used in hook.io to deploy the bot with some changes.<\/p>\n<p><a href=\"https:\/\/codingislove.com\/free-microservice-hosting-hook-io\/\" target=\"_blank\">Read how to deploy chat bot to hook.io<\/a><\/p>\n<p>You can start using wiki bot by clicking on Message Us button below!<br \/>\n<script>window.fbAsyncInit = function() {\nFB.init({\n      appId      : '1140610085990207',\n      xfbml      : true,\n      version    : 'v2.6'\n    });\n  };\n(function(d, s, id){\n     var js, fjs = d.getElementsByTagName(s)[0];\n     if (d.getElementById(id)) {return;}\n     js = d.createElement(s); js.id = id;\n     js.src = \"\/\/connect.facebook.net\/en_US\/sdk.js\";\n     fjs.parentNode.insertBefore(js, fjs);\n   }(document, 'script', 'facebook-jssdk'));\n<\/script><\/p>\n<div class=\"centerme\">\n<div class=\"fb-messengermessageus\" \n  messenger_app_id=\"1140610085990207\" \n  page_id=\"491310151067100\" \n  color=\"blue\" \n  size=\"xlarge\"><\/div>\n<\/div>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><\/p>\n<div style=\"text-align:center;\"><ins class=\"adsbygoogle\"\n     style=\"display:inline-block;width:300px;height:250px\"\n     data-ad-client=\"ca-pub-6724251756140624\"\n     data-ad-slot=\"4326164198\"><\/ins><\/div>\n<p><script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>Wrapping up<\/h3>\n<p>I&#8217;ve neither optimised this bot for best use nor handled all the errors. This was built just to get started with chat bots for facebook messenger. There&#8217;s always lot more that can be done, read official documentation and build better bots.<\/p>\n<p>We can use <a href=\"https:\/\/wit.ai\/\" target=\"_blank\" rel=\"nofollow\">wit.ai<\/a> which provides full API with artificial intelligence for interacting with users. It is also free. We can build full conversational bots using wit.ai<\/p>\n<p>A paid alternative to wit.ai is <a href=\"https:\/\/api.ai\/\" target=\"_blank\" rel=\"nofollow\">api.ai<\/a> which also has inbuilt integration for facebook messenger platform. Try it too, It has a free plan with limitations.<\/p>\n<p>Chat bots for facebook messenger can also be used for business but has few limitations, so start building bots for your business too.<\/p>\n<p><em>If you have and questions or feedback, comment below.<\/em><\/p>\n<script>(function() {\n\twindow.mc4wp = window.mc4wp || {\n\t\tlisteners: [],\n\t\tforms: {\n\t\t\ton: function(evt, cb) {\n\t\t\t\twindow.mc4wp.listeners.push(\n\t\t\t\t\t{\n\t\t\t\t\t\tevent   : evt,\n\t\t\t\t\t\tcallback: cb\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n})();\n<\/script><!-- Mailchimp for WordPress v4.10.7 - https:\/\/wordpress.org\/plugins\/mailchimp-for-wp\/ --><form id=\"mc4wp-form-1\" class=\"mc4wp-form mc4wp-form-177 mc4wp-form-theme mc4wp-form-theme-red\" method=\"post\" data-id=\"177\" data-name=\"Subscribe to Coding is Love\" ><div class=\"mc4wp-form-fields\"><p>\r\n  <strong><a style=\"cursor:pointer\" onclick=\"OneSignal.push(function() {OneSignal.registerForPushNotifications()});\">Get notified when there's a new post by clicking on<img decoding=\"async\" style=\"transform:scale(0.75,0.75)\" src=\"https:\/\/i.imgur.com\/lTEcCYt.png\" alt=\"notification-bell\"\/>in bottom left<\/a><\/strong>\r\n<\/p>\r\n\r\n<p>\r\n  <strong>Need some help? Post your questions on our <a href=\"https:\/\/forum.codingislove.com\" target=\"_blank\">forum<\/a><\/strong>\r\n<\/p>\r\n<!--<br>\r\n<script id=\"mNCC\" language=\"javascript\">\r\n   medianet_width = \"300\";\r\n   medianet_height = \"250\";\r\n   medianet_crid = \"892699656\";\r\n   medianet_versionId = \"111299\";\r\n   (function() {\r\n       var isSSL = 'https:' == document.location.protocol;\r\n       var mnSrc = (isSSL ? 'https:' : 'http:') + '\/\/contextual.media.net\/nmedianet.js?cid=8CUWS5M33' + (isSSL ? '&https=1' : '');\r\n       document.write('<scr' + 'ipt type=\"text\/javascript\" id=\"mNSC\" src=\"' + mnSrc + '\"><\/scr' + 'ipt>');\r\n   })();\r\n<\/script>\r\n<p>\r\n    Liked this post? Join our newsletter to get more stuff like this in your inbox.\r\n<\/p>\r\n<p>\r\n\t<label>Email address: <\/label>\r\n\t<input type=\"email\" name=\"EMAIL\" placeholder=\"Your email is safe with us!\" required \/>\r\n<\/p>\r\n<p>\r\n\t<input type=\"submit\" value=\"Sign up\" \/>\r\n<\/p>\r\n--><\/div><label style=\"display: none !important;\">Leave this field empty if you're human: <input type=\"text\" name=\"_mc4wp_honeypot\" value=\"\" tabindex=\"-1\" autocomplete=\"off\" \/><\/label><input type=\"hidden\" name=\"_mc4wp_timestamp\" value=\"1777143769\" \/><input type=\"hidden\" name=\"_mc4wp_form_id\" value=\"177\" \/><input type=\"hidden\" name=\"_mc4wp_form_element_id\" value=\"mc4wp-form-1\" \/><div class=\"mc4wp-response\"><\/div><\/form><!-- \/ Mailchimp for WordPress Plugin -->\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-client=\"ca-pub-6724251756140624\"\n     data-ad-slot=\"5104893391\"\n     data-ad-format=\"link\"><\/ins><\/p>\n<p><script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<div style=\"margin-top: 15px; margin-bottom: 15px;\" class=\"sharethis-inline-share-buttons\" ><\/div>","protected":false},"excerpt":{"rendered":"<p>Continued from Develop Facebook chat bot using Javascript &#8211; Part 1<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[24,25,8,23],"class_list":["post-688","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-bot","tag-chat-bot","tag-coding","tag-facebook-messenger"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love<\/title>\n<meta name=\"description\" content=\"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love\" \/>\n<meta property=\"og:description\" content=\"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Coding is Love\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/codingislove\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ranjithkumar10\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-08T11:40:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-01-17T15:35:13+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/i.imgur.com\/61B3dcG.gif\" \/>\n<meta name=\"author\" content=\"Ranjith kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codingislove\" \/>\n<meta name=\"twitter:site\" content=\"@codingislove\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ranjith kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\"},\"author\":{\"name\":\"Ranjith kumar\",\"@id\":\"https:\/\/codingislove.com\/#\/schema\/person\/ecb142505163b016d59bfbe662af587e\"},\"headline\":\"Develop Facebook chat bot using Javascript \u2013 Part 2\",\"datePublished\":\"2016-06-08T11:40:12+00:00\",\"dateModified\":\"2017-01-17T15:35:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\"},\"wordCount\":1612,\"commentCount\":27,\"publisher\":{\"@id\":\"https:\/\/codingislove.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/i.imgur.com\/61B3dcG.gif\",\"keywords\":[\"bot\",\"chat bot\",\"coding\",\"facebook messenger\"],\"articleSection\":[\"Coding Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\",\"url\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\",\"name\":\"Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love\",\"isPartOf\":{\"@id\":\"https:\/\/codingislove.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/i.imgur.com\/61B3dcG.gif\",\"datePublished\":\"2016-06-08T11:40:12+00:00\",\"dateModified\":\"2017-01-17T15:35:13+00:00\",\"description\":\"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.\",\"breadcrumb\":{\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage\",\"url\":\"http:\/\/i.imgur.com\/61B3dcG.gif\",\"contentUrl\":\"http:\/\/i.imgur.com\/61B3dcG.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Coding is Love\",\"item\":\"https:\/\/codingislove.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Coding Tutorials\",\"item\":\"https:\/\/codingislove.com\/category\/tutorials\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Develop Facebook chat bot using Javascript \u2013 Part 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codingislove.com\/#website\",\"url\":\"https:\/\/codingislove.com\/\",\"name\":\"Coding is Love\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/codingislove.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codingislove.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/codingislove.com\/#organization\",\"name\":\"Coding is Love\",\"url\":\"https:\/\/codingislove.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingislove.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/codingislove.com\/wp-content\/uploads\/2015\/12\/codinglovenew.png\",\"contentUrl\":\"https:\/\/codingislove.com\/wp-content\/uploads\/2015\/12\/codinglovenew.png\",\"width\":300,\"height\":225,\"caption\":\"Coding is Love\"},\"image\":{\"@id\":\"https:\/\/codingislove.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/codingislove\/\",\"https:\/\/x.com\/codingislove\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/codingislove.com\/#\/schema\/person\/ecb142505163b016d59bfbe662af587e\",\"name\":\"Ranjith kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingislove.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f5486247269539c638227e6213187139cc7460eeb16d789fa757485f1d2b87f0?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f5486247269539c638227e6213187139cc7460eeb16d789fa757485f1d2b87f0?s=96&d=wavatar&r=g\",\"caption\":\"Ranjith kumar\"},\"description\":\"A CA- by education, self taught coder by passion, loves to explore new technologies and believes in learn by doing.\",\"sameAs\":[\"https:\/\/www.facebook.com\/ranjithkumar10\",\"https:\/\/www.instagram.com\/livin_on_d_edge\/\",\"https:\/\/www.linkedin.com\/in\/ranjithkumar10\",\"https:\/\/www.youtube.com\/c\/codingislove01\"],\"url\":\"https:\/\/codingislove.com\/author\/ranjithkumar10\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love","description":"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love","og_description":"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.","og_url":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/","og_site_name":"Coding is Love","article_publisher":"https:\/\/facebook.com\/codingislove\/","article_author":"https:\/\/www.facebook.com\/ranjithkumar10","article_published_time":"2016-06-08T11:40:12+00:00","article_modified_time":"2017-01-17T15:35:13+00:00","og_image":[{"url":"http:\/\/i.imgur.com\/61B3dcG.gif","type":"","width":"","height":""}],"author":"Ranjith kumar","twitter_card":"summary_large_image","twitter_creator":"@codingislove","twitter_site":"@codingislove","twitter_misc":{"Written by":"Ranjith kumar","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#article","isPartOf":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/"},"author":{"name":"Ranjith kumar","@id":"https:\/\/codingislove.com\/#\/schema\/person\/ecb142505163b016d59bfbe662af587e"},"headline":"Develop Facebook chat bot using Javascript \u2013 Part 2","datePublished":"2016-06-08T11:40:12+00:00","dateModified":"2017-01-17T15:35:13+00:00","mainEntityOfPage":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/"},"wordCount":1612,"commentCount":27,"publisher":{"@id":"https:\/\/codingislove.com\/#organization"},"image":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage"},"thumbnailUrl":"http:\/\/i.imgur.com\/61B3dcG.gif","keywords":["bot","chat bot","coding","facebook messenger"],"articleSection":["Coding Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/","url":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/","name":"Develop Facebook chat bot using Javascript \u2013 Part 2 - Coding is Love","isPartOf":{"@id":"https:\/\/codingislove.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage"},"image":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage"},"thumbnailUrl":"http:\/\/i.imgur.com\/61B3dcG.gif","datePublished":"2016-06-08T11:40:12+00:00","dateModified":"2017-01-17T15:35:13+00:00","description":"A complete tutorial on building chat bots for facebook messenger. Learn how to build Wikipedia bot using NodeJS.","breadcrumb":{"@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#primaryimage","url":"http:\/\/i.imgur.com\/61B3dcG.gif","contentUrl":"http:\/\/i.imgur.com\/61B3dcG.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/codingislove.com\/build-facebook-chat-bot-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Coding is Love","item":"https:\/\/codingislove.com\/"},{"@type":"ListItem","position":2,"name":"Coding Tutorials","item":"https:\/\/codingislove.com\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Develop Facebook chat bot using Javascript \u2013 Part 2"}]},{"@type":"WebSite","@id":"https:\/\/codingislove.com\/#website","url":"https:\/\/codingislove.com\/","name":"Coding is Love","description":"","publisher":{"@id":"https:\/\/codingislove.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codingislove.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codingislove.com\/#organization","name":"Coding is Love","url":"https:\/\/codingislove.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingislove.com\/#\/schema\/logo\/image\/","url":"https:\/\/codingislove.com\/wp-content\/uploads\/2015\/12\/codinglovenew.png","contentUrl":"https:\/\/codingislove.com\/wp-content\/uploads\/2015\/12\/codinglovenew.png","width":300,"height":225,"caption":"Coding is Love"},"image":{"@id":"https:\/\/codingislove.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/codingislove\/","https:\/\/x.com\/codingislove"]},{"@type":"Person","@id":"https:\/\/codingislove.com\/#\/schema\/person\/ecb142505163b016d59bfbe662af587e","name":"Ranjith kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingislove.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f5486247269539c638227e6213187139cc7460eeb16d789fa757485f1d2b87f0?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f5486247269539c638227e6213187139cc7460eeb16d789fa757485f1d2b87f0?s=96&d=wavatar&r=g","caption":"Ranjith kumar"},"description":"A CA- by education, self taught coder by passion, loves to explore new technologies and believes in learn by doing.","sameAs":["https:\/\/www.facebook.com\/ranjithkumar10","https:\/\/www.instagram.com\/livin_on_d_edge\/","https:\/\/www.linkedin.com\/in\/ranjithkumar10","https:\/\/www.youtube.com\/c\/codingislove01"],"url":"https:\/\/codingislove.com\/author\/ranjithkumar10\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/posts\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":0,"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/posts\/688\/revisions"}],"wp:attachment":[{"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/media?parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/categories?post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingislove.com\/wp-json\/wp\/v2\/tags?post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}