Skip to content

Context Object

Abdi Urgessa edited this page Feb 18, 2024 · 12 revisions

The Context Object (often referred to as ctx within code examples) is a central part of the bot framework, providing a wide array of methods for interacting with the bot API, managing messages, queries, games, payments, chats, stickers, and more. It encapsulates the current state and context in which the bot operates, allowing for responsive and dynamic interactions with users.

Usage Example

bot.on("message", (ctx) => {
  ctx.reply("Welcome to the bot!");
});

Available Methods

The Context Object offers a comprehensive suite of methods categorized by their purpose and functionality:

Update Management

  • update
  • messageUpdate
  • editedMessageUpdate
  • channelPostUpdate
  • editedChannelPostUpdate
  • inlineQueryUpdate
  • chosenInlineResultUpdate
  • callbackQueryUpdate
  • shippingQueryUpdate
  • preCheckoutQueryUpdate
  • pollUpdate
  • pollAnswerUpdate
  • myChatMemberUpdate
  • chatMemberUpdate
  • chatJoinRequestUpdate
  • messageReactionUpdate
  • messageReactionCountUpdate
  • chatBoostUpdate
  • removedChatBoostUpdate
  • updateType
  • chat
  • from
  • message
  • chatId
  • userId
  • messageId

Callback Query Management

  • answerCallbackQuery

Inline Query Management

  • answerInlineQuery
  • answerWebAppQuery

Bot Information Management

  • getWebhookInfo
  • deleteMyCommands
  • setMyCommands
  • getMyCommands
  • setMyName
  • getMyName
  • setMyDescription
  • getMyDescription
  • setMyShortDescription
  • getMyShortDescription
  • setMyDefaultAdministratorRights
  • getMyDefaultAdministratorRights
  • getMe
  • logOut
  • close

Sticker Management

  • sendSticker
  • getStickerSet
  • getCustomEmojiStickers
  • uploadStickerFile
  • createNewStickerSet
  • addStickerToSet
  • setStickerPositionInSet
  • deleteStickerFromSet
  • setStickerEmojiList
  • setStickerKeywords
  • setStickerMaskPosition
  • setStickerSetTitle
  • setStickerSetThumbnail
  • setCustomEmojiStickerSetThumbnail
  • deleteStickerSet

Forum Management

  • getForumTopicIconStickers
  • createForumTopic
  • editForumTopic
  • closeForumTopic
  • reopenForumTopic
  • deleteForumTopic
  • unpinAllForumTopicMessages
  • editGeneralForumTopic
  • closeGeneralForumTopic
  • reopenGeneralForumTopic
  • hideGeneralForumTopic
  • unhideGeneralForumTopic
  • unpinAllGeneralForumTopicMessages

File Management

  • getUserProfilePhotos
  • getFile

Game Management

  • sendGame
  • setGameScore
  • getGameHighScores

Payement Management

  • sendInvoice
  • createInvoiceLink
  • answerShippingQuery
  • answerPreCheckoutQuery

Chat Management

  • banChatMember
  • unbanChatMember
  • restrictChatMember
  • promoteChatMember
  • setChatAdministratorCustomTitle
  • banChatSenderChat
  • unbanChatSenderChat
  • setChatPermissions
  • exportChatInviteLink
  • createChatInviteLink
  • editChatInviteLink
  • revokeChatInviteLink
  • approveChatJoinRequest
  • declineChatJoinRequest
  • setChatPhoto
  • deleteChatPhoto
  • setChatTitle
  • setChatDescription
  • pinChatMessage
  • unpinChatMessage
  • unpinAllChatMessages
  • leaveChat
  • getChat
  • getChatAdministrators
  • getChatMemberCount
  • getChatMember
  • setChatStickerSet
  • deleteChatStickerSet
  • setChatMenuButton
  • getChatMenuButton
  • getUserChatBoosts

Message Management

  • reply
  • replyWithHtml
  • replyWithMarkdown
  • replyWithPhoto
  • replyWithChatAction
  • replyWithEditedMessage
  • sendMessage
  • forwardMessage
  • forwardMessages
  • copyMessage
  • copyMessages
  • sendPhoto
  • sendAudio
  • sendDocument
  • sendVideo
  • sendAnimation
  • sendVoice
  • sendVideoNote
  • sendMediaGroup
  • sendLocation
  • sendVenue
  • sendContact
  • sendPoll
  • stopPoll
  • sendDice
  • sendChatAction
  • setMessageReaction
  • deleteMessage
  • deleteMessages
  • editMessageText
  • editMessageCaption
  • editMessageMedia
  • editMessageReplyMarkup
  • stopMessageLiveLocation
  • editMessageLiveLocation

Sheet Management

  • appendRow
  • clear
  • clearByRange
  • clearValue
  • findOne
  • findAll
  • deleteColumn
  • deleteColumns
  • deleteRow
  • deleteRows
  • getSheetData
  • getLastColumn
  • getLastRow
  • insertColumnAfter
  • insertColumnBefore
  • insertColumns
  • insertColumnsAfter
  • insertColumnsBefore
  • insertRowAfter
  • insertRowBefore
  • insertRows
  • insertRowsAfter
  • insertRowsBefore
  • moveColumns
  • moveRows
  • setName
  • sortByColumn
  • saveOne
  • saveMany
  • getValue
  • getValues

Temporary Session Management

  • getTSession
  • getTSessionValue
  • setTSessionValue
  • setTSessionValues
  • removeTSessionValue
  • deleteTSession

Permanent Session Management

  • getPSession
  • getPSessionValue
  • setPSessionValue
  • setPSessionValues
  • removePSessionValue
  • deletePSession

Cache Management (Permanent and Temporary)

  • getPCacheValue
  • getPCache
  • setPCacheValue
  • setPCacheValues
  • removePCacheValue
  • deletePCache
  • getTCacheValue
  • setTCacheValue
  • getTCacheValues
  • setTCacheValues
  • removeTCacheValue
  • removeTCacheValues

Note

This list provides a quick overview of the available methods within the Context Object for interacting with various aspects of the bot framework and Telegram API. For detailed usage, parameters, and examples, refer to the specific method documentation within the bot framework's documentation resources.

Clone this wiki locally