reo7sp / tgbot-cpp

C++ library for Telegram bot API

Home Page:http://reo7sp.github.io/tgbot-cpp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callbacks not registered OR longpool doesn't work

asprs opened this issue · comments

commented

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

#include <stdio.h>
#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;
    }
};

}

commented

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