I'm trying to create my own Telegram bot as a project and don't want to use any of the libraries already out there that already do all the hard work for me as I want to do this for myself as on going self learning.
I'm using CPPRESTSDK and trying to get values from the JSON back from telegram.
Here is an example of the JSON
{
"ok": true,
"result": [
{
"update_id": 534699960,
"message": {
"message_id": 159183,
"from": {
"id": HIDDEN,
"is_bot": false,
"first_name": "Hawke",
"username": "XXXXXXXX"
},
"chat": {
"id": HIDDEN,
"title": "CHANNEL_NAME_HIDDEN",
"username": "HIDDEN",
"type": "supergroup"
},
"date": 1548427328,
"text": "Nope, at work"
}
}
]
}
I'm trying to read the text value but I'm getting Keyname not found when trying to access result. The above JSON is stored into a file once retrieving the JSON from telegram.
try {
string_t importFile = U("json.txt");
ifstream_t f(importFile);
stringstream_t s;
json::value v;
if (f) {
s << f.rdbuf();
f.close();
v = json::value::parse(s);
auto results_array = v.at(U("result")).as_array();
}
}
catch (web::json::json_exception& excep) {
std::cout << excep.what();
}