Cppgram  1.0.0
Easy and modern C++14 Telegram Bot API wrapper
Public Member Functions | Public Attributes | List of all members
BasicBot< T > Class Template Reference

contains api methods, update handlers and listener. More...

#include <basic_bot.hpp>

Public Member Functions

 BasicBot (const std::string &token, std::string name="Bot", T *obj_ptr=nullptr)
 Constuctor. More...
 
 BasicBot (const BasicBot &b, T *base_ptr)
 Copy constructor. More...
 
void setChatId (uint_fast32_t chat_id)
 Set the chat id of the bot. More...
 
void setChatId (int_fast64_t chat_id)
 Set the chat id of the bot. More...
 
CommandHandler< T > & commands ()
 Get command handler object. More...
 
Keyboardkeyboard ()
 Get the keyboard handler. More...
 
std::shared_ptr< spdlog::logger > logger ()
 Returns current bot's logger. More...
 
std::shared_ptr< spdlog::logger > setLogger (spdlog::sink_ptr sink)
 Set the bot's logger by passing a sink. More...
 
std::shared_ptr< spdlog::logger > setLogger (std::vector< spdlog::sink_ptr > &sinks)
 Set the bot's logger by passing a vector of sinks. More...
 
void setLogger (std::shared_ptr< spdlog::logger > new_logger)
 Set the bot's logger by passing a logger. More...
 
virtual void init ()
 Init bot object.
 
const cpr::Response executeRequest (const std::string &method, const cpr::Parameters &params)
 Execute an API method by passing method name and parameters. More...
 
bool getUpdates (std::vector< types::Update > &updates, const uint_fast32_t offset=0, const uint_fast32_t limit=100, const uint_fast32_t timeout=60)
 Receive incoming updates using polling (short or long polling based on timeout) More...
 
std::experimental::optional< const class types::MessagesendMessage (const int_fast64_t chat_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=EParseMode::HTML, const bool disable_web_page_preview=true, const bool disable_notification=false, const int_fast32_t reply_to_message_id=0)
 Send a message to a specified chat. (https://core.telegram.org/bots/api#sendmessage) More...
 
std::experimental::optional< const class types::MessagesendMessage (const std::string &chat_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=EParseMode::HTML, const bool disable_web_page_preview=true, const bool disable_notification=false, const int_fast32_t reply_to_message_id=0)
 Send a message to a specified chat. (https://core.telegram.org/bots/api#sendmessage) More...
 
std::experimental::optional< const class types::MessagesendMessage (const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=EParseMode::HTML, const bool disable_web_page_preview=true, const bool disable_notification=false, const int_fast32_t reply_to_message_id=0)
 Send a message to a specified chat. More...
 
bool answerCallbackQuery (const std::string &text, bool show_alert=false, uint32_t cache_time=0, const std::string &url="")
 Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. More...
 
std::experimental::optional< const class types::MessageeditMessageText (const int_fast64_t chat_id, const uint_fast32_t message_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=static_cast< EParseMode >(1), const bool disable_web_page_preview=true)
 Edit text (and reply markup) of a message sent by the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageText (const std::string &chat_id, const uint_fast32_t message_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=static_cast< EParseMode >(1), const bool disable_web_page_preview=true)
 Edit text (and reply markup) of a message sent by the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageText (const uint_fast32_t message_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=static_cast< EParseMode >(1), const bool disable_web_page_preview=true)
 Edit text (and reply markup) of a message sent by the bot. More...
 
bool editMessageText (const std::string &inline_message_id, const std::string &text, const std::string &reply_markup="", const EParseMode parse_mode=static_cast< EParseMode >(1), const bool disable_web_page_preview=true)
 Edit text (and reply markup) of a message sent via the bot (using inline queries). More...
 
std::experimental::optional< const class types::MessageeditMessageCaption (const int_fast64_t chat_id, const uint_fast32_t message_id, const std::string &caption="", const std::string &reply_markup="")
 Edit captions of messages sent by the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageCaption (const std::string &chat_id, const uint_fast32_t message_id, const std::string &caption="", const std::string &reply_markup="")
 Edit captions of messages sent by the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageCaption (const uint_fast32_t message_id, const std::string &caption="", const std::string &reply_markup="")
 Edit captions of messages sent by the bot. More...
 
bool editMessageCaption (const std::string &inline_message_id, const std::string &caption, const std::string &reply_markup="")
 Edit captions of messages sent via the bot (using inline_queries). More...
 
std::experimental::optional< const class types::MessageeditMessageReplyMarkup (const int_fast64_t chat_id, const uint_fast32_t message_id, const std::string &reply_markup="")
 Edit only the reply markup of a message sent by the the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageReplyMarkup (const std::string &chat_id, const uint_fast32_t message_id, const std::string &reply_markup="")
 Edit only the reply markup of a message sent by the the bot. More...
 
std::experimental::optional< const class types::MessageeditMessageReplyMarkup (const uint_fast32_t message_id, const std::string &reply_markup="")
 Edit only the reply markup of a message sent by the the bot. More...
 
bool editMessageReplyMarkup (const std::string &inline_message_id, const std::string &reply_markup="")
 
bool answerInlineQuery (const Json::Value &results, const uint_fast16_t cache_time=300, const bool is_personal=false, const std::string &next_offset="", const std::string &switch_pm_text="", const std::string &switch_pm_paramter="")
 Answer an inline query. (https://core.telegram.org/bots/api#answerinlinequery) More...
 

Public Attributes

std::function< void(T &, const types::Message &)> processMessage = nullptr
 Pointer to the function that will be called on each message sent by the user.
 
void(* processEditedMessage )(T &, const types::Message &) = nullptr
 Pointer to the function that will be called on each edited message by the user.
 
void(* processChannelPost )(T &, const types::Message &) = nullptr
 Pointer to the function that will be called on each message received in a channel.
 
void(* processEditedChannelPost )(T &, const types::Message &) = nullptr
 Pointer to the function that will be called on each message modified in a channel.
 
void(* processInlineQuery )(T &, const types::InlineQuery &) = nullptr
 Pointer to the function that will be called on each inline query.
 
void(* processChosenInlineResult )(T &, const types::ChosenInlineResult &) = nullptr
 Pointer to the function that will be called on each inline query choosed by the user.
 
void(* processCallbackQuery )(T &, const types::CallbackQuery &) = nullptr
 Pointer to the funciton that will be called on each callback query.
 

Detailed Description

template<class T>
class cppgram::BasicBot< T >

contains api methods, update handlers and listener.

The basic bot that contains all basic features.

Constructor & Destructor Documentation

◆ BasicBot() [1/2]

BasicBot ( const std::string &  token,
std::string  name = "Bot",
T *  obj_ptr = nullptr 
)

Constuctor.

Parameters
tokenBot token. Get a token from BotFather.
bot_nameName of the bot (for logging purposes).
obj_ptrPointer to this object. Cannot use "this" keyboard in costructor as this is not the final object. Pointer to the derived class that is calling this parent constructor.

◆ BasicBot() [2/2]

BasicBot ( const BasicBot< T > &  b,
T *  base_ptr 
)

Copy constructor.

Parameters
bBot to copy.

Member Function Documentation

◆ commands()

CommandHandler<T>& commands ( )
inline

Get command handler object.

Returns
Reference to the object.

◆ executeRequest()

const cpr::Response executeRequest ( const std::string &  method,
const cpr::Parameters &  params 
)

Execute an API method by passing method name and parameters.

A curl call will be made using cpr::Session of the bot and url generated from API token.

Parameters
methodMethod name.
paramsParameters to pass along with the request.
Returns
The server response.

◆ keyboard()

Keyboard& keyboard ( )
inline

Get the keyboard handler.

Returns
Reference to the object.

◆ logger()

std::shared_ptr<spdlog::logger> logger ( )
inline

Returns current bot's logger.

Returns
Pointer to the bot's logger.

◆ setChatId() [1/2]

void setChatId ( uint_fast32_t  chat_id)
inline

Set the chat id of the bot.

Parameters
chat_idNew chat_id to set.

◆ setChatId() [2/2]

void setChatId ( int_fast64_t  chat_id)
inline

Set the chat id of the bot.

See also
setChatId

◆ setLogger() [1/3]

std::shared_ptr< spdlog::logger > setLogger ( spdlog::sink_ptr  sink)

Set the bot's logger by passing a sink.

Logger will be automaticcaly created using the sink passed.

Parameters
sinkSink of the log to create.
Returns
The logger created.

◆ setLogger() [2/3]

std::shared_ptr< spdlog::logger > setLogger ( std::vector< spdlog::sink_ptr > &  sinks)
inline

Set the bot's logger by passing a vector of sinks.

Logger will be automaticcaly created using the sinks passed.

Parameters
sinksSink of the log to create.
Returns
The logger created.

◆ setLogger() [3/3]

void setLogger ( std::shared_ptr< spdlog::logger >  new_logger)

Set the bot's logger by passing a logger.

Parameters
loggerNew logger to set.

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