|
|
@ -0,0 +1,36 @@ |
|
|
|
#include <stdio.h>
|
|
|
|
#include <tgbot/tgbot.h>
|
|
|
|
|
|
|
|
int main() { |
|
|
|
TgBot::Bot bot("436931164:AAG3LyZywIzODiMhXtBPzMI4U3BBEv4z4zA"); |
|
|
|
bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) { |
|
|
|
bot.getApi().sendMessage(message->chat->id, "Hi!"); |
|
|
|
}); |
|
|
|
|
|
|
|
bot.getEvents().onCommand("love", [&bot](TgBot::Message::Ptr message) { |
|
|
|
bot.getApi().sendMessage(message->chat->id, "I love you!"); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message) { |
|
|
|
printf("User wrote %s\n", message->text.c_str()); |
|
|
|
if (StringTools::startsWith(message->text, "/start")) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (StringTools::startsWith(message->text, "/love")) { |
|
|
|
return; |
|
|
|
} |
|
|
|
bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); |
|
|
|
}); |
|
|
|
try { |
|
|
|
printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); |
|
|
|
TgBot::TgLongPoll longPoll(bot); |
|
|
|
while (true) { |
|
|
|
printf("Long poll started\n"); |
|
|
|
longPoll.start(); |
|
|
|
} |
|
|
|
} catch (TgBot::TgException& e) { |
|
|
|
printf("error: %s\n", e.what()); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |