{"id":17992,"date":"2017-05-04T17:09:42","date_gmt":"2017-05-04T17:09:42","guid":{"rendered":"http:\/\/developer.kore.ai\/v7-3\/?post_type=docs&#038;p=11397"},"modified":"2021-03-26T10:22:07","modified_gmt":"2021-03-26T10:22:07","slug":"kore-ai-botkit-sdk-tutorial","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v7-3\/docs\/bots\/sdks\/kore-ai-botkit-sdk-tutorial\/","title":{"rendered":"BotKit SDK Tutorial &#8211; Flight Search Sample Bot"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>This tutorial is an end-to-end walkthrough for setting up and running an instance of the Kore.ai BotKit SDK which is a collection of libraries that you can use for more control of the messages and webhook events for Kore.ai bots for your web service. For this tutorial, you will use the sample bot called<em> Flight Search Sample<\/em>\u00a0that you can install as a new bot, generate authentication tokens, and then test the bot using <em>ngrok<\/em> as a test callback server.<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Prerequisites\">Prerequisites<\/span><\/h1>\n<p>To complete this tutorial, you will have to setup and configure the following prerequisites:<\/p>\n<ul>\n<li><strong>Install and run ngrok<\/strong> as your test callback server.\u00a0The test callback server application,\u00a0<em>ngrok<\/em>, is used to simulate your callback server application.<\/li>\n<li><strong>Install\u00a0<em>node.js<\/em> on your computer<\/strong> &#8211; The BotKit SDK requires <em>node.js<\/em> to communicate between your server and the Kore.ai Bots Platform.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Installing_and_running_ngrok\">Installing and running <em>ngrok<\/em><\/span><\/h2>\n<p>To download the test callback server application, click\u00a0<a href=\"https:\/\/ngrok.com\/download\">https:\/\/ngrok.com\/download<\/a>, and then\u00a0download and install the\u00a0<em>ngrok<\/em>\u00a0file for your operating system.<br \/>\nIn a <strong>Terminal<\/strong> Window, start <em>ngrok<\/em> to monitor port <span style=\"color: #0000ff\">8003<\/span> using the following command:<br \/>\n<code>ngrok http 8003<\/code><br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/15\/DIYBotKitSDKNgrok.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11701 alignnone\" src=\"\/wp-content\/uploads\/sites\/15\/DIYBotKitSDKNgrok.png\" alt=\"\" width=\"1184\" height=\"460\" \/><\/a><br \/>\nCopy the https <strong>Forwarding URL<\/strong> as shown in the previous illustration, for example,\u00a0<span style=\"color: #0000ff\">https:\/\/1b47f1d2.ngrok.io<\/span>. Leave the terminal window open and <em>ngrok<\/em> running.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Installing_nodejs\">Installing node.js<\/span><\/h2>\n<p>The BotKit SDK requires <em>node.js<\/em> to run on the same server where the SDK is installed. Go to\u00a0<a href=\"https:\/\/nodejs.org\/en\/download\/\">https:\/\/nodejs.org\/en\/download\/<\/a>, and then select your OS as a <span style=\"color: #0000ff\">.pkg<\/span> file type for Mac, and <span style=\"color: #0000ff\">.msi<\/span>\u00a0file type for Windows.<br \/>\nIn a <strong>Terminal<\/strong> window,\u00a0run the <code>node -v<\/code> command to verify installation\u00a0and version, for example, <code>v6.10.2<\/code>as shown in the following illustration.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/15\/DIYBotKITSDKTutorialNodeJS.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11706\" src=\"\/wp-content\/uploads\/sites\/15\/DIYBotKITSDKTutorialNodeJS.png\" alt=\"\" width=\"436\" height=\"116\" \/><\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Installing_and_Configuring_Your_Bot\">Installing and Configuring Your Bot<\/span><\/h1>\n<p>With the prerequisites installed and running, you are ready to install the\u00a0<em>Flight Search Sample<\/em>\u00a0bot. In this section, you will:<\/p>\n<ul>\n<li>Install the\u00a0<em>Flight Search Sample<\/em>\u00a0Bot<\/li>\n<li>Create an App Registration<\/li>\n<li>Generate Security Credentials<\/li>\n<li>Install and Configure the BotKit SDK &#8211; config.json and FindAFlight.js files<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Installing_the_Flight_Search_Sample_Bot\"><strong>Installing the\u00a0Flight Search Sample Bot<\/strong><\/span><\/h2>\n<p>Kore.ai provides ready to use sample bots that you can install into your instance of Bot Builder. For this tutorial, you will need to install the\u00a0<em>Flight Search Sample<\/em>\u00a0bot.<br \/>\n<strong>To install the\u00a0Flight Search Sample bot<\/strong><\/p>\n<ol>\n<li>Log on to Bot\u00a0Builder, and then click\u00a0<strong>New Bot &gt; Install Sample Bot<\/strong>.<\/li>\n<li>Point to\u00a0<strong>Flight Search Sample<\/strong>, and then click\u00a0<strong>Install<\/strong>. The <strong>Instructions<\/strong> tab on the <strong>Flight Search Sample_XXXX_X<\/strong> opens.<\/li>\n<li>Review the instructions, click the <strong>Configuration<\/strong> tab, and then rename your sample bot to <span style=\"color: #0000ff\">Flight Search Sample Tutorial<\/span>.<\/li>\n<li>The\u00a0<em>Flight Search Sample<\/em><em>_NAME_Instance# installed successfully<\/em>\u00a0message appears.<\/li>\n<\/ol>\n<p>The\u00a0<em>Flight Search Sample<\/em>\u00a0bot is only available in Bot Builder\u00a0and must be added as a new bot. For more information, see <a href=\"\/v7-3\/docs\/bots\/bot-builder\/getting-started-bots\/installing-sample-bots\/flight-search-sample-bot\/\">Flight Search Sample Bot<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Registering_Your_App_and_Generating_Client_Credentials\">Registering Your App and Generating Client Credentials<\/span><\/h2>\n<p>To register your BotKit SDK with the Kore.ai Bots platform, you will need to create an app registration, and then generate security credentials used to securely communicate between the SDK installed on your server platform and the Kore.ai Bots Platform.<br \/>\n<strong>Creating an App Registration<\/strong><\/p>\n<ol>\n<li>Hover over the side-navigation panel of the bot and click\u00a0<b>API Extensions<\/b>.<\/li>\n<li>On the API Extensions page, click the <b>BotKit SDK<\/b>\u00a0tab.<\/li>\n<li>Next to the\u00a0<b>App name\u00a0<\/b>drop-down list, click <strong>Add<\/strong>.<\/li>\n<li>Enter a name for the app and then click <strong>Next<\/strong>.<\/li>\n<li>The Client ID and Client Secret details appear. Click\u00a0<strong>Done<\/strong>.<\/li>\n<li>In the\u00a0<strong>Callback URL<\/strong>\u00a0field, enter the URL for your application that you copied from the <strong>Forwarding URL<\/strong> from the <em>ngrok<\/em> application that you installed and ran as part of the prerequisites, for example,\u00a0\u00a0<span style=\"color: #0000ff\">https:\/\/1b47f1d2.ngrok.io<\/span>.\n<p class=\"note\"><strong>Note:<\/strong> Each running instance of <em>ngrok<\/em> will generate a session unique URL. You will need to update the <strong>Callback URL<\/strong> field if you stop and restart <em>ngrok<\/em>.<\/p>\n<\/li>\n<li>In the\u00a0<strong>Events<\/strong>\u00a0section, select\u00a0<strong>OnHookNode<\/strong>\u00a0\u2013 An event is triggered when a Webhook node is encountered in the dialog task flow.<\/li>\n<li>Click <strong>Save<\/strong>. The <em>Successfully subscribed<\/em> message is displayed.<\/li>\n<\/ol>\n<p>To configure the BotKit SDK settings, you will need to:<\/p>\n<ul>\n<li>Copy the <strong>Client ID<\/strong>, for example,\u00a0<span style=\"color: #0000ff\">cs-6e5eb411-e592-50d9-9ba2-ccc748d4f719<\/span>.<\/li>\n<li>View, and then copy the <strong>Client Secret<\/strong>, for example,\u00a0<span style=\"color: #0000ff\">dTTmuTOgs8SOCwF\/tFizouE0EPy28fXojOJWedOEF6s=<\/span>.<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"Publishing_the_Bot\">Publishing the Bot<\/span><\/h1>\n<p>A developer can use any installed bot immediately for testing as bots are available to the owner on save. If you only want to run and test this bot for this tutorial, you can skip to the next section, <em>Installing and Configuring the BotKit SDK<\/em>.<br \/>\nTo enable the bot for other users, you must publish the bot so the Enterprise Admin for other users can approve and deploy the bot for users in their enterprise. For more information, see <a href=\"\/v7-3\/docs\/bots\/bot-builder-tool\/publish\/publishing-bot\/#Publishing_Tasks\">Publishing Tasks<\/a>.<br \/>\nAfter you publish a bot in Bot Builder, an Enterprise Admin for your bot must complete one of the following bot deployments in the Bots Admin Console depending if\u00a0your bot <strong>Target Audience<\/strong> is set to <strong>Enterprise Users<\/strong> (managed users) or <strong>General Public<\/strong> (unmanaged users):<\/p>\n<ul>\n<li><strong>For Enterprise Users<\/strong>\n<ol>\n<li>In the Bots Admin Console, in the <strong>Bots Management<\/strong> module, on the <strong>Enterprise\u00a0Bots<\/strong> page,\u00a0click the <strong>Ellipses<\/strong> icon for the\u00a0<em>Agent Transfer<\/em>\u00a0bot that you want to deploy,\u00a0and then click <strong>Manage bot tasks<\/strong>. The <strong>Manage Bot Tasks<\/strong> dialog is displayed.<\/li>\n<li>Expand the Bot Tasks field to view the available and deployed tasks.<\/li>\n<li>Select all tasks of the bot and then click <strong>Confirm<\/strong>.<\/li>\n<li>In the <strong>Manage bots tasks<\/strong> dialog, click <strong>Confirm<\/strong>. The <em>Bot status changed successfully<\/em> message is displayed.<\/li>\n<li>On the <strong>Enterprise\u00a0Bots<\/strong> page,\u00a0click the <strong>Ellipses<\/strong> icon for the\u00a0<em>Agent Transfer<\/em>\u00a0bot\u00a0that you want to assign enterprise users to,\u00a0and then click <strong>Bot &amp; task assignments<\/strong>. The <strong>Bot &amp; task assignments<\/strong>\u00a0dialog is displayed.<\/li>\n<li>Assign the bot to the selected users in the enterprise.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p><strong>\u00a0&#8211; or &#8211; <\/strong><\/p>\n<ul>\n<li><strong>For General Public Users<\/strong>\n<ol>\n<li>In the Bots Admin Console, in the <strong>Bots Management<\/strong> module, on the <strong>Consumer\u00a0Bots<\/strong> page,\u00a0click the <strong>Ellipses<\/strong> icon for the <em>Agent Transfer<\/em>\u00a0bot\u00a0that you want to deploy,\u00a0and then click <strong>Manage bot tasks<\/strong>. The <strong>Manage Bot Tasks<\/strong> dialog is displayed.<\/li>\n<li>Expand the Bot Tasks field to view the available and deployed tasks.<\/li>\n<li>Select all tasks of the bot and then click <strong>Confirm<\/strong>.\u00a0The <em>Bot status changed successfully<\/em> message is displayed.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Installing_and_Configuring_the_BotKit_SDK\">Installing and Configuring the BotKit SDK<\/span><\/h2>\n<p>You will need to download and then uncompress the Kore.ai BotKit\u00a0SDK from <a href=\"https:\/\/github.com\/Koredotcom\/BotKit\">https:\/\/github.com\/Koredotcom\/BotKit<\/a>. Be sure to download the latest version that contains the <span style=\"color: #0000ff\">LiveChat.js<\/span> files.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"configjson\">config.json<\/span><\/h3>\n<p>In your BotKit SDK folder, you will need to edit the <span style=\"color: #0000ff\">config.json<\/span> file that contains the connection information to your callback server. For this tutorial, you are using <em>ngrok<\/em>, along with the security credentials generated when you created the app registration for the\u00a0<em>Flight Search Sample<\/em>\u00a0bot, and adding a new line to <span style=\"color: #0000ff\">config.json<\/span> file that contains the license key for your <em>LiveChat<\/em> agent application.<br \/>\nModify the default <span style=\"color: #0000ff\">config.json<\/span> file for the following parameters as follows:<\/p>\n<ul>\n<li><code>url<\/code> &#8211; Add this parameter with the <strong>Forwarding URL<\/strong>\u00a0field from <em>ngrok<\/em><\/li>\n<li><code>apikey<\/code> &#8211; Update parameter using <strong>Client Secret<\/strong><\/li>\n<li><code>appId<\/code> &#8211; Update parameter using <strong>Client ID<\/strong><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">{\r\n    \"server\": {\r\n        \"port\": 8003\r\n    },\r\n    \"app\": {\r\n        \"apiPrefix\" : \"\",\r\n        \"url\": \"&lt; ngrok Forwarding URL &gt;\"\r\n    },\r\n    \"credentials\": {\r\n        \"apikey\": \"&lt; Client Secret from Bot Builder &gt;\",\r\n        \"appId\": \"&lt; Client ID from Bot Builder &gt;\"\r\n    },\r\n    \"redis\": {\r\n        \"options\": {\r\n            \"host\": \"localhost\",\r\n            \"port\": 6379\r\n        },\r\n        \"available\": false\r\n    },\r\n    \"examples\" : {\r\n        \"mockServicesHost\"  : \"http:\/\/localhost:8004\"\r\n    }\r\n}<\/pre>\n<p>The following code is an example of a fully defined sample <span style=\"color: #0000ff\">config.json<\/span> file:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"server\": {\r\n        \"port\": 8003\r\n    },\r\n    \"app\": {\r\n        \"apiPrefix\" : \"\",\r\n        \"url\": \"https:\/\/1b47f1d2.ngrok.io\"\r\n    },\r\n    \"credentials\": {\r\n        \"apikey\": \"dTTmuTOgs8SOCwXXXXXXXXE0EPy28fXojOJWedOEF6s=\",\r\n        \"appId\": \"cs-6e5eb411-XXXX-XXXX-9ba2-ccc748d4f719\"\r\n    },\r\n    \"redis\": {\r\n        \"options\": {\r\n            \"host\": \"localhost\",\r\n            \"port\": 6379\r\n        },\r\n        \"available\": false\r\n    },\r\n    \"examples\" : {\r\n        \"mockServicesHost\"  : \"http:\/\/localhost:8004\"\r\n    }\r\n}<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"FindAFlightjs\">FindAFlight.js<\/span><\/h3>\n<p>The <a href=\"https:\/\/github.com\/Koredotcom\/BotKit\/blob\/master\/FindAFlight.js\"><span style=\"color: #0000ff\">FindAFlight.js<\/span><\/a> file in the BotKit SDK contains the JavaScript that handles the webhook call for flight information. For this tutorial, you will configure the webhook settings\u00a0with the following information:<br \/>\nIn Bot Builder, select the <em>Flight Search Sample<\/em> bot, and then on the <strong>Settings -&gt; Config Settings<\/strong> section, select the <strong>General Settings<\/strong>\u00a0section. The <strong>General Settings\u00a0<\/strong>page is displayed. Copy the:<\/p>\n<ul>\n<li><strong>Bot Name<\/strong> &#8211; The name of the bot on the Bots Platform, for example,\u00a0<em>Flight Search Sample Tutorial<\/em>.<\/li>\n<li><strong>Bot ID<\/strong> &#8211; The Bots Platform system unique ID for the Bot, for example,\u00a0<em>st-26cfae3a-XXXX-XXXX-991a-376b7fe579d5<\/em>.<\/li>\n<\/ul>\n<p>In the <a href=\"https:\/\/github.com\/Koredotcom\/BotKit\/blob\/master\/FindAFlight.js\"><span style=\"color: #0000ff\">FindAFlight.js<\/span><\/a> file, update and save the following case-sensitive variables with the settings from your bot instance:<br \/>\n<code>var botId = \"&lt; <strong><em>Bot ID<\/em><\/strong> &gt;\";<br \/>\nvar botName = \"&lt; <em><strong>Bot Name<\/strong>\u00a0&gt;<\/em>\";<\/code><br \/>\nFor example:<br \/>\n<code>var botId = \"<em>st-26cfae3a-XXXX-XXXX-991a-376b7fe579d5<\/em>\";<br \/>\nvar botName = \"<em>Flight Search Sample Tutorial<\/em>\";<\/code><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Starting_the_BotKit_SDK_Application\">Starting the BotKit SDK Application<\/span><\/h1>\n<p>To start using the\u00a0<em>Flight Search Sample<\/em> bot using the BotKit SDK, <em>node.js<\/em> must be installed and <em>ngrok<\/em> running listening on port <span style=\"color: #0000ff\">8003<\/span>.<br \/>\n<strong>To start BotKit SDK<\/strong><br \/>\nIn a <strong>Terminal<\/strong> window, navigate to your BotKit SDK folder, and then enter the following command:<br \/>\n<code>     node app.js<\/code><br \/>\nWhen <em>node.js<\/em> is running, you should get the following response:<br \/>\n<code>app listening at http:\/\/:::8003<\/code><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Testing_the_BotKit_SDK_Bot\">Testing the BotKit SDK Bot<\/span><\/h1>\n<p>To test your bot, you need the following:<\/p>\n<ul>\n<li><em>ngrok<\/em> running &#8211; Command =\u00a0<code>ngrok http 8003<\/code><\/li>\n<li><em>node.js<\/em> running &#8211; Command =\u00a0<code>node app.js<\/code><\/li>\n<li>Bot Builder &#8211; Start <em>Talk to the Bot<\/em> by clicking the following icon on the bottom right corner of any Bot Builder page:<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/15\/talk-to-bot-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15259\" src=\"\/wp-content\/uploads\/sites\/15\/talk-to-bot-3.png\" alt=\"\" width=\"78\" height=\"95\" \/><\/a><\/li>\n<\/ul>\n<p>After the Flight Search Sample dialog is started, messages are exchanged between the third-party webhook as a web service\u00a0and the BotKit SDK.<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Next_Steps\"><em>Next Steps<\/em><\/span><\/h1>\n<p>To use the Kore.ai bot in your application, you would need to configure the BotKit SDK and register your application with <strong>CallBack URL<\/strong> to point to your company application server instead of <em>ngrok<\/em>. And of course, to share the bot with other users, the Enterprise Admin for your company would need to approve the bot, and deploy the bot to those users after you publish the bot.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"This tutorial is an end-to-end walkthrough for setting up and running an instance of the Kore.ai BotKit SDK which is a collection of libraries that you can use for more control of the messages and webhook events for Kore.ai bots for your web service. For this tutorial, you will use the sample bot called Flight...","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-17992","post","type-post","status-publish","format-standard","hentry","category-sdks"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts\/17992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/comments?post=17992"}],"version-history":[{"count":4,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts\/17992\/revisions"}],"predecessor-version":[{"id":23619,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/posts\/17992\/revisions\/23619"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/media?parent=17992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/categories?post=17992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-3\/wp-json\/wp\/v2\/tags?post=17992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}