Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • TelegramAPI

Implements

Index

Constructors

constructor

  • new TelegramAPI(token: string, host: string): TelegramAPI
  • TelegramAPI constructor

    Parameters

    • token: string

      Bot token

    • host: string

      Public secure url

    Returns TelegramAPI

Properties

Private callbackQueryHandler

callbackQueryHandler: QueryHandler = null

Private host

host: string

Public secure url

Private state

state: Map<string, (ctx: Message) => void> = new Map<string, CommandHandler>()

Private token

token: string

Bot token

Methods

answerCallbackQuery

  • answerCallbackQuery(id: string, text: string, showAlert?: boolean): Promise<boolean>
  • Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.

    Parameters

    • id: string

      Unique identifier for the query to be answered.

    • text: string

      Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.

    • Default value showAlert: boolean = false

      Default: false. If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.

    Returns Promise<boolean>

cmd

  • Use this method register the command message.

    Parameters

    • name: string

      Command name (without "/" charater).

    • handler: CommandHandler

      Command hanlder (executed when a message sent by a user matches the command message that is registered).

    Returns Map<string, CommandHandler>

delCmd

  • delCmd(name: string): boolean
  • Use this method to unregister the command message.

    Parameters

    • name: string

      Command name (include "/" charater, e.q: "/command-name").

    Returns boolean

deleteText

  • deleteText(chatId: ChatId, msgId: number): Promise<boolean>
  • Use this method to delete a message, including service messages, with the following limitations:

    • A message can only be deleted if it was sent less than 48 hours ago.
    • Bots can delete outgoing messages in private chats, groups, and supergroups.
    • Bots can delete incoming messages in private chats.
    • Bots granted can_post_messages permissions can delete outgoing messages in channels.
    • If the bot is an administrator of a group, it can delete any message there.
    • If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. Returns True on success.

    Parameters

    • chatId: ChatId

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • msgId: number

      Identifier of the message to delete.

    Returns Promise<boolean>

editMessageCaption

  • Use this method to edit captions of messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

    Parameters

    • chatId: ChatId

      Unique identifier for the target chat or username of the target channel (in the format @channelusername).

    • msgId: number

      Identifier of the message to edit.

    • Optional opt: editCaptionOpt

      Optional parameter. See.

    Returns Promise<Message>

editText

  • Use this method to edit text messages. On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

    Parameters

    • chatId: ChatId

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • msgId: number

      Identifier of the message to edit.

    • Optional opt: editTextOpt

      Optional parameter. See

    Returns Promise<Message>

Private forwardUpdate

  • forwardUpdate(update: Update): void
  • Receive updates from the webhook and proceed to the corresponding handler.

    Parameters

    • update: Update

      Update from Telegram server.

    Returns void

on

  • Use this method to set a handler for specific events.

    Parameters

    • event: "callback_query"

      Event name, e.q: "callback_query".

    • handler: QueryHandler

      Query handler.

    Returns void

sendPhoto

  • Use this method to send photos. On success, the sent Message is returned.

    Parameters

    • chatId: ChatId

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • photo: PathLike

      Path photo to send.

    • Optional opt: sendPhotoOpt

      Optional parameter. See

    Returns Promise<Message>

sendText

  • Use this method to send text messages. On success, the sent Message is returned.

    Parameters

    • chatId: ChatId

      Unique identifier for the target chat or username of the target channel (in the format @channelusername)

    • text: string

      Text of the message to be sent

    • Optional opt: SendTextOpt

      Optional parameter. See

    Returns Promise<Message>

startWebhook

  • startWebhook(endpoint: string, port: number, cb: () => void): TelegramAPI
  • Use this method to start the webhook server to receive incoming updates from the Telegram server when the user sends a message or request.

    Parameters

    • endpoint: string

      Secret path to receive incoming updates

    • port: number

      protocol port.

    • cb: () => void

      callback function called when the server is started.

        • (): void
        • Returns void

    Returns TelegramAPI

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc