reo7sp / tgbot-cpp

C++ library for Telegram bot API
http://reo7sp.github.io/tgbot-cpp
MIT License
1.01k stars 245 forks source link

Callbacks not registered OR longpool doesn't work #283

Open asprs opened 1 year ago

asprs commented 1 year ago

Guys, I'm stuck. I don't receive any message. Why? Please help.

include

include <tgbot/tgbot.h>

include "config.h"

include "logger.h"

namespace broker { class telegram_bot { public: TgBot::Bot bot;

    telegram_bot() : bot(config::telegram_bot.token)
{
    bot.getEvents().onAnyMessage(std::bind(&telegram_bot::on_start, this, std::placeholders::_1));
        new std::thread(&telegram_bot::work, this);
    }

    void work()
    {
        try
        {
            TgBot::TgLongPoll longPoll(bot);

            while (true)
            {
                LOG_INFO << "[telegram_bot] " << " Long pool started";
                longPoll.start();
            }

            LOG_INFO << "[telegram_bot] " << " Exit"; 
    }
        catch (const std::exception &e)
        {
            LOG_ERROR << "[telegram_bot] " << " error: " << e.what();
        }
    }

    void on_start(const TgBot::Message::Ptr message)
    {
        cout << "work" << endl;
    }
};

}

asprs commented 1 year ago

going deeper into investigation I've created simple bot form main example and found that

TgBot::Bot bot(,,,);
bot.getApi().deleteWebhook();

just hangs w/o any exception or return