Documentation

Do you use documentation to use NewBot Framework

Call a list of custom entities

The goal is to recover specific entities present in a sentence. For example :

I want to buy a place for the show You Show

Background:

  1. We create an intention
  2. The name of the intention in ConverseScript is buy

In schema, enter the following information:

  1. Identifier for entity: show
  2. Type: External Data

The value is composed of two pieces of information:

  1. URL to a webservice returning an object array in JSON format
  2. The property to read in the object in the table

For example, if the webservice returns the following table:

[
    {
        "id": 1,
        "name": "You Show",
        "price": 5
    }
]

So the property will be name

In the conversational script, you can retrieve the entity:

@Intent('buy')
buy() {
    show = :intent.show.value
    > Show name is { show.name }
}

Host the API

If you do not have a URL to call your API, you can create it directly in NewBot Cloud. For that,

  1. At the root of our project, let's add a file server/routes.js
  2. Let's return a function:
module.exports = (app, expressBot) => {
    app.get('/shows', (req, res, next) => {
        res.json([
            {
                "id": 1,
                "name": "You Show",
                "price": 5
            },
            // etc
        ])
    })
}

You can just put the /shows URL in the intent schema

The creation of the router uses expressJs. Routing documentation. Then, deploy with the newbot deploy command to turn on the API.

© 2019 NewBot