wa-chat-server-unblu
v0.8.2
Published
wa-chat-server adapter for Unblu
Downloads
12
Maintainers
Readme
wa-chat-server-unblu
wa-chat-server-unblu is a wa-chat-server adapter for the Unblu collaboration server.
Adapter Usage
Register the Adapter
A sample initialization of the wa-chat-server (in a chat application using wa-chat-server to communicate with Watson Assistant) with a wa-chat-server-unblu adapter:
import { WAChatServer, Types } from "wa-chat-server";
import { WAChatServerUnbluAdapter } from "wa-chat-server-unblu";
import { config } from "dotenv";
config();
const server: WAChatServer = new WAChatServer((process.env as any) as Types.IWAChatServerConfig);
server.addAdapter("unblu", WAChatServerUnbluAdapter);
server.serve();
Configure the Adapter
To pass configuration into the Adapter, use the wa-chat-server naming convention. Set the following environment variables (e.g. in .env
):
| Variable | Obligatory | Meaning |
| ------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| adapter__unblu__unbluApiUrl
| Y | Base URL for API endpoints on Unblu Collaboration Server, up to API version (../rest/v3) |
| adapter__unblu__unbluApiUsername
| Y | Unblu basic authentication Username (account is created in Unblu Web UI) |
| adapter__unblu__unbluApiPassword
| Y | Unblu basic authentication Password (account is created in Unblu Web UI) |
| adapter__unblu__webhookApiKey
| N | Secret to verify sender (Unblu) of incoming webhook events - same value must be set in Unblu when registering bot); This also requires wa-chat-server configuration json_raw_body=true
; If left empty, validation will not be performed |
| adapter__unblu__webhookSecuritySha1
| N | If set to true
the Adapter will use SHA-1 (x-unblu-signature
header) algorithm to validate webhook events instead of SHA-256 (x-unblu-signature-256
header) |
| adapter__unblu__messageStaggerMs
| N | Amount in milliseconds between messages when sending multiple responses to a single request (default is 600) |
| adapter__unblu__fallbackMessages
| N | Messages to be sent in case there is a technical outage of Watson Assistant service; Multiple answers can be specified separated by semicolon (Message1;Message2;Message3) |
| adapter__unblu__mapping
| N | Use this optional configuration to specifically map Watson Assistant response types to Unblu message types |
import { ResponseType, Message$Type } from "wa-chat-server-unblu";
const { disambiguation, option, text } = ResponseType;
const { OptionsPost, QuickReply, TextPost } = Message$Type;
const adapter__unblu__mapping = {
[disambiguation]: OptionsPost,
[option]: QuickReply,
[text]: TextPost,
}
Watson Assistant Response Types
disambiguation
- Disambiguationoption
- Optionstext
- Text reply
Unblu Message Types
OptionPost
- Title message with buttons as options; One of the options must be selected; The buttons carry payload which can be different than label displayedQuickReply
- Optional response buttons that can be used instead of typing the response; When using an quick reply the value sent is the same as the labelTextPost
- Block of markdown text
Important: If [text]: QuickReply
mapping is used, the buttons are attached to the last TextPost
instead of being sent as an individual message. This is mainly used to avoid using Title from Options in Watson Response and also prevents prefixing the option buttons with empty message box.