1#ifndef TGBOT_TGHTTPSERVER_H
2#define TGBOT_TGHTTPSERVER_H
10#include <unordered_map>
15template<
typename Protocol>
21 TgWebhookServer(
const typename boost::asio::basic_socket_acceptor<Protocol>::endpoint_type& endpoint, std::string path,
const EventHandler& eventHandler)
23 [this](const std::string& _1, const std::unordered_map<std::string, std::string>& _2) {
return _handle(_1, _2); }),
24 _path(std::move(path)), _eventHandler(eventHandler), _tgTypeParser()
28 TgWebhookServer(
const typename boost::asio::basic_socket_acceptor<Protocol>::endpoint_type& endpoint,
const Bot& bot)
29 :
TgWebhookServer(endpoint,
"/" + bot.getToken(), bot.getEventHandler())
34 std::string _handle(
const std::string& data,
const std::unordered_map<std::string, std::string>& headers) {
35 if (headers.at(
"_method") ==
"POST" && headers.at(
"_path") == _path) {
36 _eventHandler.
handleUpdate(_tgTypeParser.parseJsonAndGetUpdate(_tgTypeParser.parseJson(data)));
41 const std::string _path;
42 const EventHandler& _eventHandler;
43 const TgTypeParser _tgTypeParser;
This object holds other objects specific for this bot instance.
void handleUpdate(const Update::Ptr &update) const
std::string generateResponse(const std::string &data, const std::string &mimeType, unsigned short statusCode, const std::string &statusStr, bool isKeepAlive) const
This class handles HTTP requests from the Internet.
std::function< std::string(const std::string &, const std::unordered_map< std::string, std::string > &)> ServerHandler
const HttpParser _httpParser
TgWebhookServer(const typename boost::asio::basic_socket_acceptor< Protocol >::endpoint_type &endpoint, const Bot &bot)
TgWebhookServer(const typename boost::asio::basic_socket_acceptor< Protocol >::endpoint_type &endpoint, std::string path, const EventHandler &eventHandler)
TgWebhookServer(const typename boost::asio::basic_socket_acceptor< Protocol >::endpoint_type &endpoint, const typename HttpServer< Protocol >::ServerHandler &handler)=delete