yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
Update_fromJson.cc
Go to the documentation of this file.
1 // From JSON Specialication //
4 #include <jsoncpp/json/json.h>
5 #include "types/telegram_type.h"
7 #include "types/Update.h"
8 
9 using namespace std;
10 
11 namespace yatbcpp {
17  template<> Update fromJson(Json::Value Data) {
18  //Checking for essential fields
19  if (!Data.isMember("update_id")) {
20  throw essential_key_missing("Update::update_id is missing");
21  }
22  //Extracting the essential information
23  std::int32_t update_id = Data["update_id"].asInt();
24  //Creating the for return created object
25  Update ret(update_id);
26  //Adding Optional/Additional Information
27  if (Data.isMember("message")) {
28  Message M = fromJson<Message>(Data["message"]);
29  ret.setMessage(M);
30  }
31  if (Data.isMember("edited_message")) {
32  Message M = fromJson<Message>(Data["edited_message"]);
33  ret.setEdited_message(M);
34  }
35  if (Data.isMember("channel_post")) {
36  Message M = fromJson<Message>(Data["channel_post"]);
37  ret.setChannel_post(M);
38  }
39  if (Data.isMember("edited_channel_post")) {
40  Message M = fromJson<Message>(Data["edited_channel_post"]);
42  }
43  if (Data.isMember("inline_query")) {
44  InlineQuery I= fromJson<InlineQuery>(Data["inline_query"]);
45  ret.setInlineQuery(I);
46  }
47 
48 
49  return ret;
50  }
51 }
void setMessage(const std::optional< Message > &message)
Definition: Update.cc:32
void setEdited_message(const std::optional< Message > &edited_message)
Definition: Update.cc:36
Definition: Bot.h:27
void setEdited_channel_post(const std::optional< Message > &edited_channel_post)
Definition: Update.cc:44
void setChannel_post(const std::optional< Message > &channel_post)
Definition: Update.cc:40
void setInlineQuery(const std::optional< InlineQuery > &inlineQuery)
Definition: Update.cc:48
Update fromJson(Json::Value Data)