Recast.AI is a collaborative bot platform for developers that makes it easy to use natural language understanding in conversational bots.
To create a new bot, login on Recast.AI and click on the link + NEW BOT in the header section.
- Choose a name and a description
- Set the default language, you will be able to add more languages later ;)
- Choose a template to start easily, the Meeting Bot is a complete bot example!
An intent is a box of expressions that mean the same thing but are constructed in different ways. Intents are the heart of your bot's understanding. Each one of your intents represents an idea your bot is able to understand. For example, an intent greetings makes your bot understand when a user says `Hello`. In the meeting bot you will find all intents you need to create a bot that can book you a meeting room. Explore each intent a little bit by clicking on the name and you will see expressions inside that train your bot to understand the user intent ;)
The optimal setting for a great intent is to contain around twenty different expressions. Add some expressions your users will say by typing the sentence in the field Add an expression.
If you click on one of the expressions you will see highlighted words, with tags. These are entities. They’re keywords detected in expressions that are important to you in order to automate a task.
We automatically detect 31 different entities like: Location, Datetime, Colors, Emojis, Number… We call them gold entities. If you need another entity, a custom one like a meal for a cooking bot, just select what you want to tag as your new entity and type a name. The more examples you provide, the better the detection will be ;)
Once you’ve set up your bot, you can test it with the console. Click on the TEST bubble icon on the top right to make it appear. Select the tab Analyse, and type a sentence to test if your bot is well trained: `I want meeting room 2 for tomorrow`
You will see which intent is detected and which entities are extracted. Click on the Smart view toggle to switch the view to the JSON mode. The JSON contains a lot of useful information about the message you’ve sent, like all the enrichments we can provide for the gold entities.
This JSON returned in the console is what you receive when you've sent a text (like a user input) and want to analyze it. To get that response, you need to make a request: How? First, get your Request access token: click on the little gear icon to go to the settings of your bot.
Go to your bot code folder and install the Recast.AI module:
npm install --save recastai
Set the Request access token (copied earlier) as a config var:
recime-cli config set RECASTAI_KEY=PASTE_YOUR_TOKEN_HERE
Once everything is set, you can analyse user input, get intents and entities from it, in the following way:
/*jshint esversion: 6 */
import recastai from 'recastai'
export default class Bot {
constructor(args) {
this.args = args
this.recastai = new recastai.request(process.env.RECASTAI_KEY)
}
execute() {
const text = this.args.text
return new Promise((resolve, reject) => {
this.recastai.analyseText(text)
.then(res => {
// get the intent detected
const intent = res.intent()
// get all the location entities extracted from your text
const locations = res.all('location')
// Do your code
resolve({
'text': `Intent is ${intent.slug}.`
})
}).catch(err => {
reject(err)
})
})
}
}