api-bot

0.0.1 • Public • Published

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.

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.

baseCmd.text ⇒ String

Kind: instance property of BaseCmd
Returns: String - text message from the payload

baseCmd.payload ⇒ Object

Kind: instance property of BaseCmd
Returns: Object - payload payload from bot.

baseCmd.cmd ⇒ Object

Kind: instance property of BaseCmd
Returns: Object - cmd Command string.

baseCmd.tokens ⇒ Array.<String>

Kind: instance property of BaseCmd
Returns: Array.<String> - tokens Argument tokens.

BotMsg.SlashCmd ⇐ BaseCmd

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

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.

slashCmd.text ⇒ String

Kind: instance property of SlashCmd
Returns: String - text message from the payload

slashCmd.payload ⇒ Object

Kind: instance property of SlashCmd
Returns: Object - payload payload from bot.

slashCmd.cmd ⇒ Object

Kind: instance property of SlashCmd
Returns: Object - cmd Command string.

slashCmd.tokens ⇒ Array.<String>

Kind: instance property of SlashCmd
Returns: Array.<String> - tokens Argument tokens.

FbHook

Module for handling Facebook messenger hooks.

FbHook ⏏

Utility class to handle Facebook messenger APIs.

Kind: Exported class

FbHook.send(id, payload) ⇒ Promise

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.

FbHook.process(cmds, botCmd) ⇒ Promise

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.

FbHook~Attachment : Object

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.

FbHook~QuickReply : Object

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.

FbHook~Message : Object

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.

FbHook~Recipient : Object

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.

FbHook~Payload : Object

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.

Package Sidebar

Install

npm i api-bot

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • eterna2