<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Samuel</title>
    <description>The latest articles on DEV Community by Samuel (@rsamaium).</description>
    <link>https://dev.to/rsamaium</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F214767%2Fd5525b33-a9e0-4e4d-8079-667872201564.jpg</url>
      <title>DEV Community: Samuel</title>
      <link>https://dev.to/rsamaium</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rsamaium"/>
    <language>en</language>
    <item>
      <title>My 7 steps to build a chatbot efficiently</title>
      <dc:creator>Samuel</dc:creator>
      <pubDate>Thu, 05 Aug 2021 10:05:22 +0000</pubDate>
      <link>https://dev.to/rsamaium/my-7-steps-to-build-a-chatbot-efficiently-1fpb</link>
      <guid>https://dev.to/rsamaium/my-7-steps-to-build-a-chatbot-efficiently-1fpb</guid>
      <description>&lt;h1&gt;
  
  
  Step 1. Identify the problem
&lt;/h1&gt;

&lt;p&gt;What is the pain point you want to solve? For instance, you want to build a chatbot to help your team organize the sales meetings.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2. Define the scope
&lt;/h1&gt;

&lt;p&gt;What is the main functionality? Your chatbot should be able to schedule meetings. The bot will connect the sales representatives and the manager. When the meeting time is scheduled, the bot will send a reminder to all involved parties.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3. Identify the endpoints
&lt;/h1&gt;

&lt;p&gt;What is the content you want to share? What is the format? You need to think about the information that will be shared. For instance, the bot will have to send the meeting invite via email, to create a calendar event, and to send reminders.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 4. Design the conversation flow
&lt;/h1&gt;

&lt;p&gt;What are the possible paths of the conversation? For example, to schedule a meeting, the manager can ask to invite another sales representative.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5. Code the chatbot
&lt;/h1&gt;

&lt;p&gt;Write the conversational script and use tools to code chatbot:&lt;/p&gt;

&lt;p&gt;Some examples of tools:&lt;/p&gt;

&lt;p&gt;a) IBM Watson Bot Builder&lt;/p&gt;

&lt;p&gt;b) Wit.ai&lt;/p&gt;

&lt;p&gt;c) Dialogflow&lt;/p&gt;

&lt;p&gt;d) Botfuel&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 6. Test the chatbot
&lt;/h1&gt;

&lt;p&gt;Test and refine the chatbot.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 7. Deploy the chatbot
&lt;/h1&gt;

</description>
      <category>chatbot</category>
      <category>flow</category>
    </item>
    <item>
      <title>DialogFlow Chatbot with NewBot Framework</title>
      <dc:creator>Samuel</dc:creator>
      <pubDate>Tue, 20 Aug 2019 14:52:32 +0000</pubDate>
      <link>https://dev.to/rsamaium/dialogflow-chatbot-with-newbot-framework-39g4</link>
      <guid>https://dev.to/rsamaium/dialogflow-chatbot-with-newbot-framework-39g4</guid>
      <description>&lt;p&gt;The goal: to create a chatbot quickly in Javascript with the understanding of the natural language (DialogFlow).&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Have a Google Cloud and DialogFlow account&lt;/li&gt;
&lt;li&gt;Have NodeJS and NPM installed on your machine&lt;/li&gt;
&lt;li&gt;Knowledge of Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Why NewBot Framework?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Universal, a single code to work everywhere&lt;/li&gt;
&lt;li&gt;Creation of conversational website&lt;/li&gt;
&lt;li&gt;Modular and structured&lt;/li&gt;
&lt;li&gt;Using the NLP (Natural Language Processing)&lt;/li&gt;
&lt;li&gt;Conversational script syntax to write user-chatbot conversations easily and quickly&lt;/li&gt;
&lt;li&gt;Internationalization&lt;/li&gt;
&lt;li&gt;Unit tests&lt;/li&gt;
&lt;li&gt;Emulator with NewBot CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Compatibility
&lt;/h1&gt;

&lt;p&gt;All platforms, i.e.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Facebook Messenger&lt;/li&gt;
&lt;li&gt;Google Assistant&lt;/li&gt;
&lt;li&gt;Amazon Alexa&lt;/li&gt;
&lt;li&gt;Slack&lt;/li&gt;
&lt;li&gt;Telegram&lt;/li&gt;
&lt;li&gt;Viber&lt;/li&gt;
&lt;li&gt;Skype&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Above all
&lt;/h1&gt;

&lt;p&gt;Install NewBot CLI to take advantage of command lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g newbot-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newbot new &amp;lt;your directory name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to the generated folder&lt;/p&gt;

&lt;p&gt;You can test the chatbot with the command &lt;code&gt;newbot serve&lt;/code&gt;. See below&lt;/p&gt;

&lt;h1&gt;
  
  
  Retrieve the credentials of DialogFlow
&lt;/h1&gt;

&lt;p&gt;Have a Google Cloud and DialogFlow account&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1_dDZIzL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1_dDZIzL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow1.jpeg" alt="DialogFlow Account"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the service in Google Cloud&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BrJt7N0W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BrJt7N0W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow2.jpeg" alt="DialogFlow Account 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create new Key&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ePD13BN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ePD13BN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow3.jpeg" alt="Create Key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download the private key and add it to the root of the project&lt;/p&gt;

&lt;h1&gt;
  
  
  Add DialogFlow in our project
&lt;/h1&gt;

&lt;p&gt;Install the &lt;code&gt;newbot-dialogflow&lt;/code&gt; module :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install newbot-dialogflow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;main.js&lt;/code&gt; file, add the DialogFlow skill :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;dialogflowSkill&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-dialogflow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./main.converse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;dialogflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dialogflowSkill&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-fttkoh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-fttkoh-69d17227a8b7.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;projectId&lt;/code&gt; : The project ID (in Chatbot Settings)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;credentials&lt;/code&gt;: Path to credentials file&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Input unknown
&lt;/h2&gt;

&lt;p&gt;Add this code to the &lt;code&gt;main.converse&lt;/code&gt; file :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input.unknown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;An &lt;code&gt;input.unknow&lt;/code&gt; intention is already present in DialogFlow, it is triggered when no other intention is triggered&lt;/li&gt;
&lt;li&gt;We then display the response received from DialogFlow&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;:intent.date.value&lt;/code&gt; is a magic variable that retrieves the date entered by the user&lt;/p&gt;

&lt;p&gt;The language used is specific to NewBot. It is called ConverseScript and allows you to create conversational scripts with a syntax close to Javascript&lt;br&gt;
More : &lt;a href="https://newbot.io/docs/syntax/variables.html"&gt;https://newbot.io/docs/syntax/variables.html&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Add our own intention: we buy a pizza!
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create a new intent in DialogFlow&lt;/li&gt;
&lt;li&gt;Put a name ("Buy Pizza" by example)&lt;/li&gt;
&lt;li&gt;Add trainings phrases&lt;/li&gt;
&lt;li&gt;Add action name. Here, this name is &lt;code&gt;input.buy&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can add parameters. Here, we recover the date in the sentence&lt;/li&gt;
&lt;li&gt;Add response(s)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---V-wO3YN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---V-wO3YN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow4.jpeg" alt="Create Intent"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4-uk0eBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4-uk0eBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://newbot.io/images/shared/dialogflow5.jpeg" alt="Add responses"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;main.converse&lt;/code&gt; content contains a new intention!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input.buy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;buy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;callApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input.unknown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We retrieve the date entity and call a function that can trigger an API&lt;/p&gt;

&lt;p&gt;&lt;code&gt;callApi()&lt;/code&gt; is a function created by us, present in Javascript :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;main.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;dialogflowSkill&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-dialogflow&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./main.converse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;dialogflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dialogflowSkill&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-fttkoh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;newbot-fttkoh-69d17227a8b7.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;callApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Call your own API. date is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Test in Emulator
&lt;/h1&gt;

&lt;p&gt;Type the following command at the root of your project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newbot serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to &lt;code&gt;localhost:3000&lt;/code&gt; and test the project in the emulator&lt;/p&gt;

&lt;h1&gt;
  
  
  Documentation
&lt;/h1&gt;

&lt;p&gt;Here : &lt;a href="https://newbot.io/en/docs"&gt;https://newbot.io/en/docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chatbot</category>
      <category>dialogflow</category>
      <category>javascript</category>
      <category>nlp</category>
    </item>
    <item>
      <title>Create a universal chatbot with JavaScript and NewBot Framework</title>
      <dc:creator>Samuel</dc:creator>
      <pubDate>Mon, 19 Aug 2019 13:20:27 +0000</pubDate>
      <link>https://dev.to/rsamaium/create-a-universal-chatbot-with-javascript-and-newbot-framework-324</link>
      <guid>https://dev.to/rsamaium/create-a-universal-chatbot-with-javascript-and-newbot-framework-324</guid>
      <description>&lt;p&gt;We will create a modular and fast chatbot. We take advantage of NLP without an external platform (like DialogFlow)&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Have NodeJS and NPM installed on your machine&lt;/li&gt;
&lt;li&gt;Knowledge of Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Why NewBot Framework?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Universal, a single code to work everywhere&lt;/li&gt;
&lt;li&gt;Creation of conversational website&lt;/li&gt;
&lt;li&gt;Modular and structured&lt;/li&gt;
&lt;li&gt;Using the NLP (Natural Language Processing)&lt;/li&gt;
&lt;li&gt;Conversational script syntax to write user-chatbot conversations easily and quickly&lt;/li&gt;
&lt;li&gt;Internationalization&lt;/li&gt;
&lt;li&gt;Unit tests&lt;/li&gt;
&lt;li&gt;Emulator with NewBot CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Compatibility
&lt;/h1&gt;

&lt;p&gt;All platforms, i.e.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Facebook Messenger&lt;/li&gt;
&lt;li&gt;Google Assistant&lt;/li&gt;
&lt;li&gt;Amazon Alexa&lt;/li&gt;
&lt;li&gt;Slack&lt;/li&gt;
&lt;li&gt;Telegram&lt;/li&gt;
&lt;li&gt;Viber&lt;/li&gt;
&lt;li&gt;Skype&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and directly in your browser (offline)&lt;/p&gt;

&lt;h1&gt;
  
  
  Above all
&lt;/h1&gt;

&lt;p&gt;Install NewBot CLI to take advantage of command lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g newbot-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newbot new &amp;lt;your directory name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to the generated folder&lt;/p&gt;

&lt;p&gt;You can test the chatbot with the command &lt;code&gt;newbot serve&lt;/code&gt;. See below&lt;/p&gt;

&lt;h1&gt;
  
  
  Create main skill
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;main.converse&lt;/code&gt; is the conversational script of the main skill. It’s just the departure conversation&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The language used is specific to NewBot. It is called ConverseScript and allows you to create conversational scripts with a syntax close to Javascript&lt;br&gt;
More : &lt;a href="https://newbot.io/docs/syntax/variables.html"&gt;https://newbot.io/docs/syntax/variables.html&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;am&lt;/span&gt; &lt;span class="nx"&gt;PizzaBot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple, isn't it? The chatbot gives its name from the first interaction with the user&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;start()&lt;/code&gt; is a function representing a dialog&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@Event('start')&lt;/code&gt; is a decorator indicating how the function should be triggered. Here, the “start” event indicates that the function is triggered as soon as the first interaction with the chatbot occurs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Entering a text
&lt;/h2&gt;

&lt;p&gt;Let's complete the &lt;code&gt;main.converse&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;am&lt;/span&gt; &lt;span class="nx"&gt;PizzaBot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
    &lt;span class="nx"&gt;Prompt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Welcome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;$name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$name&lt;/code&gt; is a global variable specific to the user&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Prompt()&lt;/code&gt; is a native function waiting for the user to enter&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:text&lt;/code&gt; a magic variable. It was created by the system. It contains the user entry. We store the value in the global variable &lt;code&gt;$name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Javascript file
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;main.js&lt;/code&gt; file contains an object representing the skill&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./main.converse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Create a skill to place an order
&lt;/h1&gt;

&lt;p&gt;First, create a new skill&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newbot generate skill order
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An &lt;code&gt;order&lt;/code&gt; folder has been created in the &lt;code&gt;bot/skills&lt;/code&gt; folder&lt;/p&gt;

&lt;p&gt;&lt;code&gt;order.converse&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;order&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;order a pizza&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get pizza&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;buy pizza&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="nx"&gt;callApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;have&lt;/span&gt; &lt;span class="nx"&gt;noted&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use an &lt;code&gt;@Intent&lt;/code&gt; decorator to use the NLP&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Intent()&lt;/code&gt; is a decorator who defines an intention. First parameter: the name of the intention. Second parameter: the training phrase array&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:intent.date.value&lt;/code&gt; is a magic variable that retrieves the date entered by the user&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;callApi()&lt;/code&gt; is a function created by us, present in Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  and JS skill
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./order.converse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;callApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`call yout custom api, date is &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;functions&lt;/code&gt; property allows you to declare functions that can be used in the conversational script&lt;/p&gt;

&lt;h2&gt;
  
  
  Link the created skill to the chatbot
&lt;/h2&gt;

&lt;p&gt;Now that the skill &lt;code&gt;order&lt;/code&gt; has been created, add it to the property &lt;code&gt;skills&lt;/code&gt; in the &lt;code&gt;main.js&lt;/code&gt; file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;order.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./main.converse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;orderSkill&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./skills/order/order&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;orderSkill&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Full code
&lt;/h1&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/pizzabot-with-newbot-framework-tssc5"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Test in Emulator
&lt;/h1&gt;

&lt;p&gt;Type the following command at the root of your project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newbot serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to &lt;code&gt;localhost:3000&lt;/code&gt; and test the project in the emulator&lt;/p&gt;

&lt;h1&gt;
  
  
  Go further in understanding
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Deploy in browser : &lt;a href="https://newbot.io/en/docs/essential/browser.html"&gt;https://newbot.io/en/docs/essential/browser.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Develop ExpressJS server and execute chatbot : &lt;a href="https://newbot.io/en/docs/engine/express.html"&gt;https://newbot.io/en/docs/engine/express.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>chatbot</category>
      <category>nlp</category>
      <category>conversational</category>
    </item>
  </channel>
</rss>
