Telegram bot
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 

37 satır
1.0 KiB

#include <stdio.h>
#include <iostream>
#include <tgbot/tgbot.h>
#include <string>
#include <vector>
#include <boost/algorithm/string/classification.hpp> // Include boost::for is_any_of
#include <boost/algorithm/string/split.hpp> // Include for boost::split
#define OWNER 129755859
int main() {
std::string token(getenv("TOKEN"));
TgBot::Bot bot(token);
bot.getEvents().onCommand("start", [&bot](TgBot::Message::Ptr message) {
bot.getApi().sendMessage(message->chat->id, "Hi!");
});
bot.getEvents().onAnyMessage([&bot](TgBot::Message::Ptr message)
{
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;
}