1 #ifndef CPPGRAM_BASIC_BOT_HPP 2 #define CPPGRAM_BASIC_BOT_HPP 7 #include <spdlog/spdlog.h> 9 #include "command_handler.hpp" 10 #include "exception.hpp" 11 #include "keyboard.hpp" 12 #include "types/update.hpp" 201 template <
typename V>
friend class Polling;
213 BasicBot(
const std::string &token, std::string name =
"Bot", T *obj_ptr =
nullptr );
234 inline void setChatId( uint_fast32_t chat_id ) { this->chat_id = chat_id; }
240 inline void setChatId( int_fast64_t chat_id ) { this->chat_id = chat_id; }
258 inline std::shared_ptr<spdlog::logger>
logger() {
return logger_ptr; }
266 std::shared_ptr<spdlog::logger>
setLogger( spdlog::sink_ptr sink );
275 inline std::shared_ptr<spdlog::logger>
setLogger( std::vector<spdlog::sink_ptr> &sinks );
281 void setLogger( std::shared_ptr<spdlog::logger> new_logger );
296 const cpr::Response
executeRequest(
const std::string &method,
const cpr::Parameters ¶ms );
305 bool checkMethodError(
const cpr::Response &response, Json::Value &val );
328 bool getUpdates( std::vector<types::Update> &updates,
329 const uint_fast32_t offset = 0,
330 const uint_fast32_t limit = 100,
331 const uint_fast32_t timeout = 60 );
348 std::experimental::optional<const class types::Message>
350 const std::string &text,
351 const std::string &reply_markup =
"",
353 const bool disable_web_page_preview =
true,
354 const bool disable_notification =
false,
355 const int_fast32_t reply_to_message_id = 0 );
362 std::experimental::optional<const class types::Message>
364 const std::string &text,
365 const std::string &reply_markup =
"",
367 const bool disable_web_page_preview =
true,
368 const bool disable_notification =
false,
369 const int_fast32_t reply_to_message_id = 0 );
378 std::experimental::optional<const class types::Message>
380 const std::string &reply_markup =
"",
382 const bool disable_web_page_preview =
true,
383 const bool disable_notification =
false,
384 const int_fast32_t reply_to_message_id = 0 );
402 bool show_alert =
false,
403 uint32_t cache_time = 0,
404 const std::string &
url =
"" );
419 std::experimental::optional<const class types::Message>
421 const uint_fast32_t message_id,
422 const std::string & text,
423 const std::string & reply_markup =
"",
424 const EParseMode parse_mode = static_cast<EParseMode>( 1 ),
425 const bool disable_web_page_preview =
true );
433 std::experimental::optional<const class types::Message>
435 const uint_fast32_t message_id,
436 const std::string & text,
437 const std::string & reply_markup =
"",
438 const EParseMode parse_mode = static_cast<EParseMode>( 1 ),
439 const bool disable_web_page_preview =
true );
447 std::experimental::optional<const class types::Message>
449 const std::string & text,
450 const std::string & reply_markup =
"",
451 const EParseMode parse_mode = static_cast<EParseMode>( 1 ),
452 const bool disable_web_page_preview =
true );
467 const std::string &text,
468 const std::string &reply_markup =
"",
469 const EParseMode parse_mode = static_cast<EParseMode>( 1 ),
470 const bool disable_web_page_preview =
true );
481 std::experimental::optional<const class types::Message>
483 const uint_fast32_t message_id,
484 const std::string & caption =
"",
485 const std::string & reply_markup =
"" );
493 std::experimental::optional<const class types::Message>
495 const uint_fast32_t message_id,
496 const std::string & caption =
"",
497 const std::string & reply_markup =
"" );
504 std::experimental::optional<const class types::Message>
506 const std::string & caption =
"",
507 const std::string & reply_markup =
"" );
519 const std::string &caption,
520 const std::string &reply_markup =
"" );
531 std::experimental::optional<const class types::Message>
533 const uint_fast32_t message_id,
534 const std::string & reply_markup =
"" );
543 std::experimental::optional<const class types::Message>
545 const uint_fast32_t message_id,
546 const std::string & reply_markup =
"" );
554 std::experimental::optional<const class types::Message>
566 const std::string &reply_markup =
"" );
589 const uint_fast16_t cache_time = 300,
590 const bool is_personal =
false,
591 const std::string & next_offset =
"",
592 const std::string & switch_pm_text =
"",
593 const std::string & switch_pm_paramter =
"" );
646 void processUpdate(
const types::Update &update );
649 int_fast64_t chat_id;
652 std::string callback_query_id;
655 std::string inline_query_id;
661 cpr::Session connection;
664 std::shared_ptr<spdlog::logger> logger_ptr;
680 #include "basic_bot_impl.hpp" void(* processInlineQuery)(T &, const types::InlineQuery &)
Pointer to the function that will be called on each inline query.
Definition: basic_bot.hpp:626
void(* processEditedMessage)(T &, const types::Message &)
Pointer to the function that will be called on each edited message by the user.
Definition: basic_bot.hpp:611
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)
Definition: basic_bot_impl.hpp:151
An helper class to create inline keyboard.
Definition: keyboard.hpp:33
A message send by user.
Definition: message.hpp:36
BasicBot(const std::string &token, std::string name="Bot", T *obj_ptr=nullptr)
Constuctor.
std::shared_ptr< spdlog::logger > setLogger(spdlog::sink_ptr sink)
Set the bot's logger by passing a sink.
Definition: basic_bot_impl.hpp:64
Data from an inline keyboard button pressed.
Definition: callback_query.hpp:21
Handle bot commands.
Definition: command_handler.hpp:26
void(* processEditedChannelPost)(T &, const types::Message &)
Pointer to the function that will be called on each message modified in a channel.
Definition: basic_bot.hpp:621
std::function< void(T &, const types::Message &)> processMessage
Pointer to the function that will be called on each message sent by the user.
Definition: basic_bot.hpp:606
virtual void init()
Init bot object.
Definition: basic_bot_impl.hpp:107
CommandHandler< T > & commands()
Get command handler object.
Definition: basic_bot.hpp:246
const cpr::Response executeRequest(const std::string &method, const cpr::Parameters ¶ms)
Execute an API method by passing method name and parameters.
Definition: basic_bot_impl.hpp:114
Incoming inline query.
Definition: inline_query.hpp:22
void setChatId(int_fast64_t chat_id)
Set the chat id of the bot.
Definition: basic_bot.hpp:240
std::experimental::optional< const class types::Message > editMessageCaption(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.
std::experimental::optional< const class types::Message > editMessageText(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.
void(* processCallbackQuery)(T &, const types::CallbackQuery &)
Pointer to the funciton that will be called on each callback query.
Definition: basic_bot.hpp:636
contains api methods, update handlers and listener.
Definition: basic_bot.hpp:199
EParseMode
Formattation options.
Definition: enums.hpp:66
Abstract class for bot commands.
Definition: command_handler.hpp:15
Keyboard & keyboard()
Get the keyboard handler.
Definition: basic_bot.hpp:252
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)
Definition: basic_bot_impl.hpp:511
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 di...
Definition: basic_bot_impl.hpp:265
std::experimental::optional< const class types::Message > editMessageReplyMarkup(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.
std::experimental::optional< const class types::Message > sendMessage(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) ...
main namespace for Cppgram
void(* processChannelPost)(T &, const types::Message &)
Pointer to the function that will be called on each message received in a channel.
Definition: basic_bot.hpp:616
Handle long (or short) polling for a bot.
Definition: polling.hpp:12
void setChatId(uint_fast32_t chat_id)
Set the chat id of the bot.
Definition: basic_bot.hpp:234
A inline query choosed by the user.
Definition: chosen_inline_result.hpp:22
std::shared_ptr< spdlog::logger > logger()
Returns current bot's logger.
Definition: basic_bot.hpp:258
void(* processChosenInlineResult)(T &, const types::ChosenInlineResult &)
Pointer to the function that will be called on each inline query choosed by the user.
Definition: basic_bot.hpp:631