added logging Telegram bot
This commit is contained in:
parent
bd4cbb6872
commit
9fa3f1cc27
5 changed files with 27 additions and 2 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "tgbot"]
|
||||
path = tgbot
|
||||
url = git@github.com:mandlm/telegram-bot-api
|
|
@ -1,6 +1,8 @@
|
|||
#include "settings.h"
|
||||
#include "tgbot/bot.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -15,6 +17,25 @@ int main(int argc, char **argv)
|
|||
std::cout << user << " ";
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ add_executable(${PROJECT_NAME}
|
|||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
Boost::program_options
|
||||
tgbot
|
||||
)
|
||||
|
||||
target_compile_features(${PROJECT_NAME}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(Beezle)
|
||||
|
||||
add_subdirectory(tgbot)
|
||||
add_subdirectory(BeezleBot)
|
||||
|
|
1
tgbot
Submodule
1
tgbot
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b51e3aeb9c59a62ae620e7d2b7e856edef1db5b1
|
Loading…
Reference in a new issue