Each key represents an NLP system. We have already had a first look at it with regular expressions under [/ docs / trigger / intent]. This time, we want to call a third-party API. Here is a complete example:
We can retrieve user information using userId and instance converse
We make a request to the third-party API by sending data (here, the text and the current language of the user)
We return a list of intentions following the same process as seen in chapter [/ docs / trigger / intent]
If ret.intentName is welcome, then we can trigger the intent in ConverseScript:
Share an NLP system with other skills
Here is the project structure:
bot
skills
skill-a
skill-a.js
skill-b
skill-b.js
nlp
my-api.js
main.js
main.converse
As we can see, we created an nlp folder containing the my-api.js file. This file must return the NLP system:
In each skill, let's add the NLP system:
In skill-a.js, we have:
In skill-b.js, we have:
At first glance, we find that the NLP system will be called twice: once in the skill-a skill and another time in the skill-b skill. If the NLP system makes a request, it is not wise to do the same request twice. Do not worry, NewBot has been optimized. He caches the NLP system and calls it only once.
Spread the NLP system
Although the previous method is the most recommended (because we can do unit tests per skill), we can also use the propagateNlp property on a parent skill to propagate the NLP system to child skills:
In the main.js file:
In this way, all the child skills will have the NLP system. We do not need to put in each child's skill