"Hello world" App
A FrontM.js App is a JavaScript function that receives a State as its input parameter and returns an array of Intents:
const Bot = state => {
let main = new Intent('main', state);
main.onResolution = async () => {
state.addStringResponse('Hello World!');
};
};
This App is a very basic example and returns only one Intent called "main".
let main = new Intent('main', state);
"main" is not a mandatory Intent but, when present, will always run when the user starts a conversation.
The "Hello World" App does nothing i.e. it won’t respond to a user question. In order to do that, we could assoctate an NLP agent as follows.
const Bot = state => {
state.nlp.addNlp('FMApp');
let main = new Intent('main');
main.onResolution = async () => {
state.addStringResponse('Hello World! How are you?');
};
};
The NLP agent "FMApp" could implement a questions and answers, chitchat, etc, making the bot more interactive.
Developers can associate a NLP agent to their apps with the following instructions passing the agent ID:
state.nlp.addNlp('FMApp');
The current FrontM architecture uses Google Dialogflow, AWS Lex or GPT-3 as NLP engines; we will, however, soon be using an internal solution to support NLP at the edge.
Next, we can offer the user a couple of suggestions on what to send to the App:
const Bot = state => {
state.nlp.addNlp('FMApp');
let main = new Intent('main');
main.onResolution = async () => {
state.addStringResponse('Hello World! How are you?');
state.addEnglishSmartSuggestions(['Hello', 'How can you help me?']);
};
};
We have added the following line to the script:
state.addEnglishSmartSuggestions(['Hello', 'How can you help me?']);
So instead of the user typing a response, the App will display two suggestions they can select from. It will then act exactly as if the user has typed them.
Here is another way of adding smart suggestions:
const Bot = state => {
state.nlp.addNlp('FMApp');
let main = new Intent('main');
main.setEnglishSmartSuggestions([['Hello', 'How can you help me?']);
main.onResolution = async () => {
state.addStringResponse('Hello World! How are you?');
};
};
The difference between the two methods is that, in the second one, the suggestions are displayed all the time and not just after the code has executed.
Comments
0 comments
Please sign in to leave a comment.