tgbotxx 1.2.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
tgbotxx::Bot Class Reference

#include <Bot.hpp>

Inheritance diagram for tgbotxx::Bot:
PaidSubscriptionBot

Public Member Functions

 Bot (const std::string &token)
 Constructs a new Bot object.
 
virtual ~Bot ()
 
void start ()
 Start the long polling.
 
void stop ()
 Stop the long polling.
 
virtual void onStart ()
 Bot Callbacks.
 
virtual void onStop ()
 Called when Bot is about to be stopped (triggered by Bot::stop()) Cleanup your code in this callback (close handles, backup data...)
 
virtual void onAnyMessage (const Ptr< Message > &message)
 Called when a new message is received of any kind - text, photo, sticker, etc.
 
virtual void onNonCommandMessage (const Ptr< Message > &message)
 Called when a non-command message is received of any kind - text, photo, sticker, etc.
 
virtual void onCommand (const Ptr< Message > &command)
 Called when a new command is received (messages with leading '/' char).
 
virtual void onUnknownCommand (const Ptr< Message > &message)
 Called when an unknown command is received (messages with leading '/' char).
 
virtual void onMessageEdited (const Ptr< Message > &editedMessage)
 Called when a new version of a message that is known to the bot and was edited.
 
virtual void onChannelPost (const Ptr< Message > &channelPost)
 Called when a new incoming channel post of any kind (text, photo, sticker, etc.) is received.
 
virtual void onChannelPostEdited (const Ptr< Message > &editedChannelPost)
 Called when a new version of a channel post that is known to the bot and was edited.
 
virtual void onBusinessConnection (const Ptr< BusinessConnection > &businessConnection)
 Called when the bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.
 
virtual void onBusinessMessage (const Ptr< Message > &businessMessage)
 Called when a new message from a connected business account is received.
 
virtual void onBusinessMessageEdited (const Ptr< Message > &editedBusinessMessage)
 Called when a new version of a message from a connected business account is received.
 
virtual void onBusinessMessagesDeleted (const Ptr< BusinessMessagesDeleted > &deletedBusinessMessages)
 Called when Messages were deleted from a connected business account.
 
virtual void onMessageReactionUpdated (const Ptr< MessageReactionUpdated > &messageReaction)
 Called when a reaction to a message was changed by a user.
 
virtual void onMessageReactionCountUpdated (const Ptr< MessageReactionCountUpdated > &messageReactionCount)
 Called when reactions to a message with anonymous reactions were changed.
 
virtual void onInlineQuery (const Ptr< InlineQuery > &inlineQuery)
 Called when a new incoming inline query is received.
 
virtual void onChosenInlineResult (const Ptr< ChosenInlineResult > &chosenInlineResult)
 Called when the result of an inline query that was chosen by a user and sent to their chat partner.
 
virtual void onCallbackQuery (const Ptr< CallbackQuery > &callbackQuery)
 Called when a new incoming callback query is received.
 
virtual void onShippingQuery (const Ptr< ShippingQuery > &shippingQuery)
 Called when a new incoming shipping query is received.
 
virtual void onPreCheckoutQuery (const Ptr< PreCheckoutQuery > &preCheckoutQuery)
 Called when a new incoming pre-checkout query is received. Contains full information about checkout.
 
virtual void onPaidMediaPurchased (const Ptr< PaidMediaPurchased > &purchasedPaidMedia)
 Called when a user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.
 
virtual void onPoll (const Ptr< Poll > &poll)
 Called when a new poll state is received.
 
virtual void onPollAnswer (const Ptr< PollAnswer > &pollAnswer)
 Called when a user changed their answer in a non-anonymous poll.
 
virtual void onMyChatMemberUpdated (const Ptr< ChatMemberUpdated > &myChatMember)
 Called when the bot's chat member status was updated in a chat.
 
virtual void onChatMemberUpdated (const Ptr< ChatMemberUpdated > &chatMember)
 Called when a chat member's status was updated in a chat.
 
virtual void onChatJoinRequest (const Ptr< ChatJoinRequest > &chatJoinRequest)
 Called when a request to join the chat has been sent.
 
virtual void onChatBoostUpdated (const Ptr< ChatBoostUpdated > &chatBoost)
 Called when a chat boost was added or changed.
 
virtual void onChatBoostRemoved (const Ptr< ChatBoostRemoved > &removedChatBoost)
 Called when a boost was removed from a chat.
 
virtual void onLongPollError (const std::string &errorMessage, ErrorCode errorCode)
 Called when the long polling getUpdates fails.
 

Protected Member Functions

const Ptr< Api > & getApi () const noexcept
 Returns Api object.
 
const Ptr< Api > & api () const noexcept
 Returns Api object.
 
bool isRunning () const noexcept
 Returns true if the Bot long polling is currently running.
 

Detailed Description

Definition at line 30 of file Bot.hpp.

Constructor & Destructor Documentation

◆ Bot()

tgbotxx::Bot::Bot ( const std::string &  token)
explicit

Constructs a new Bot object.

Parameters
tokenBot token from the BotFather

◆ ~Bot()

virtual tgbotxx::Bot::~Bot ( )
virtual

Member Function Documentation

◆ api()

const Ptr< Api > & tgbotxx::Bot::api ( ) const
protectednoexcept

Returns Api object.

◆ getApi()

const Ptr< Api > & tgbotxx::Bot::getApi ( ) const
protectednoexcept

Returns Api object.

Getters

◆ isRunning()

bool tgbotxx::Bot::isRunning ( ) const
protectednoexcept

Returns true if the Bot long polling is currently running.

◆ onAnyMessage()

virtual void tgbotxx::Bot::onAnyMessage ( const Ptr< Message > &  message)
inlinevirtual

Called when a new message is received of any kind - text, photo, sticker, etc.

Parameters
messageReceived message object

Definition at line 63 of file Bot.hpp.

◆ onBusinessConnection()

virtual void tgbotxx::Bot::onBusinessConnection ( const Ptr< BusinessConnection > &  businessConnection)
inlinevirtual

Called when the bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.

Parameters
businessConnectionBusinessConnection object

Definition at line 97 of file Bot.hpp.

◆ onBusinessMessage()

virtual void tgbotxx::Bot::onBusinessMessage ( const Ptr< Message > &  businessMessage)
inlinevirtual

Called when a new message from a connected business account is received.

Parameters
businessMessageMessage object

Definition at line 101 of file Bot.hpp.

◆ onBusinessMessageEdited()

virtual void tgbotxx::Bot::onBusinessMessageEdited ( const Ptr< Message > &  editedBusinessMessage)
inlinevirtual

Called when a new version of a message from a connected business account is received.

Parameters
editedBusinessMessageMessage object

Definition at line 105 of file Bot.hpp.

◆ onBusinessMessagesDeleted()

virtual void tgbotxx::Bot::onBusinessMessagesDeleted ( const Ptr< BusinessMessagesDeleted > &  deletedBusinessMessages)
inlinevirtual

Called when Messages were deleted from a connected business account.

Parameters
deletedBusinessMessagesBusinessMessagesDeleted object

Definition at line 109 of file Bot.hpp.

◆ onCallbackQuery()

virtual void tgbotxx::Bot::onCallbackQuery ( const Ptr< CallbackQuery > &  callbackQuery)
inlinevirtual

Called when a new incoming callback query is received.

Parameters
callbackQueryCallbackQuery object

Definition at line 138 of file Bot.hpp.

◆ onChannelPost()

virtual void tgbotxx::Bot::onChannelPost ( const Ptr< Message > &  channelPost)
inlinevirtual

Called when a new incoming channel post of any kind (text, photo, sticker, etc.) is received.

Parameters
channelPostMessage object

Definition at line 86 of file Bot.hpp.

◆ onChannelPostEdited()

virtual void tgbotxx::Bot::onChannelPostEdited ( const Ptr< Message > &  editedChannelPost)
inlinevirtual

Called when a new version of a channel post that is known to the bot and was edited.

Parameters
editedChannelPostMessage object

Definition at line 90 of file Bot.hpp.

◆ onChatBoostRemoved()

virtual void tgbotxx::Bot::onChatBoostRemoved ( const Ptr< ChatBoostRemoved > &  removedChatBoost)
inlinevirtual

Called when a boost was removed from a chat.

Parameters
removedChatBoostChatBoostRemoved object

Definition at line 190 of file Bot.hpp.

◆ onChatBoostUpdated()

virtual void tgbotxx::Bot::onChatBoostUpdated ( const Ptr< ChatBoostUpdated > &  chatBoost)
inlinevirtual

Called when a chat boost was added or changed.

Parameters
chatBoostChatBoostUpdated object

Definition at line 186 of file Bot.hpp.

◆ onChatJoinRequest()

virtual void tgbotxx::Bot::onChatJoinRequest ( const Ptr< ChatJoinRequest > &  chatJoinRequest)
inlinevirtual

Called when a request to join the chat has been sent.

Note
The bot must have the can_invite_users administrator right in the chat to receive these updates.
Parameters
chatJoinRequestChatJoinRequest object

Definition at line 182 of file Bot.hpp.

◆ onChatMemberUpdated()

virtual void tgbotxx::Bot::onChatMemberUpdated ( const Ptr< ChatMemberUpdated > &  chatMember)
inlinevirtual

Called when a chat member's status was updated in a chat.

Note
The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates.
Parameters
chatMemberChatMemberUpdated object

Definition at line 177 of file Bot.hpp.

◆ onChosenInlineResult()

virtual void tgbotxx::Bot::onChosenInlineResult ( const Ptr< ChosenInlineResult > &  chosenInlineResult)
inlinevirtual

Called when the result of an inline query that was chosen by a user and sent to their chat partner.

Note
Please see our documentation on the feedback collecting for details on how to enable these updates for your bot. https://core.telegram.org/bots/inline#collecting-feedback
Parameters
chosenInlineResultChosenInlineResult object

Definition at line 134 of file Bot.hpp.

◆ onCommand()

virtual void tgbotxx::Bot::onCommand ( const Ptr< Message > &  command)
inlinevirtual

Called when a new command is received (messages with leading '/' char).

Parameters
commandReceived command object

Definition at line 71 of file Bot.hpp.

◆ onInlineQuery()

virtual void tgbotxx::Bot::onInlineQuery ( const Ptr< InlineQuery > &  inlineQuery)
inlinevirtual

Called when a new incoming inline query is received.

Parameters
inlineQueryInlineQuery object

Definition at line 129 of file Bot.hpp.

◆ onLongPollError()

virtual void tgbotxx::Bot::onLongPollError ( const std::string &  errorMessage,
ErrorCode  errorCode 
)
inlinevirtual

Called when the long polling getUpdates fails.

Parameters
errorMessagethe reason of failure
errorCodeErrorCode enum from Telegram Api

Definition at line 197 of file Bot.hpp.

◆ onMessageEdited()

virtual void tgbotxx::Bot::onMessageEdited ( const Ptr< Message > &  editedMessage)
inlinevirtual

Called when a new version of a message that is known to the bot and was edited.

Parameters
editedMessageEdited Message object

Definition at line 80 of file Bot.hpp.

◆ onMessageReactionCountUpdated()

virtual void tgbotxx::Bot::onMessageReactionCountUpdated ( const Ptr< MessageReactionCountUpdated > &  messageReactionCount)
inlinevirtual

Called when reactions to a message with anonymous reactions were changed.

Note
The bot must be an administrator in the chat and must explicitly specify "message_reaction_count" in the list of allowed_updates to receive these updates using Api::setAllowedUpdates(). The updates are grouped and can be sent with delay up to a few minutes.
Parameters
messageReactionCountMessageReactionCountUpdated object

Definition at line 123 of file Bot.hpp.

◆ onMessageReactionUpdated()

virtual void tgbotxx::Bot::onMessageReactionUpdated ( const Ptr< MessageReactionUpdated > &  messageReaction)
inlinevirtual

Called when a reaction to a message was changed by a user.

Note
The bot must be an administrator in the chat and must explicitly specify "message_reaction" in the list of allowed_updates to receive these updates using Api::setAllowedUpdates(). The update isn't received for reactions set by bots.
Parameters
messageReactionMessageReactionUpdated object

Definition at line 117 of file Bot.hpp.

◆ onMyChatMemberUpdated()

virtual void tgbotxx::Bot::onMyChatMemberUpdated ( const Ptr< ChatMemberUpdated > &  myChatMember)
inlinevirtual

Called when the bot's chat member status was updated in a chat.

Note
For private chats, this update is received only when the bot is blocked or unblocked by the user.
Parameters
myChatMemberChatMemberUpdated object

Definition at line 172 of file Bot.hpp.

◆ onNonCommandMessage()

virtual void tgbotxx::Bot::onNonCommandMessage ( const Ptr< Message > &  message)
inlinevirtual

Called when a non-command message is received of any kind - text, photo, sticker, etc.

Parameters
messageReceived non-command message object

Definition at line 67 of file Bot.hpp.

◆ onPaidMediaPurchased()

virtual void tgbotxx::Bot::onPaidMediaPurchased ( const Ptr< PaidMediaPurchased > &  purchasedPaidMedia)
inlinevirtual

Called when a user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.

Parameters
purchasedPaidMediaPaidMediaPurchased object

Definition at line 153 of file Bot.hpp.

◆ onPoll()

virtual void tgbotxx::Bot::onPoll ( const Ptr< Poll > &  poll)
inlinevirtual

Called when a new poll state is received.

Note
Bots receive only updates about stopped polls and polls, which are sent by the bot
Parameters
pollPoll object

Definition at line 160 of file Bot.hpp.

◆ onPollAnswer()

virtual void tgbotxx::Bot::onPollAnswer ( const Ptr< PollAnswer > &  pollAnswer)
inlinevirtual

Called when a user changed their answer in a non-anonymous poll.

Note
Bots receive new votes only in polls that were sent by the bot itself.
Parameters
pollAnswerPollAnswer object

Definition at line 165 of file Bot.hpp.

◆ onPreCheckoutQuery()

virtual void tgbotxx::Bot::onPreCheckoutQuery ( const Ptr< PreCheckoutQuery > &  preCheckoutQuery)
inlinevirtual

Called when a new incoming pre-checkout query is received. Contains full information about checkout.

Parameters
preCheckoutQueryPreCheckoutQuery object

Definition at line 147 of file Bot.hpp.

◆ onShippingQuery()

virtual void tgbotxx::Bot::onShippingQuery ( const Ptr< ShippingQuery > &  shippingQuery)
inlinevirtual

Called when a new incoming shipping query is received.

Note
Only for invoices with flexible price
Parameters
shippingQueryShippingQuery object

Definition at line 143 of file Bot.hpp.

◆ onStart()

virtual void tgbotxx::Bot::onStart ( )
inlinevirtual

Bot Callbacks.

Called before Bot starts receiving updates (triggered by Bot::start()) Use this callback to initialize your code, set commands..

Definition at line 53 of file Bot.hpp.

◆ onStop()

virtual void tgbotxx::Bot::onStop ( )
inlinevirtual

Called when Bot is about to be stopped (triggered by Bot::stop()) Cleanup your code in this callback (close handles, backup data...)

Definition at line 57 of file Bot.hpp.

◆ onUnknownCommand()

virtual void tgbotxx::Bot::onUnknownCommand ( const Ptr< Message > &  message)
inlinevirtual

Called when an unknown command is received (messages with leading '/' char).

Parameters
messageReceived unknown command object
Note
Known commands are set with Bot::setCommands()

Definition at line 76 of file Bot.hpp.

◆ start()

void tgbotxx::Bot::start ( )

Start the long polling.

Exceptions
Exceptionon failure

◆ stop()

void tgbotxx::Bot::stop ( )

Stop the long polling.


The documentation for this class was generated from the following file: