forked from MCMrARM/updateprocessor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegram.cpp
25 lines (22 loc) · 887 Bytes
/
telegram.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "telegram.h"
using namespace playapi;
using namespace nlohmann;
nlohmann::json telegram::Api::sendRequest(playapi::http_method method, std::string const& path,
std::string const& body) {
playapi::http_request req (url + path);
req.set_method(method);
req.set_body(body);
req.add_header("Content-Type", "application/json");
auto resp = req.perform();
if (!resp)
throw std::runtime_error("Failed to perform http request");
return json::parse(resp.get_body());
}
void telegram::Api::sendMessage(std::string const& chatId, std::string const& text, const std::string& parseMode) {
json data;
data["chat_id"] = chatId;
data["text"] = text;
if (!parseMode.empty())
data["parse_mode"] = parseMode;
sendRequest(playapi::http_method::POST, "bot" + token + "/sendMessage", data);
}