Telegram bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <tgbot/tgbot.h>
  4. #include <string>
  5. #include <vector>
  6. #include <boost/algorithm/string/classification.hpp> // Include boost::for is_any_of
  7. #include <boost/algorithm/string/split.hpp> // Include for boost::split
  8. #define OWNER 129755859
  9. int main() {
  10. std::string token(getenv("TOKEN"));
  11. TgBot::Bot bot(token);
  12. bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) {
  13. bot.getApi().sendMessage(message->chat->id, "Hi!");
  14. });
  15. bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message)
  16. {
  17. bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text);
  18. });
  19. try {
  20. printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str());
  21. TgBot::TgLongPoll longPoll(bot);
  22. while (true) {
  23. printf("Long poll started\n");
  24. longPoll.start();
  25. }
  26. } catch (TgBot::TgException& e) {
  27. printf("error: %s\n", e.what());
  28. }
  29. return 0;
  30. }