1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace unreal4u\TelegramAPI\Telegram\Types; |
6
|
|
|
|
7
|
|
|
use unreal4u\TelegramAPI\Abstracts\TelegramTypes; |
8
|
|
|
use unreal4u\TelegramAPI\Telegram\Types\Custom\PhotoSizeArray; |
9
|
|
|
use unreal4u\TelegramAPI\Telegram\Types\Custom\MessageEntityArray; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This object represents a message. |
13
|
|
|
* |
14
|
|
|
* Objects defined as-is december 2015 |
15
|
|
|
* |
16
|
|
|
* @see https://core.telegram.org/bots/api#message |
17
|
|
|
*/ |
18
|
|
|
class Message extends TelegramTypes |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Unique message identifier |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
public $message_id = 0; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Optional. Sender, can be empty for messages sent to channels |
28
|
|
|
* @var User |
29
|
|
|
*/ |
30
|
|
|
public $from = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Date the message was sent in Unix time |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
public $date = 0; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Conversation the message belongs to |
40
|
|
|
* @var Chat |
41
|
|
|
*/ |
42
|
|
|
public $chat = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Optional. For forwarded messages, sender of the original message |
46
|
|
|
* @var User |
47
|
|
|
*/ |
48
|
|
|
public $forward_from = null; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Optional. For messages forwarded from a channel, information about the original channel |
52
|
|
|
* @var Chat |
53
|
|
|
*/ |
54
|
|
|
public $forward_from_chat = null; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Optional. For forwarded messages, date the original message was sent in Unix time |
58
|
|
|
* @var int |
59
|
|
|
*/ |
60
|
|
|
public $forward_date = 0; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Optional. For replies, the original message. Note that the Message object in this field will not contain further |
64
|
|
|
* reply_to_message fields even if it itself is a reply. |
65
|
|
|
* @var Message |
66
|
|
|
*/ |
67
|
|
|
public $reply_to_message = null; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Optional. Date the message was last edited in Unix time |
71
|
|
|
* @var int |
72
|
|
|
*/ |
73
|
|
|
public $edit_date = 0; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
public $text = ''; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
public $entities = []; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Optional. Message is an audio file, information about the file |
89
|
|
|
* @var Audio |
90
|
|
|
*/ |
91
|
|
|
public $audio = null; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Optional. Message is a general file, information about the file |
95
|
|
|
* @var Document |
96
|
|
|
*/ |
97
|
|
|
public $document = null; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Optional. Message is a photo, available sizes of the photo |
101
|
|
|
* @var array |
102
|
|
|
*/ |
103
|
|
|
public $photo = []; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Optional. Message is a sticker, information about the sticker |
107
|
|
|
* @var Sticker |
108
|
|
|
*/ |
109
|
|
|
public $sticker = null; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Optional. Message is a video, information about the video |
113
|
|
|
* @var Video |
114
|
|
|
*/ |
115
|
|
|
public $video = null; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Optional. Message is a voice message, information about the file |
119
|
|
|
* @var Voice |
120
|
|
|
*/ |
121
|
|
|
public $voice = null; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Optional. Caption for the photo or video |
125
|
|
|
* @var string |
126
|
|
|
*/ |
127
|
|
|
public $caption = ''; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Optional. Message is a shared contact, information about the contact |
131
|
|
|
* @var Contact |
132
|
|
|
*/ |
133
|
|
|
public $contact = null; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Optional. Message is a shared location, information about the location |
137
|
|
|
* @var Location |
138
|
|
|
*/ |
139
|
|
|
public $location = null; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Optional. Message is a venue, information about the venue |
143
|
|
|
* @var Venue |
144
|
|
|
*/ |
145
|
|
|
public $venue = null; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Optional. A new member was added to the group, information about them (this member may be the bot itself) |
149
|
|
|
* @var User |
150
|
|
|
*/ |
151
|
|
|
public $new_chat_participant = null; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Optional. A member was removed from the group, information about them (this member may be the bot itself) |
155
|
|
|
* @var User |
156
|
|
|
*/ |
157
|
|
|
public $left_chat_participant = null; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Optional. A chat title was changed to this value |
161
|
|
|
* @var string |
162
|
|
|
*/ |
163
|
|
|
public $new_chat_title = ''; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Optional. A chat photo was change to this value |
167
|
|
|
* @var array |
168
|
|
|
*/ |
169
|
|
|
public $new_chat_photo = []; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Optional. Service message: the chat photo was deleted |
173
|
|
|
* @var bool |
174
|
|
|
*/ |
175
|
|
|
public $delete_chat_photo = false; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Optional. Service message: the group has been created |
179
|
|
|
* @var bool |
180
|
|
|
*/ |
181
|
|
|
public $group_chat_created = false; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Optional. Service message: the supergroup has been created. This field can‘t be received in a message coming |
185
|
|
|
* through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in |
186
|
|
|
* reply_to_message if someone replies to a very first message in a directly created supergroup |
187
|
|
|
* @var bool |
188
|
|
|
*/ |
189
|
|
|
public $supergroup_chat_created = false; |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Optional. Service message: the channel has been created. This field can‘t be received in a message coming through |
193
|
|
|
* updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message |
194
|
|
|
* if someone replies to a very first message in a channel |
195
|
|
|
* @var bool |
196
|
|
|
*/ |
197
|
|
|
public $channel_chat_created = false; |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater |
201
|
|
|
* than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller |
202
|
|
|
* than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier |
203
|
|
|
* @var int |
204
|
|
|
*/ |
205
|
|
|
public $migrate_to_chat_id = 0; |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater |
209
|
|
|
* than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller |
210
|
|
|
* than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier |
211
|
|
|
* @var int |
212
|
|
|
*/ |
213
|
|
|
public $migrate_from_chat_id = 0; |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Optional. Specified message was pinned. Note that the Message object in this field will not contain further |
217
|
|
|
* reply_to_message fields even if it is itself a reply. |
218
|
|
|
* @var Message |
219
|
|
|
*/ |
220
|
|
|
public $pinned_message = null; |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* A message may contain one or more subobjects, map them always in this function |
224
|
|
|
* |
225
|
|
|
* @return TelegramTypes |
226
|
|
|
*/ |
227
|
9 |
|
protected function mapSubObjects(string $key, array $data): TelegramTypes |
228
|
|
|
{ |
229
|
|
|
switch ($key) { |
230
|
9 |
|
case 'from': |
231
|
9 |
|
case 'forward_from': |
232
|
9 |
|
case 'new_chat_participant': |
233
|
9 |
|
case 'left_chat_participant': |
234
|
9 |
|
return new User($data, $this->logger); |
235
|
9 |
|
case 'photo': |
236
|
9 |
|
case 'new_chat_photo': |
237
|
1 |
|
return new PhotoSizeArray($data, $this->logger); |
238
|
9 |
|
case 'chat': |
239
|
5 |
|
case 'forward_from_chat': |
240
|
9 |
|
return new Chat($data, $this->logger); |
241
|
5 |
|
case 'reply_to_message': |
242
|
5 |
|
case 'pinned_message': |
243
|
|
|
return new Message($data, $this->logger); |
244
|
5 |
|
case 'entities': |
245
|
|
|
return new MessageEntityArray($data, $this->logger); |
246
|
5 |
|
case 'audio': |
247
|
1 |
|
return new Audio($data, $this->logger); |
248
|
4 |
|
case 'document': |
249
|
1 |
|
return new Document($data, $this->logger); |
250
|
3 |
|
case 'sticker': |
251
|
1 |
|
return new Sticker($data, $this->logger); |
252
|
2 |
|
case 'video': |
253
|
1 |
|
return new Video($data, $this->logger); |
254
|
1 |
|
case 'voice': |
255
|
|
|
return new Voice($data, $this->logger); |
256
|
1 |
|
case 'contact': |
257
|
|
|
return new Contact($data, $this->logger); |
258
|
1 |
|
case 'location': |
259
|
1 |
|
return new Location($data, $this->logger); |
260
|
|
|
case 'venue': |
261
|
|
|
return new Venue($data, $this->logger); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// Return always null if none of the objects above matches |
265
|
|
|
return parent::mapSubObjects($key, $data); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|