yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Contact_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/Contact.h"
8 
9 using namespace std;
10 
11 namespace yatbcpp {
12 
18  template<> Contact fromJson(Json::Value Data) {
19  if (!Data.isMember("phone_number")) {
20  throw essential_key_missing("Contact::file_id is missing");
21  }
22  if (!Data.isMember("first_name")) {
23  throw essential_key_missing("Contact::duration is missing");
24  }
25  std::string phone_number = Data["phone_number"].asString();
26  std::string first_name = Data["first_name"].asString();
27 
28  Contact ret(phone_number, first_name);
29 
30  if (Data.isMember("last_name")) {
31  ret.setLast_name(Data["last_name"].asString());
32  }
33  if (Data.isMember("user_id")) {
34  ret.setUser_id(Data["user_id"].asInt());
35  }
36  return ret;
37  }
38 
39 }
void setLast_name(const std::optional< std::string > &last_name)
Definition: Contact.cc:30
Contact fromJson(Json::Value Data)
void setUser_id(const std::optional< std::int32_t > &user_id)
Definition: Contact.cc:34
Definition: Bot.h:27