diff options
Diffstat (limited to 'samples/photo')
-rw-r--r-- | samples/photo/CMakeLists.txt | 14 | ||||
-rw-r--r-- | samples/photo/Dockerfile | 8 | ||||
-rw-r--r-- | samples/photo/example.jpg | bin | 0 -> 16770 bytes | |||
-rw-r--r-- | samples/photo/src/main.cpp | 45 |
4 files changed, 67 insertions, 0 deletions
diff --git a/samples/photo/CMakeLists.txt b/samples/photo/CMakeLists.txt new file mode 100644 index 0000000..d431b88 --- /dev/null +++ b/samples/photo/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.4) +project(photo) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") +set(Boost_USE_MULTITHREADED ON) + +find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(Boost COMPONENTS system iostreams REQUIRED) +include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) + +add_executable(photo src/main.cpp) + +target_link_libraries(photo /usr/local/lib/libTgBot.a ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES}) diff --git a/samples/photo/Dockerfile b/samples/photo/Dockerfile new file mode 100644 index 0000000..2bdbe1f --- /dev/null +++ b/samples/photo/Dockerfile @@ -0,0 +1,8 @@ +FROM reo7sp/tgbot-cpp +MAINTAINER Oleg Morozenkov <a@reo7sp.ru> + +WORKDIR /tmp/photo +COPY . . +RUN cmake . +RUN make -j4 +CMD ./photo diff --git a/samples/photo/example.jpg b/samples/photo/example.jpg Binary files differnew file mode 100644 index 0000000..cbfd0d5 --- /dev/null +++ b/samples/photo/example.jpg diff --git a/samples/photo/src/main.cpp b/samples/photo/src/main.cpp new file mode 100644 index 0000000..1b81f27 --- /dev/null +++ b/samples/photo/src/main.cpp @@ -0,0 +1,45 @@ +// +// Created by Oleg Morozenkov on 25.01.17. +// + +#include <signal.h> +#include <stdio.h> +#include <exception> + +#include <tgbot/tgbot.h> + +using namespace std; +using namespace TgBot; + +bool sigintGot = false; + +int main() { + const string photoFilePath = "example.jpg"; + const string photoMimeType = "image/jpeg"; + + Bot bot("PLACE YOUR TOKEN HERE"); + bot.getEvents().onCommand("start", [&bot](Message::Ptr message) { + bot.getApi().sendMessage(message->chat->id, "Hi!"); + }); + bot.getEvents().onCommand("photo", [&bot, &photoFilePath, &photoMimeType](Message::Ptr message) { + bot.getApi().sendPhoto(message->chat->id, InputFile::fromFile(photoFilePath, photoMimeType)); + }); + + signal(SIGINT, [](int s) { + printf("SIGINT got"); + sigintGot = true; + }); + try { + printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); + + TgLongPoll longPoll(bot); + while (!sigintGot) { + printf("Long poll started\n"); + longPoll.start(); + } + } catch (exception& e) { + printf("error: %s\n", e.what()); + } + + return 0; +} |