Skip to content

Commit

Permalink
Update EchoBot example
Browse files Browse the repository at this point in the history
Fix compile issue #4
  • Loading branch information
baderouaich authored Mar 24, 2024
1 parent 431376e commit 5703eb0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/EchoBot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ using namespace tgbotxx;

class EchoBot : public Bot {
public:
EchoBot() : Bot("BOT_TOKEN_FROM_BOT_FATHER") { }
EchoBot(const std::string& token) : Bot(token) { }

private:
/// Called before Bot starts receiving updates (triggered by Bot::start())
/// Use this callback to initialize your code, set commands..
void onStart() override {
// Drop awaiting updates (when Bot is not running, updates will remain 24 hours
// in Telegram server before they get deleted or retrieved by BOT)
getApi()->deleteWebhook(true);
std::cout << "Bot " << getApi()->getMe()->firstName << " started\n";
api()->deleteWebhook(true);
std::cout << "Bot " << api()->getMe()->firstName << " started\n";
}

/// Called when Bot is about to be stopped (triggered by Bot::stop())
void onStop() override {
/// Cleanup your code in this callback (close handles, backup data...)
std::cout << "Bot " << getApi()->getMe()->firstName << " stopped\n";
std::cout << "Bot " << api()->getMe()->firstName << " stopped\n";
}

/// Called when a new message is received of any kind - text, photo, sticker, etc.
void onAnyMessage(const Ptr<Message>& message) override {
std::cout << "Received " << message->text << " from " << message->from->username << std::endl;
getApi()->sendMessage(message->chat->id, message->text); // Echo back message
api()->sendMessage(message->chat->id, message->text); // Echo back message
}

/// ============ [OPTIONAL OVERLOAD] =============
Expand Down

0 comments on commit 5703eb0

Please sign in to comment.