@acpaas-ui-widgets/ngx-chatbot 中文文档教程
Chatbot Smart Widget UI (Angular)
使用聊天机器人智能小部件,您可以简单地在任何页面中实现聊天机器人。
您还需要 BFF 包才能让聊天机器人智能小部件工作:http://github.com/TriangleJuice/chatbot servicenodejs
有演示应用程序,请参阅下面的运行说明。
How to use
Installing
> npm install @acpaas-ui-widgets/ngx-chatbot
在您的模块中导入组件:
@NgModule({
imports: [
...,
ChatbotModule
],
...
})
在 index.html 中,包含核心品牌样式表:
<link rel="stylesheet" href="https://cdn.antwerpen.be/core_branding_scss/5.0.1/main.min.css">
对于仍在使用 Angular 5 的项目,我们是 维护一个 v1 分支,如果需要,它仍然会收到错误修复。
> npm install @acpaas-ui-widgets/ngx-chatbot@"<2.0.0"
In your template
<aui-chatbot
url="http://localhost:3000/api/bff"
session="123456789"
title="My great chatbot widget"
placeholder="Type your message here…"
[pinned]="false"
[delay]="200"
[height]="400">
</aui-chatbot>
Supported attributes
url
string
BFF 网址。
session
string
聊天机器人引擎所需的会话 ID,其中每个聊天对话都链接到其聊天会话。 使用唯一 ID 很重要,因为所有会话数据(例如已经给出的答案)都存储在聊天机器人引擎中。
title
string
聊天窗口上方的标题。
pinned
boolean
聊天机器人是内联的还是固定在应用程序的底部。
placeholder
string
聊天输入字段中的占位符字符串。
delay
number
从聊天机器人引擎接收到的多条消息之间的延迟。
height
number
聊天机器人的高度(以像素为单位)。 只能在 pinned="false"
时使用。
width
number
聊天机器人的宽度(以像素为单位)。 只能在 pinned="true"
时使用。 不会小于 18rem
。
avatar
string
头像图片地址。 默认是特殊提供的安特卫普图标。
aria
ChatbotMessageAriaLabels
整个聊天机器人 UI 中使用的辅助功能字符串:
默认值:
{
chatbot: 'Chatbot',
close: 'Chatbot minimaliseren',
avatar: 'Chatbot:',
user: 'Jij:',
message: 'Te verzenden bericht',
send: 'Bericht verzenden',
toggle: 'Een vraag stellen',
}
Events
actionStarted
当用户单击类型为 action
的消息按钮时触发。 这种类型的消息由 BFF 通过将其注入到响应中来注入。 actionStarted
输出事件需要定义的操作并暂停聊天机器人小部件的工作,等待具有相同定义操作的方法调用 (completeAction
)。 它允许开发人员在返回聊天机器人对话之前处理聊天机器人之外的一些事情(例如付款)。
How does it work?
<aui-chatbot
#myChatbotWithAction
[url]="'http://localhost:3000/api/chatbot'"
[session]="session1"
(actionStarted)="triggerMe($event)">
</aui-chatbot>
- Your BFF sends a message of type
action
with one or more actions defined.
{
actions: [
{
action: 'someAction',
text: 'Click me',
}
]
}
- When the user clicks this button, the defined
actionStarted
output event will fire and the chatbot is disabled.
public triggerMe(event) {
// Do something with `event`
}
$event
can now be handled in the parent controller and whenever finished, the chatbot widget'scompleteAction
method can be triggered to re-enable the chatbot conversation. The result will be sent as a hidden message to the chatbot engine.
重要的!
completeAction
的方法属性必须包含与禁用聊天机器人时首次定义的完全相同的action
值,否则聊天机器人将忽略方法调用。
const result = {
action: 'someAction',
message: 'success',
}
this.myChatbotWithAction.completeAction(result);
Run the demo app
> npm install
> npm start
浏览到 localhost:4200
为了使用聊天机器人小部件演示应用程序,您还需要启动相应的后端服务。
Contributing
我们欢迎您的错误报告和拉取请求。
请参阅我们的贡献指南。
Support
Jasper Van Proeyen (jasper.vanproeyen@digipolis.be)
License
此项目根据 MIT 许可证发布。
Chatbot Smart Widget UI (Angular)
With the chatbot smart widget you can simply implement a chatbot in any page.
You will also need the BFF package in order to get the chatbot smart widget to work: http://github.com/TriangleJuice/chatbotservicenodejs
There is a demo app, see below for instructions on running it.
How to use
Installing
> npm install @acpaas-ui-widgets/ngx-chatbot
Import the component in your module:
@NgModule({
imports: [
...,
ChatbotModule
],
...
})
In the index.html, include the core branding stylesheet:
<link rel="stylesheet" href="https://cdn.antwerpen.be/core_branding_scss/5.0.1/main.min.css">
For projects that are still using Angular 5, we are maintaining a v1 branch, which will still receive bug fixes if needed.
> npm install @acpaas-ui-widgets/ngx-chatbot@"<2.0.0"
In your template
<aui-chatbot
url="http://localhost:3000/api/bff"
session="123456789"
title="My great chatbot widget"
placeholder="Type your message here…"
[pinned]="false"
[delay]="200"
[height]="400">
</aui-chatbot>
Supported attributes
url
string
BFF URL.
session
string
Required session ID for the chatbot engine, where each chat conversation is linked to its chat session. It's important to use a unique id, since all session data, like answers already given, are stored in the chatbot engine.
title
string
Title above the chat window.
pinned
boolean
Whether the chatbot is inline or pinned to the bottom of the application.
placeholder
string
Placeholder string in the chat input field.
delay
number
Delay between multiple messages received from the chatbot engine.
height
number
Height of the chatbot in pixels. Can only be used when pinned="false"
.
width
number
Width of the chatbot in pixels. Can only be used when pinned="true"
. Will not be smaller than 18rem
.
avatar
string
Avatar image URL. Default is the special provided Antwerp icon.
aria
ChatbotMessageAriaLabels
Accessibility strings used throughout the chatbot UI:
Default:
{
chatbot: 'Chatbot',
close: 'Chatbot minimaliseren',
avatar: 'Chatbot:',
user: 'Jij:',
message: 'Te verzenden bericht',
send: 'Bericht verzenden',
toggle: 'Een vraag stellen',
}
Events
actionStarted
Triggers when the user clicks a button of a message with type action
. This type of message is injected by the BFF by injecting it into the response. The actionStarted
output event requires a defined action and pauses the workings of the chatbot widget, waiting for a method call (completeAction
) that has the same defined action. It allows the developer to handle some things outside the chatbot (e.g. a payment) before returning to the chatbot conversation.
How does it work?
<aui-chatbot
#myChatbotWithAction
[url]="'http://localhost:3000/api/chatbot'"
[session]="session1"
(actionStarted)="triggerMe($event)">
</aui-chatbot>
- Your BFF sends a message of type
action
with one or more actions defined.
{
actions: [
{
action: 'someAction',
text: 'Click me',
}
]
}
- When the user clicks this button, the defined
actionStarted
output event will fire and the chatbot is disabled.
public triggerMe(event) {
// Do something with `event`
}
$event
can now be handled in the parent controller and whenever finished, the chatbot widget'scompleteAction
method can be triggered to re-enable the chatbot conversation. The result will be sent as a hidden message to the chatbot engine.
Important! The method property of
completeAction
has to contain the exact sameaction
value that was first defined when disabling the chatbot, otherwise the chatbot will just ignore the method call.
const result = {
action: 'someAction',
message: 'success',
}
this.myChatbotWithAction.completeAction(result);
Run the demo app
> npm install
> npm start
Browse to localhost:4200
In order to use the chatbot widget demo app, you will also need to have started the corresponding back-end service.
Contributing
We welcome your bug reports and pull requests.
Please see our contribution guide.
Support
Jasper Van Proeyen (jasper.vanproeyen@digipolis.be)
License
This project is published under the MIT license.