Use @Intent

Intentions

Depending on a user's intent, a function can be triggered. For this, we use the Intent() decorator. The easiest way is to use a regular expression:

@Intent(/hello/i)
hey() {
    > Hey
}

Use the native NLP

You can use the native NLP system to get away from third-party platforms.

Advantages

  • Independent of third party platforms (no need for DialogFlow or others)

  • You can integrate this system directly into the browser. Useful for creating an offline chatbot

Disadvantages

  • You have no visibility on the phrases used by the user. On third-party platforms, they record the new sentences in order to add them to the chatbot's understanding.

  • Extraction of entities (a place, the name of a person, etc.) is less elaborate

  • On the browser side, your chatbot will be heavier

this will generate different browser and server side code

Create intentions with phrases to train.

In the conversational script of the skill, let's use the Intent decorator to create an intent:

@Intent('buy.product', [
    'I want an ice cream',
    'I want to buy a coffee'
])
buyProduct() {
    > Ok, I take your order
}

@Intent('buy.stop', [
    'cancel my order',
    'delete my purchase'
])
buyStop() {
    > Ok, I cancel the order
}

Phrases in several languages.

You have two ways

Add languages ​​to the conversational script

In the conversational script, here's how we can add phrases per language

@Intent('buy.product', {
    fr: [
        'Je veux une glace',
        'Je veux acheter un café'
    ],
    en: [
        'I want an ice cream',
        'I want to buy a coffee'
    ]
})
buyProduct() {
    > Ok, I take your order
}

Add languages ​​to the .json file

  1. Follow the internationalization tutorial

  2. Let's add the identifiers in the table:

Assuming the file languages/en_EN.json is the following

[
    {
        "want_ice_cream": "I want an ice cream",
        "want_coffee": "I want to buy a coffee"
    }, 
    {
        "plurial": {
            "p": [
                "s"
            ]
        }
    }
]

Here is the conversational script:

@Intent('buy.product', [
    '#want_ice_cream',
    '#want_coffee'
])
buyProduct() {
    > Ok, I take your order
}

Extract Entities

Some entities are extracted. You can read them with the magic variable :entity:

@Intent('buy.product', [
    'By today'
])
buyProduct() {
    > Ok, date is { :entity.date.value }
}

Last updated