Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IBotContext

Hierarchy

Index

Constructors

constructor

  • new IBotContext(update: Update, telegram: Telegram, options?: undefined | { username?: undefined | string }): IBotContext

Properties

alertManager

alertManager: AlertManager

Optional botInfo

botInfo: tt.User

Optional callbackQuery

callbackQuery: tt.CallbackQuery

Optional channelPost

channelPost: tt.Message

Optional chat

chat: tt.Chat

Optional chosenInlineResult

chosenInlineResult: tt.ChosenInlineResult

Optional editedChannelPost

editedChannelPost: tt.Message

Optional editedMessage

editedMessage: tt.Message

Optional from

from: tt.User

Optional inlineQuery

inlineQuery: tt.InlineQuery

Optional match

match: RegExpExecArray | null

Optional me

me: undefined | string

Optional message

message: tt.IncomingMessage

Optional poll

poll: tt.Poll

Optional pollAnswer

pollAnswer: tt.PollAnswer

Optional preCheckoutQuery

preCheckoutQuery: tt.PreCheckoutQuery

Optional shippingQuery

shippingQuery: tt.ShippingQuery

telegram

telegram: Telegram

tg

tg: Telegram

update

update: Update

updateSubTypes

updateSubTypes: tt.MessageSubTypes[]

updateType

updateType: tt.UpdateType

userIds

userIds: string[]

Methods

addStickerToSet

  • addStickerToSet(ownerId: number, name: string, stickerData: StickerData, isMasks: boolean): Promise<boolean>

answerCbQuery

  • answerCbQuery(text?: undefined | string, showAlert?: undefined | false | true, extra?: undefined | object): Promise<boolean>

answerGameQuery

  • answerGameQuery(url: string): Promise<boolean>

answerInlineQuery

  • answerInlineQuery(results: tt.InlineQueryResult[], extra?: tt.ExtraAnswerInlineQuery): Promise<boolean>
  • Use this method to send answers to an inline query. No more than 50 results per query are allowed.

    Parameters

    • results: tt.InlineQueryResult[]

      Array of results for the inline query

    • Optional extra: tt.ExtraAnswerInlineQuery

      Extra optional parameters

    Returns Promise<boolean>

    On success, True is returned.

answerPreCheckoutQuery

  • answerPreCheckoutQuery(ok: boolean, errorMessage?: undefined | string): Promise<boolean>
  • Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.

    Parameters

    • ok: boolean

      Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.

    • Optional errorMessage: undefined | string

      Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.

    Returns Promise<boolean>

answerShippingQuery

  • answerShippingQuery(ok: boolean, shippingOptions: ShippingOption[], errorMessage: string): Promise<boolean>
  • If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.

    Parameters

    • ok: boolean

      Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)

    • shippingOptions: ShippingOption[]

      Required if ok is True. A JSON-serialized array of available shipping options.

    • errorMessage: string

      Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.

    Returns Promise<boolean>

createNewStickerSet

  • createNewStickerSet(ownerId: number, name: string, title: string, stickerData: StickerData): Promise<boolean>
  • Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set

    Parameters

    • ownerId: number

      User identifier of created sticker set owner

    • name: string

      Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “by”. is case insensitive. 1-64 characters.

    • title: string

      Sticker set title, 1-64 characters

    • stickerData: StickerData

      Sticker object

    Returns Promise<boolean>

    Returns True on success.

deleteChatPhoto

  • deleteChatPhoto(): Promise<boolean>
  • Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

    Returns Promise<boolean>

    True on success

deleteMessage

  • deleteMessage(messageId?: undefined | 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 groups and supergroups.
    • 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.

    Parameters

    • Optional messageId: undefined | number

    Returns Promise<boolean>

    Returns True on success.

deleteStickerFromSet

  • deleteStickerFromSet(sticker: string): Promise<boolean>

editMessageCaption

  • editMessageCaption(caption?: undefined | string, markup?: tt.InlineKeyboardMarkup): Promise<Message | boolean>
  • Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

    Parameters

    • Optional caption: undefined | string

      New caption of the message

    • Optional markup: tt.InlineKeyboardMarkup

      Markup of inline keyboard

    Returns Promise<Message | boolean>

editMessageLiveLocation

  • editMessageLiveLocation(lat: number, lon: number, extra?: tt.ExtraLocation): Promise<MessageLocation | boolean>
  • Use this method to edit live location messages.

    Parameters

    • lat: number

      New latitude

    • lon: number

      New longitude

    • Optional extra: tt.ExtraLocation

    Returns Promise<MessageLocation | boolean>

    On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned.

editMessageMedia

  • editMessageMedia(media: tt.MessageMedia, extra?: tt.ExtraEditMessage): Promise<Message | boolean>
  • Use this method to edit animation, audio, document, photo, or video messages.

    Parameters

    • media: tt.MessageMedia

      New media of message

    • Optional extra: tt.ExtraEditMessage

    Returns Promise<Message | boolean>

    On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

editMessageReplyMarkup

  • editMessageReplyMarkup(markup?: tt.InlineKeyboardMarkup): Promise<Message | boolean>
  • Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).

    Parameters

    • Optional markup: tt.InlineKeyboardMarkup

      Markup of inline keyboard

    Returns Promise<Message | boolean>

    On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

editMessageText

  • editMessageText(text: string, extra?: tt.ExtraEditMessage): Promise<Message | boolean>
  • Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).

    Parameters

    • text: string

      New text of the message

    • Optional extra: tt.ExtraEditMessage

      Extra params

    Returns Promise<Message | boolean>

    On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

exportChatInviteLink

  • exportChatInviteLink(): Promise<string>
  • Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

    Returns Promise<string>

    exported invite link as String on success.

getChat

  • getChat(): Promise<Chat>
  • Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.)

    Returns Promise<Chat>

    a Chat object on success.

getChatAdministrators

  • getChatAdministrators(): Promise<Array<ChatMember>>
  • Use this method to get a list of administrators in a chat.

    Returns Promise<Array<ChatMember>>

    On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.

getChatMember

  • getChatMember(userId: number): Promise<ChatMember>
  • Use this method to get information about a member of a chat.

    Parameters

    • userId: number

      Unique identifier of the target user

    Returns Promise<ChatMember>

    a ChatMember object on success

getChatMembersCount

  • getChatMembersCount(): Promise<number>

getStickerSet

  • getStickerSet(setName: string): Promise<StickerSet>

kickChatMember

  • kickChatMember(userId: number, untilDate?: undefined | number): Promise<boolean>
  • Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights

    Parameters

    • userId: number

      Unique identifier of the target user

    • Optional untilDate: undefined | number

      Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever

    Returns Promise<boolean>

    True on success

leaveChat

  • leaveChat(): Promise<boolean>

pinChatMessage

  • pinChatMessage(messageId: number, extra?: undefined | { disable_notification?: undefined | false | true }): Promise<boolean>
  • Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights

    Parameters

    • messageId: number

      Identifier of a message to pin

    • Optional extra: undefined | { disable_notification?: undefined | false | true }

      Pass { disable_notification: true }, if it is not necessary to send a notification to all group members about the new pinned message

    Returns Promise<boolean>

    True on success

promoteChatMember

  • promoteChatMember(userId: number, extra: ExtraPromoteChatMember): Promise<boolean>
  • Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.

    Parameters

    • userId: number

      Unique identifier of the target user

    • extra: ExtraPromoteChatMember

    Returns Promise<boolean>

    True on success

reply

  • reply(text: string, extra?: tt.ExtraReplyMessage): Promise<Message>
  • Use this method to reply on messages in the same chat.

    Parameters

    • text: string

      Text of the message to be sent

    • Optional extra: tt.ExtraReplyMessage

      SendMessage additional params

    Returns Promise<Message>

    sent Message if Success

replyWithAudio

  • replyWithAudio(audio: tt.InputFile, extra?: tt.ExtraAudio): Promise<MessageAudio>
  • Use this method to send audio files to the same chat, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

    Parameters

    • audio: tt.InputFile

      Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data

    • Optional extra: tt.ExtraAudio

      Audio extra parameters

    Returns Promise<MessageAudio>

    On success, the sent Message is returned.

replyWithChatAction

  • replyWithChatAction(action: tt.ChatAction): Promise<boolean>
  • Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Choose one, depending on what the user is about to receive:

    • typing for text messages,
    • upload_photo for photos,
    • record_video or upload_video for videos,
    • record_audio or upload_audio for audio files,
    • upload_document for general files,
    • find_location for location data,
    • record_video_note or upload_video_note for video notes.

    Parameters

    • action: tt.ChatAction

      Type of action to broadcast.

    Returns Promise<boolean>

    True on success

replyWithDice

  • replyWithDice(extra?: tt.ExtraDice): Promise<MessageDice>
  • Use this method to send a dice, which will have a random value from 1 to 6. On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die. But it's awkward, and we decided to help it change. One dice at a time!)

    Parameters

    • Optional extra: tt.ExtraDice

      Additional params to send dice

    Returns Promise<MessageDice>

    a Message on success

replyWithDocument

  • replyWithDocument(document: tt.InputFile, extra?: tt.ExtraDocument): Promise<MessageDocument>
  • Use this method to send general files. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.

    Parameters

    • document: tt.InputFile

      File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data

    • Optional extra: tt.ExtraDocument

      Additional params for send document

    Returns Promise<MessageDocument>

    a Message on success

replyWithGame

  • replyWithGame(gameShortName: string, extra?: tt.ExtraGame): Promise<MessageGame>
  • Use this method to send a game

    Parameters

    • gameShortName: string

      Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.

    • Optional extra: tt.ExtraGame

      Additional params for send game

    Returns Promise<MessageGame>

    a Message on success

replyWithHTML

  • replyWithHTML(html: string, extra?: tt.ExtraReplyMessage): Promise<Message>
  • The Bot API supports basic formatting for messages

    Parameters

    • html: string

      You can use bold and italic text, as well as inline links and pre-formatted code in your bots' messages.

    • Optional extra: tt.ExtraReplyMessage

      Additional params to send message

    Returns Promise<Message>

    a Message on success

replyWithInvoice

  • replyWithInvoice(invoice: NewInvoiceParameters, extra?: tt.ExtraInvoice): Promise<MessageInvoice>
  • Use this method to send invoices

    Parameters

    • invoice: NewInvoiceParameters

      Object with new invoice params

    • Optional extra: tt.ExtraInvoice

      Additional params for send invoice

    Returns Promise<MessageInvoice>

    a Message on success

replyWithLocation

  • replyWithLocation(latitude: number, longitude: number, extra?: tt.ExtraLocation): Promise<MessageLocation>
  • Use this method to send point on the map

    Parameters

    • latitude: number

      Latitude of location

    • longitude: number

      Longitude of location

    • Optional extra: tt.ExtraLocation

      Additional params for send location

    Returns Promise<MessageLocation>

    a Message on success

replyWithMarkdown

  • replyWithMarkdown(markdown: string, extra?: tt.ExtraReplyMessage): Promise<Message>
  • The Bot API supports basic formatting for messages

    Parameters

    • markdown: string

      You can use bold and italic text, as well as inline links and pre-formatted code in your bots' messages.

    • Optional extra: tt.ExtraReplyMessage

      Additional params to send message

    Returns Promise<Message>

    a Message on success

replyWithMediaGroup

  • replyWithMediaGroup(media: tt.MessageMedia[], extra?: tt.ExtraMediaGroup): Promise<Array<Message>>
  • Use this method to send a group of photos or videos as an album

    Parameters

    • media: tt.MessageMedia[]

      A JSON-serialized array describing photos and videos to be sent, must include 2–10 items

    • Optional extra: tt.ExtraMediaGroup

      Additional params to send media group

    Returns Promise<Array<Message>>

    On success, an array of the sent Messages is returned

replyWithPhoto

  • replyWithPhoto(photo: tt.InputFile, extra?: tt.ExtraPhoto): Promise<MessagePhoto>
  • Use this method to send photos

    Parameters

    • photo: tt.InputFile

      Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data

    • Optional extra: tt.ExtraPhoto

      Additional params to send photo

    Returns Promise<MessagePhoto>

    a Message on success

replyWithPoll

  • replyWithPoll(question: string, options: string[], extra: ExtraPoll): Promise<MessagePoll>
  • Use this method to send a native poll.

    Parameters

    • question: string

      Poll question, 1-255 characters

    • options: string[]

      A JSON-serialized list of answer options, 2-10 strings 1-100 characters each

    • extra: ExtraPoll

      Additional params to send poll

    Returns Promise<MessagePoll>

    On success, the sent Message is returned.

replyWithQuiz

  • replyWithQuiz(question: string, options: string[], extra: ExtraPoll): Promise<MessagePoll>
  • Use this method to send a native quiz.

    Parameters

    • question: string

      Poll question, 1-255 characters

    • options: string[]

      A JSON-serialized list of answer options, 2-10 strings 1-100 characters each

    • extra: ExtraPoll

      Additional params to send quiz

    Returns Promise<MessagePoll>

    On success, the sent Message is returned.

replyWithSticker

  • replyWithSticker(sticker: tt.InputFile, extra?: tt.ExtraSticker): Promise<MessageSticker>
  • Use this method to send .webp stickers

    Parameters

    • sticker: tt.InputFile

      Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload a new one using multipart/form-data

    • Optional extra: tt.ExtraSticker

      Additional params to send sticker

    Returns Promise<MessageSticker>

    a Message on success

replyWithVideo

  • replyWithVideo(video: tt.InputFile, extra?: tt.ExtraVideo): Promise<MessageVideo>
  • Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document) Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.

    Parameters

    • video: tt.InputFile

      video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data

    • Optional extra: tt.ExtraVideo

      Additional params to send video

    Returns Promise<MessageVideo>

    a Message on success

replyWithVoice

  • replyWithVoice(voice: tt.InputFile, extra?: tt.ExtraVoice): Promise<MessageVoice>
  • Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.

    Parameters

    • voice: tt.InputFile

      Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data

    • Optional extra: tt.ExtraVoice

      Additional params to send voice

    Returns Promise<MessageVoice>

    a Message on success

restrictChatMember

  • restrictChatMember(userId: number, extra?: tt.ExtraRestrictChatMember): Promise<boolean>
  • Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.

    Parameters

    • userId: number
    • Optional extra: tt.ExtraRestrictChatMember

      Additional params for restrict chat member

    Returns Promise<boolean>

    True on success

setChatTitle

  • setChatTitle(title: string): Promise<boolean>
  • Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights

    Parameters

    • title: string

      New chat title, 1-255 characters

    Returns Promise<boolean>

    True on success

setStickerPositionInSet

  • setStickerPositionInSet(sticker: string, position: number): Promise<boolean>

stopMessageLiveLocation

  • stopMessageLiveLocation(extra?: tt.ExtraLocation): Promise<MessageLocation | boolean>
  • Use this method to stop updating a live location message before live_period expires.

    Parameters

    • Optional extra: tt.ExtraLocation

      Extra params

    Returns Promise<MessageLocation | boolean>

    On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.

stopPoll

  • stopPoll(messageId: number, extra: ExtraStopPoll): Promise<Poll>
  • Use this method to send a native quiz.

    Parameters

    • messageId: number

      Identifier of the original message with the poll

    • extra: ExtraStopPoll

      Additional params to stop poll

    Returns Promise<Poll>

    On success, the stopped Poll with the final results is returned.

unbanChatMember

  • unbanChatMember(userId: number): Promise<boolean>
  • Use this method to unban a user from a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights

    Parameters

    • userId: number

      Unique identifier of the target user

    Returns Promise<boolean>

    True on success

unpinChatMessage

  • unpinChatMessage(): Promise<boolean>

uploadStickerFile

  • uploadStickerFile(ownerId: number, stickerFile: tt.InputFile): Promise<File>
  • Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times) https://core.telegram.org/bots/api#sending-files

    Parameters

    • ownerId: number

      User identifier of sticker file owner

    • stickerFile: tt.InputFile

      Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

    Returns Promise<File>

    Returns the uploaded File on success

Generated using TypeDoc