@acpaas-ui-widgets/nodejs-chatbot 中文文档教程
Chatbot Smart Widget BFF (Node)
这是一个 Node.js 后端服务库,用于为 Chatbot Smart Widget 创建 BFF 服务。 该小部件提供聊天界面。
有一个演示服务,请参阅下面的运行说明。
How to use
Installing
将此存储库中的 .npmrc 文件复制到应用程序的文件夹中。
然后安装(你需要在 digipolis 网络上):
> npm install --save @acpaas-ui-widgets/nodejs-chatbot
Using
Express example:
const express = require('express');
const chatbotService = require('@acpaas-ui-widgets/nodejs-chatbot-service');
const app = express();
const controller = chatbotService.chatbot.createController({
accessToken: <ACCESS_TOKEN> (you can find this in the chatbot interface under 'Instellingen'),
chatbot: <CHATBOT> the Id of the chatbot you want to address,
chatbotenv: <CHATBOT_ENV> test | production,
serviceUrl: <SERVICEURL> endpoint (api-store),
responseHandler: (optional) true(default) | false. The package needs to handle the http response or call 'next()'
apikey: <APIKEY> the apikey from the api-store
});
app.post('/api/chatbot', controller);
app.listen(3000);
Typescript example:
import * as express from 'express';
import chatbotService from '@acpaas-ui-widgets/nodejs-chatbot';
const app = express();
const controller = chatbotService.createController({
accessToken: <ACCESS_TOKEN> (you can find this in the chatbot interface under 'Instellingen'),
chatbot: <CHATBOT> the Id of the chatbot you want to address,
chatbotenv: <CHATBOT_ENV> test | production,
serviceUrl: <SERVICEURL> endpoint (api-store),
apikey: <APIKEY> the apikey from the api-store
});
app.post('/api/chatbot', controller);
app.listen(3000);
Run the demo app
创建一个包含以下内容的 .env 文件:
ACCESS_TOKEN=
CHATBOT=
CHATBOT_ENV=
PORT=(optional, defaults to 3000)
SERVICEURL=
TOKEN=
APIKEY=
通过在 api-store.antwerpen.be。 ACCESS_TOKEN 值可以在 chatbots.antwerpen.be 的设置屏幕底部获取(“API 令牌”)。
(在主机名需要的地方添加 -o
或 -a
扩展名以访问开发或验收环境。)
运行服务:
> npm install
> npm start
Service Specification
POST: /chats/{botId}/message?access_token={access_token}
{
"message": "Hello World",
"session_id": "<your session id>",
"type": "message",
"send": "true",
"metadata": {
"firstname": "Example",
"lastname:": "name",
"..." : "..."
}
}
- message: Your message to the bot,
- session_id: The chatsession
- type: message
- send: true
- metadata:: Metadata to be passed along, this has to be an object.
ResponseHandler
如果 responseHandler 设置为 false 包不会发送 http 响应。 相反,它将调用下一个函数并将响应放在 req.chatbotResponse
上。 如果您想在将消息发送到客户端之前修改/过滤消息,则可以使用此功能。
包含一个 example swagger description。
Contributing
我们欢迎您的错误报告和拉取请求。
请参阅我们的贡献指南。
License
该项目根据 MIT 许可发布。
Chatbot Smart Widget BFF (Node)
This is a Node.js backend service library to create a BFF service for the Chatbot Smart Widget. The widget provides a chat interface.
There is a demo service, see below for instructions on running it.
How to use
Installing
Copy the .npmrc file from this repo to your application's folder.
Then install (you will need to be on the digipolis network):
> npm install --save @acpaas-ui-widgets/nodejs-chatbot
Using
Express example:
const express = require('express');
const chatbotService = require('@acpaas-ui-widgets/nodejs-chatbot-service');
const app = express();
const controller = chatbotService.chatbot.createController({
accessToken: <ACCESS_TOKEN> (you can find this in the chatbot interface under 'Instellingen'),
chatbot: <CHATBOT> the Id of the chatbot you want to address,
chatbotenv: <CHATBOT_ENV> test | production,
serviceUrl: <SERVICEURL> endpoint (api-store),
responseHandler: (optional) true(default) | false. The package needs to handle the http response or call 'next()'
apikey: <APIKEY> the apikey from the api-store
});
app.post('/api/chatbot', controller);
app.listen(3000);
Typescript example:
import * as express from 'express';
import chatbotService from '@acpaas-ui-widgets/nodejs-chatbot';
const app = express();
const controller = chatbotService.createController({
accessToken: <ACCESS_TOKEN> (you can find this in the chatbot interface under 'Instellingen'),
chatbot: <CHATBOT> the Id of the chatbot you want to address,
chatbotenv: <CHATBOT_ENV> test | production,
serviceUrl: <SERVICEURL> endpoint (api-store),
apikey: <APIKEY> the apikey from the api-store
});
app.post('/api/chatbot', controller);
app.listen(3000);
Run the demo app
Create a .env file containing:
ACCESS_TOKEN=
CHATBOT=
CHATBOT_ENV=
PORT=(optional, defaults to 3000)
SERVICEURL=
TOKEN=
APIKEY=
Obtain the APIKEY by taking out a contract on the chatbot-api
service on api-store.antwerpen.be. The ACCESS_TOKEN value can be obtained at the bottom of the settings screen ("API token") on chatbots.antwerpen.be.
(Add -o
or -a
extensions where needed to the host names to access the development or acceptance environments.)
Run the service:
> npm install
> npm start
Service Specification
POST: /chats/{botId}/message?access_token={access_token}
{
"message": "Hello World",
"session_id": "<your session id>",
"type": "message",
"send": "true",
"metadata": {
"firstname": "Example",
"lastname:": "name",
"..." : "..."
}
}
- message: Your message to the bot,
- session_id: The chatsession
- type: message
- send: true
- metadata:: Metadata to be passed along, this has to be an object.
ResponseHandler
If the responseHandler is set to false the package will not send the http response. Instead it will call the next function and put the response on req.chatbotResponse
. This feature can be used if you would like to modify / filter the message before it's sent to the client.
An example swagger description is included.
Contributing
We welcome your bug reports and pull requests.
Please see our contribution guide.
License
This project is published under the MIT license.