tgbot-cpp
Loading...
Searching...
No Matches
TgBot::TgLongPoll Class Reference

This class handles long polling and updates parsing. More...

#include <TgLongPoll.h>

Public Types

using ErrorHandler = std::function<void(const std::exception&)>

Public Member Functions

 TgLongPoll (const Api *api, const EventHandler *eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr< std::vector< std::string > > allowUpdates)
 TgLongPoll (const Bot &bot, std::int32_t limit=100, std::int32_t timeout=10, const std::shared_ptr< std::vector< std::string > > &allowUpdates=nullptr)
void start ()
 Performs one long-polling iteration and dispatches received updates. Parses received updates and passes them to EventHandler, which invokes the registered listeners.
void startLoop (const ErrorHandler &errorHandler={ }, std::initializer_list< int > signals={ SIGINT, SIGTERM })
 Polls for updates until stop() is called, one of the configured signals is received, or an unhandled error occurs.
void stop ()
 Requests cancellation of the active HTTP request and stops startLoop().
bool isRunning () const
 Returns true while startLoop() is active.

Detailed Description

This class handles long polling and updates parsing.

Definition at line 27 of file TgLongPoll.h.

Member Typedef Documentation

◆ ErrorHandler

using TgBot::TgLongPoll::ErrorHandler = std::function<void(const std::exception&)>

Definition at line 29 of file TgLongPoll.h.

Constructor & Destructor Documentation

◆ TgLongPoll() [1/2]

TgBot::TgLongPoll::TgLongPoll ( const Api * api,
const EventHandler * eventHandler,
std::int32_t limit,
std::int32_t timeout,
std::shared_ptr< std::vector< std::string > > allowUpdates )

◆ TgLongPoll() [2/2]

TgBot::TgLongPoll::TgLongPoll ( const Bot & bot,
std::int32_t limit = 100,
std::int32_t timeout = 10,
const std::shared_ptr< std::vector< std::string > > & allowUpdates = nullptr )

Member Function Documentation

◆ isRunning()

bool TgBot::TgLongPoll::isRunning ( ) const
inline

Returns true while startLoop() is active.

Definition at line 59 of file TgLongPoll.h.

◆ start()

void TgBot::TgLongPoll::start ( )

Performs one long-polling iteration and dispatches received updates. Parses received updates and passes them to EventHandler, which invokes the registered listeners.

◆ startLoop()

void TgBot::TgLongPoll::startLoop ( const ErrorHandler & errorHandler = { },
std::initializer_list< int > signals = { SIGINT, SIGTERM } )

Polls for updates until stop() is called, one of the configured signals is received, or an unhandled error occurs.

Parameters
errorHandlerCalled when a polling iteration fails. The loop continues after the handler returns. If no handler is provided, the exception is propagated.
signalsProcess signals that stop the loop. Pass an empty list to disable signal handling.

◆ stop()

void TgBot::TgLongPoll::stop ( )

Requests cancellation of the active HTTP request and stops startLoop().


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