Documentation

Do you use documentation to use NewBot Framework

Create a km / miles conversion system

Introduction

We wish to have this type of conversation:

Utilisateur : Combien fait 15 kilomètres en miles ?
Bot : ça fait 9.320565 miles

The goal: to create this skill in 5 minutes. !

Prerequisites

  1. You must have a NewBot Cloud account
  2. You have already installed NewBot Framework

Generate a project

At first, we will create a chatbot:

newbot new superbot

or clone the directory on Github: git clone git@github.com:newbotjs/chatbot-conversion-example.git

Conversational script

The main.converse file contains this code:

@Intent('conversion', [
    'Combien font 10 km en miles ?',
    'Convertir 20 kilomètres en miles',
])
toMiles() {
    km = :intent.distance.value
    mile = km * 0.621371
    > Ok, that is { mile } miles
}

  1. We create a function toMiles() that will be triggered by the intention conversion
  2. conversion intent contains workout phrases
  3. We retrieve the distance in kilometers using the magic variable :intent.distance.value
  4. The chatbot displays the answer

The competence

The main.js file only has this code:

import code from './main.converse'

export default {
    code
}

Deploy

Type newbot deploy and choose the relevant chatbot. You can test the chatbot directly on NewBot Cloud

© 2019 NewBot