Closed micfan closed 5 years ago
void handler(Message::Ptr message) {
//do something
}
…
bot.getEvents().onCommand("start", &handler);
//or bot.getEvents().onCommand("start", handler);
Thanks,
the function void hander(Message::Ptr message)
, how to get access of bot
object?
Use 'global object', or use tricks.
Example)
TgBot::Bot bot(…)
void handler(TgBot::Message::Ptr message) { //do something }
…
bot.getEvents().onCommand("start", &handler); //or bot.getEvents().onCommand("start", handler);
2. Trick
void handler(TgBot::Message::Ptr message, TgBot::Bot& bot) { //do something } …
bot.getEvents().onCommand("start", [&bot] (TgBot::Message::Ptr message) { handler(message, bot); });
@JellyBrick Thank your kindly show case very much!
As in the demo, all the callback is lambda: https://github.com/reo7sp/tgbot-cpp/blob/master/samples/echobot-curl-client/src/main.cpp#L18
how to bind a function handler?