api-bot
An api-bot
is an customizable chat bot that can proxy with any APIs and
transform the results into a bot message. A JSON or YAML config file is used to
describe the both the interaction with the API and the transformation of the
output. The config file/doc can also easily be served via a noSQL database.
This is a NodeJS library to handle various instructions for an api-bot
.
Quick start
yarn add api-bot --save
API Reference
BotMsg
Module for handling messages from bot.
BotMsg.BaseCmd
Base class to parse message string into commands and arguments.
Kind: static class of BotMsg
Properties
Name | Type | Description |
---|---|---|
payload | Object |
payload from bot. |
text | String |
text message from the payload. |
cmd | String |
Command string. |
tokens | Array.<String> |
Argument tokens. |
- .BaseCmd
- new BaseCmd(payload, textAccessor)
- .text ⇒
String
- .payload ⇒
Object
- .cmd ⇒
Object
- .tokens ⇒
Array.<String>
new BaseCmd(payload, textAccessor)
Create a new BaseCmd instance.
Param | Type | Description |
---|---|---|
payload | Object |
payload from bot. |
textAccessor | function |
accessor function to extract message text from the payload. |
String
baseCmd.text ⇒ Kind: instance property of BaseCmd
Returns: String
- text message from the payload
Object
baseCmd.payload ⇒ Kind: instance property of BaseCmd
Returns: Object
- payload payload from bot.
Object
baseCmd.cmd ⇒ Kind: instance property of BaseCmd
Returns: Object
- cmd Command string.
Array.<String>
baseCmd.tokens ⇒ Kind: instance property of BaseCmd
Returns: Array.<String>
- tokens Argument tokens.
BaseCmd
BotMsg.SlashCmd ⇐ Class to extract a slash command string (i.e. /hello
) and the argument tokens from a text message.
Kind: static class of BotMsg
Extends: BaseCmd
- .SlashCmd ⇐
BaseCmd
- new SlashCmd(payload, textAccessor)
- .text ⇒
String
- .payload ⇒
Object
- .cmd ⇒
Object
- .tokens ⇒
Array.<String>
new SlashCmd(payload, textAccessor)
Create a new SlashCmd instance.
Param | Type | Description |
---|---|---|
payload | Object |
payload from bot. |
textAccessor | function |
accessor function to extract message text from the payload. |
String
slashCmd.text ⇒ Kind: instance property of SlashCmd
Returns: String
- text message from the payload
Object
slashCmd.payload ⇒ Kind: instance property of SlashCmd
Returns: Object
- payload payload from bot.
Object
slashCmd.cmd ⇒ Kind: instance property of SlashCmd
Returns: Object
- cmd Command string.
Array.<String>
slashCmd.tokens ⇒ SlashCmd
Returns: Array.<String>
- tokens Argument tokens.
Kind: instance property of FbHook
Module for handling Facebook messenger hooks.
- FbHook
- FbHook ⏏
- static
- .send(id, payload) ⇒
Promise
- .process(cmds, botCmd) ⇒
Promise
- .send(id, payload) ⇒
- inner
- ~Attachment :
Object
- ~QuickReply :
Object
- ~Message :
Object
- ~Recipient :
Object
- ~Payload :
Object
- ~Attachment :
- static
- FbHook ⏏
FbHook ⏏
Utility class to handle Facebook messenger APIs.
Promise
FbHook.send(id, payload) ⇒ Utility class to handle Facebook messenger APIs.
Kind: static method of FbHook
Param | Type | Description |
---|---|---|
id | String |
id of the Facebook recipient to send the message to. |
payload | Payload |
Payload to Facebook messenger. |
Promise
FbHook.process(cmds, botCmd) ⇒ Function to process a bot message from Facebook messenger.
Kind: static method of FbHook
Param | Type | Description |
---|---|---|
cmds | Object.<String, Api.Transformer> |
A map of Api.Transformer . |
botCmd | BotMsg.BaseCmd |
BotMsg.BaseCmd instance. |
Object
FbHook~Attachment : attachment
object for response message to Facebook messenger.
details
Kind: inner typedef of FbHook
Properties
Name | Type | Description |
---|---|---|
type | String |
Type of attachment, may be image , audio , video , file or template . |
payload | Any |
Payload of attachment. |
Object
FbHook~QuickReply : quick_reply
object for response message to Facebook messenger.
details
Kind: inner typedef of FbHook
Properties
Name | Type | Description |
---|---|---|
content_type | String |
text or location . |
title | String |
Caption of button. |
payload | String | Number |
Custom data that will be sent back to you via webhook. |
image_url | String |
URL of image for text quick replies. |
Object
FbHook~Message : message
object for response message to Facebook messenger.
details
Kind: inner typedef of FbHook
Properties
Name | Type | Description |
---|---|---|
text | String |
Message text. Previews will not be shown for the URLs in this field. Use attachment instead. Must be UTF-8 and has a 640 character limit. |
attachment | Attachment |
attachment object. Previews the URL. Used to send messages with media or Structured Messages. |
quick_replies | Array.<QuickReply> |
Array of quick_reply to be sent with messages. |
metadata | String |
Custom string that is delivered as a message echo. 1000 character limit. |
Object
FbHook~Recipient : payload
object for response message to Facebook messenger.
Kind: inner typedef of FbHook
Properties
Name | Type | Description |
---|---|---|
id | String | Number |
id of the Facebook messenger recipient. |
Object
FbHook~Payload : payload
object for response message to Facebook messenger.
details
Kind: inner typedef of FbHook
Properties
Name | Type | Description |
---|---|---|
recipient | Recipient |
Recipient object. |
message | Message |
Message object. |
sender_action | String |
typing_on , typing_off or mark_seen . |
notification_type | String |
REGULAR , SILENT_PUSH , NO_PUSH . Defaults to REGULAR . |
tag | String |
The message tag string. See Message Tags. |