Bot

Bot

Communicates with the API and executes Processors on incoming updates

Constructor

new Bot(options)

Parameters:
Name Type Description
options object
Properties
Name Type Attributes Description
apiUrl String <nullable>

URL to the bot's API or null if any request's url should be able to be used

server Server <optional>
<nullable>

Server object, or null if no server should be set. Leave blank or pass undefined if the server should be generated automatically.

route string <optional>

The default route: e.g. if url is https://bot.com/hook?url=https://... pass '/webhook'

parser Requirement <optional>

The default parser. Used to parse the body from a HTTP request. As long as a Handler's parser option is not null, this Requirement will be added to all Handlers.

log object <optional>
<nullable>

Logger object containing npmlog's methods. Pass null to disable. If none is passed, npmlog will be used

Source:

Methods

handle(data, passedUrl, route, res)

Handles the data received from the API

Parameters:
Name Type Description
data string

The body supplied by the API

passedUrl string

URL supplied by the API

route string

The request's route

res ServerResponse

Response to be sent to the API

Source:

listen(port, host)

Invokes the server's listen method

Parameters:
Name Type Description
port number

Port to listen on

host string

Hostname for the server

Source:
See:

register(handler, optionsopt)

Register handler

Parameters:
Name Type Attributes Description
handler Handler

Handler object

options object <optional>

options for registering

Properties
Name Type Attributes Description
forceReplace boolean <optional>

Forces to replace Handler with same name

Source:

send(method, update, callback, optionsopt)

Sends an update to the API

Parameters:
Name Type Attributes Description
method string

Is appended to the API's URL

update object

The update object that should be sent

callback Bot~response

Callback containing error, response and body

options object <optional>

Options object

Properties
Name Type Attributes Description
silent boolean <optional>

Will not log the response if true

apiUrl string <optional>

Custom API URL

Source:

Type Definitions

response(error, response, body)

Callback containing the API's response data

Parameters:
Name Type Description
error object
response object
body String
Source: