LibTgBotPP
 All Classes Namespaces Files Functions Variables Typedefs Macros
Message.cc
Go to the documentation of this file.
1 #include "Telegram/Message.h"
2 
3 // Generic constructor
4 // @TODO: Make this an "init"-Method and call it from the constructor
6 
7  this->init();
8 }
9 
10 Telegram::Message::Message(Json::Value json) {
11 
12  if (json["message"].isNull()) {
13  this->init();
14  return;
15  }
16 
17  this->init(json);
18 }
19 
20 Telegram::Message::Message(std::string message) {
21 
22  Json::Value json;
23  Json::Reader reader;
24 
25  reader.parse(message, json);
26 
27  this->init(json);
28 }
29 
31 
32  this->message_id = 0;
33  this->from = NULL;
34  this->date = 0;
35  this->chat = NULL;
36  this->forward_from = NULL;
37  this->forward_date = 0;
38  this->reply_to_message = NULL;
39  this->text = "";
40  this->entities.clear();
41  this->audio = NULL;
42  this->document = NULL;
43  this->photo.clear();
44  this->sticker = NULL;
45  this->video = NULL;
46  this->voice = NULL;
47  this->caption = "";
48  this->contact = NULL;
49  this->location = NULL;
50  this->venue = NULL;
51  this->new_chat_member = NULL;
52  this->left_chat_member = NULL;
53  this->new_chat_title = "";
54  this->new_chat_photo.clear();
55  this->delete_chat_photo = 0;
56  this->group_chat_created = 0;
57  this->supergroup_chat_created = 0;
58  this->migrate_to_chat_id = 0;
59  this->pinned_message = NULL;
60 }
61 
62 void Telegram::Message::init(Json::Value json) {
63 
64  Json::Value msg = json["message"];
65 
66  this->message_id = msg["message_id"].asUInt64();
67  this->from = new Telegram::User(msg["from"]);
68  this->date = msg["date"].asUInt64();
69  this->chat = new Telegram::Chat(msg["chat"]);
70  this->forward_from = new Telegram::User(msg["forward_from"]);
71  this->forward_date = msg["forward_date"].asUInt64();
72  this->reply_to_message = new Telegram::Message(msg["reply_to_message"]);
73  this->text = msg["text"].asString();
74  this->setEntities(msg["entities"]);
75  this->audio = new Audio(msg["audio"]);
76  this->document = new Document(msg["document"]);
77  this->photo = this->setPhotos(msg["photo"]);
78  this->sticker = new Sticker(msg["sticker"]);
79  this->video = new Video(msg["video"]);
80  this->voice = new Voice(msg["voice"]);
81  this->caption = msg["caption"].asString();
82  this->contact = new Contact(msg["contact"]);
83  this->location = new Location(msg["location"]);
84  this->venue = new Venue(msg["venue"]);
85  this->new_chat_member = new User(msg["new_chat_member"]);
86  this->left_chat_member = new User(msg["left_chat_member"]);
87  this->new_chat_title = msg["new_chat_title"].asString();
88  this->new_chat_photo = this->setPhotos(msg["new_chat_photo"]);
89  this->delete_chat_photo = msg["delete_chat_photo"].asInt64();
90  this->group_chat_created = msg["group_chat_created"].asInt64();
91  this->supergroup_chat_created = msg["supergroup_chat_created"].asInt64();
92  this->migrate_to_chat_id = msg["migrate_to_chat_id"].asUInt64();
93  this->migrate_from_chat_id = msg["migrate_from_chat_id"].asUInt64();
94  this->pinned_message = new Message(msg["pinned_message"]);
95 }
96 
97 // Setter
98 void Telegram::Message::setEntities(Json::Value entities) {
99 
100  Json::ArrayIndex size = entities.size();
101  for(Json::ArrayIndex i = 0; i < size; i++) {
102  Telegram::MessageEntity *entity = new Telegram::MessageEntity(entities[i]);
103  this->entities.push_back(entity);
104  }
105 }
106 
107 std::vector<Telegram::PhotoSize*> Telegram::Message::setPhotos(Json::Value photos) {
108 
109  Json::ArrayIndex size = photos.size();
110  std::vector<PhotoSize*> vPhotos;
111 
112  for(Json::ArrayIndex i = 0; i < size; i++) {
113  Telegram::PhotoSize *photo_size = new Telegram::PhotoSize(photos[i]);
114  vPhotos.push_back(photo_size);
115  }
116 
117  return(vPhotos);
118 }
119 
120 // Getter
122 
123  return(this->chat);
124 }
125 
127 
128  return(this->text);
129 }
130 
132 
133  return(this->entities);
134 }
void setEntities(Json::Value)
Definition: Message.cc:98
void init(void)
Definition: Message.cc:30
Telegram::Chat * getChat()
Definition: Message.cc:121
Telegram::TMessageEntities getEntities()
Definition: Message.cc:131
std::vector< PhotoSize * > setPhotos(Json::Value)
Definition: Message.cc:107
std::vector< Telegram::MessageEntity * > TMessageEntities
Definition: MessageEntity.h:23
std::string getText()
Definition: Message.cc:126