added logging Telegram bot

main
Michael Mandl 2018-03-30 20:26:34 +02:00
parent bd4cbb6872
commit 9fa3f1cc27
5 changed files with 27 additions and 2 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tgbot"]
path = tgbot
url = git@github.com:mandlm/telegram-bot-api

View File

@ -1,6 +1,8 @@
#include "settings.h" #include "settings.h"
#include "tgbot/bot.h"
#include <iostream> #include <iostream>
#include <sstream>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -15,6 +17,25 @@ int main(int argc, char **argv)
std::cout << user << " "; std::cout << user << " ";
} }
std::cout << std::endl; std::cout << std::endl;
tgbot::LongPollBot bot(settings.token);
bot.callback([] (const tgbot::types::Message message, const tgbot::methods::Api &api)
{
if (message.text != nullptr && message.from != nullptr)
{
std::ostringstream logMessage;
logMessage << message.from->firstName;
if (message.from->username != nullptr)
{
logMessage << " (" << *message.from->username << ")";
}
logMessage << ": " << *message.text;
api.getLogger().info(logMessage.str());
}
});
bot.start();
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {

View File

@ -12,6 +12,7 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE PRIVATE
Boost::program_options Boost::program_options
tgbot
) )
target_compile_features(${PROJECT_NAME} target_compile_features(${PROJECT_NAME}

View File

@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(Beezle) add_subdirectory(tgbot)
add_subdirectory(BeezleBot) add_subdirectory(BeezleBot)

1
tgbot Submodule

@ -0,0 +1 @@
Subproject commit b51e3aeb9c59a62ae620e7d2b7e856edef1db5b1