@yoctol/kurator
v0.50.9
Published
```sh yarn add @yoctol/kurator ```
Downloads
632
Readme
Installation
yarn add @yoctol/kurator
Usage
const Kurator = require('@yoctol/kurator');
const { createDeployMiddleware } = require('@yoctol/kurator/koa');
const { middleware } = require('bottender');
const kurator = new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
});
bot.onEvent(
middleware([
kurator.createBottenderMiddleware(),
(context) => {
// ...
},
])
);
To get specific action, use kurator.getAction
:
const action = kurator.getAction('<ACTION_ID>');
To register local action, use kurator.registerAction
:
kurator.registerAction('<ACTION_ID>', (context) => {
/* ... */
});
To register multiple local actions, use kurator.registerActions
:
kurator.registerActions({
'<ACTION_ID_1>': (context) => {
/* ... */
},
'<ACTION_ID_2>': (context) => {
/* ... */
},
});
Debug
Add DEBUG
env variable for debug package:
DEBUG=kurator
DEBUG=kurator:chatbase
DEBUG=kurator:trigger
DEBUG=kurator:predict
Updating
Webhook:
router.use('deployz', createDeployMiddleware({ kurator }));
Polling:
const kurator = new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
polling: {
interval: 5 * 60 * 1000,
},
});
Run with Action Map
If a map between actionId and actionName is needed, visit: https://kurator.yoctol.com/api/projects/<PROJECT_ID>/action-map
And the result is a map as below:
{
"FOO": "87654321",
"BAR": "12345678"
}
To get action map support in Kurator SDK, just passing actionMap
to your Kurator
constructor:
const kurator = new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
actionMap: {
FOO: '87654321',
BAR: '12345678',
},
});
After that, you can trigger your action by key of the action map:
kurator.getAction('FOO');
// calling with context
await kurator.getAction('FOO')(context);
Add Chatbase Support
const kurator = new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
chatbase: {
apiKey: '<CHATBASE_KEY>',
},
});
Specify Environment
const kurator = new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
environment: 'staging', // Enum: 'staging' | 'production'
});
Use customAdapter
to Handle Universal Platform
const customAdapter = {
toTextAction: ({ descriptor: { text, buttons } }) => (context) =>
context.sendText(text),
toImageAction: ({
descriptor: { imageUrl, title, subtitle, webUrl, buttons },
}) => (context) => context.sendImage(imageUrl),
};
new Kurator({
projectId: '<PROJECT_ID>',
accessToken: '<ACCESS_TOKEN>',
customAdapter,
});