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