ApiClient

The API client class implements a raw api call via http requests & webhook reply

Constructor

new ApiClient(token, optionsopt, webhookResponseopt)

Parameters:
NameTypeAttributesDescription
tokenstring

Bot token

optionsTelegramOptions<optional>

Options

webhookResponsehttp.ServerResponse<optional>

Response object from HTTP server for reply via webhook if enabled

Members

webhookReply

Setter for webhookReply

Use this property to control reply via webhook feature.

webhookReply

Getter for webhookReply

Use this property to control reply via webhook feature.

Methods

(async) callApi(method, dataopt, extraopt) → {Promise.<(object|boolean|number)>}

Method for direct call telegram bots api methods

Takes an optional AbortSignal object that allows to cancel the API call if desired.

For example:

const controller = new AbortController();
const signal = controller.signal;
ctx.telegram.callApi ('getMe', {}, { signal })
  .then(console.log)
  .catch(err => {
    if (err instanceof AbortError) {
      console.log('API call aborted')
    } else throw err
  })

controller.abort(); // Abort request

Read more about request aborts

Parameters:
NameTypeAttributesDescription
methodstring

Telegram API method name

dataobject<optional>

Object with method parameters

extraCallApiExtra<optional>

Extra parameters

Returns:
Type: 
Promise.<(object|boolean|number)>