Skip to content

Parse sentence

Guidone edited this page Aug 22, 2017 · 1 revision

The Listen Node is able to detect and parse a set of simple sentence with a very simple keyword detection algorithm. For example suppose we would like to offer the the chatbot user the option to request our curriculum vitae and deliver that by email

Example Email

The first block listen to incoming message and verify that it matches a set of tokens, if it matches the message is routed to the first output or second output, otherwise the last one. The Listen Node is configured in this way

Example Listen Node

All the keywords for a row must match the input message in order to have the message go through the related output. Smaller keywords requires an exact match, longer ones match with Levehnstein algorithm (so for example the keyword "building" also matches "boilding").

The token ->email it's used to save the matched word to the chat context variable email. The keyword * matches everything and it's generally used as a catch-all in case all previous rules failed. Remember that if a rules is matched, the following rules are skipped and not tested.

For example:

"send your cv to [email protected]" // ok
"send your curriculum to [email protected]" // ok
"send your curricula to [email protected]" // ok
"send your curriculum" // no, missing email
"send to [email protected]" // no, missing cv or curriculum token

Listen node is also capable of a basic simple analysis of the sentence (only available for English) and a more specific match is possible to specify also the type for a keyword.

Available types are: word (catches everything), noun, verb, adjective, conjunction, adverb, symbol, date, determiner, person, number, email, url, currency.

For a better match we can rewrite the rules in this way, in that case only valid email will be catched

Example Listen Node

The generic syntax of a token is text-to-match[type]->variable

  • text-to-match: the text to match
  • type: the type of token (verb, number, url, etc.)
  • variable: the variable name to store the value into

A little bit of coding is required to prepare the payload for the email node

// get the chat context
var chat = msg.chat();
// email payload
msg.to = chat.get('email');
msg.payload = 'Hi, this is my curriculum vitae';
msg.attachments = [
  {
   filename: 'my_cv.pdf',
   path: '/my_cv.pdf'
}];
return msg;

The output 1 and 2 of the Listen Node are connected to a confirmation message to be sent back to the user: Sending resume to {{myemail}}. Here the variable {{myemail}} is automatically replaced by the value present in the chat context.

Clone this wiki locally