tgbotxx  1.1.6.9
Telegram Bot C++ Library
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. More...
 
 ~Bot ()
 
void start ()
 Start the long polling. More...
 
void stop ()
 Stop the long polling. More...
 
virtual void onStart ()
 Called before Bot starts receiving updates (triggered by Bot::start()) Use this callback to initialize your code, set commands.. More...
 
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...) More...
 
virtual void onAnyMessage (const Ptr< Message > &message)
 Called when a new message is received of any kind - text, photo, sticker, etc. More...
 
virtual void onNonCommandMessage (const Ptr< Message > &message)
 Called when a non-command message is received of any kind - text, photo, sticker, etc. More...
 
virtual void onCommand (const Ptr< Message > &command)
 Called when a new command is received (messages with leading '/' char). More...
 
virtual void onUnknownCommand (const Ptr< Message > &message)
 Called when an unknown command is received (messages with leading '/' char). More...
 
virtual void onEditedMessage (const Ptr< Message > &editedMessage)
 Called when a new version of a message that is known to the bot and was edited. More...
 
virtual void onMessageReactionUpdated (const Ptr< MessageReactionUpdated > &messageReaction)
 Called when a reaction to a message was changed by a user. More...
 
virtual void onMessageReactionCountUpdated (const Ptr< MessageReactionCountUpdated > &messageReactionCount)
 Called when reactions to a message with anonymous reactions were changed. More...
 
virtual void onInlineQuery (const Ptr< InlineQuery > &inlineQuery)
 Called when a new incoming inline query is received. More...
 
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. More...
 
virtual void onCallbackQuery (const Ptr< CallbackQuery > &callbackQuery)
 Called when a new incoming callback query is received. More...
 
virtual void onShippingQuery (const Ptr< ShippingQuery > &shippingQuery)
 Called when a new incoming shipping query is received. More...
 
virtual void onPreCheckoutQuery (const Ptr< PreCheckoutQuery > &preCheckoutQuery)
 Called when a new incoming pre-checkout query is received. Contains full information about checkout. More...
 
virtual void onPoll (const Ptr< Poll > &poll)
 Called when a new poll state is received. More...
 
virtual void onPollAnswer (const Ptr< PollAnswer > &pollAnswer)
 Called when a user changed their answer in a non-anonymous poll. More...
 
virtual void onMyChatMember (const Ptr< ChatMemberUpdated > &myChatMemberUpdated)
 Called when the bot's chat member status was updated in a chat. More...
 
virtual void onChatMember (const Ptr< ChatMemberUpdated > &chatMemberUpdated)
 Called when a chat member's status was updated in a chat. More...
 
virtual void onChatJoinRequest (const Ptr< ChatJoinRequest > &chatJoinRequest)
 Called when a request to join the chat has been sent. More...
 
virtual void onChatBoostUpdated (const Ptr< ChatBoostUpdated > &chatBoostUpdated)
 Called when a chat boost was added or changed. More...
 
virtual void onChatBoostRemoved (const Ptr< ChatBoostRemoved > &chatBoostRemoved)
 Called when a boost was removed from a chat. More...
 
virtual void onLongPollError (const std::string &errorMessage, ErrorCode errorCode)
 Called when the long polling getUpdates fails. More...
 

Protected Member Functions

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

Detailed Description

Definition at line 27 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()

tgbotxx::Bot::~Bot ( )

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 58 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 100 of file Bot.hpp.

◆ onChatBoostRemoved()

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

Called when a boost was removed from a chat.

Parameters
chatBoostRemovedChatBoostRemoved object

Definition at line 142 of file Bot.hpp.

◆ onChatBoostUpdated()

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

Called when a chat boost was added or changed.

Parameters
chatBoostUpdatedChatBoostUpdated object

Definition at line 138 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 134 of file Bot.hpp.

◆ onChatMember()

virtual void tgbotxx::Bot::onChatMember ( const Ptr< ChatMemberUpdated > &  chatMemberUpdated)
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
chatMemberUpdatedChatMemberUpdated object

Definition at line 129 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 96 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 66 of file Bot.hpp.

◆ onEditedMessage()

virtual void tgbotxx::Bot::onEditedMessage ( 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 75 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 91 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 147 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 87 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 81 of file Bot.hpp.

◆ onMyChatMember()

virtual void tgbotxx::Bot::onMyChatMember ( const Ptr< ChatMemberUpdated > &  myChatMemberUpdated)
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
myChatMemberUpdatedChatMemberUpdated object

Definition at line 124 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 62 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 114 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 119 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 109 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 105 of file Bot.hpp.

◆ onStart()

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

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

Bot Callbacks

Definition at line 50 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 54 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 71 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: