-
Notifications
You must be signed in to change notification settings - Fork 50
/
ClientMessages.php
530 lines (491 loc) · 17.6 KB
/
ClientMessages.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<?php
namespace Hu\MadelineProto;
use danog\MadelineProto\messages;
class ClientMessages
{
/**
* @var messages
*/
private $messages;
/**
* ClientMessage constructor.
*
* @param messages $messages
*/
public function __construct($messages)
{
$this->messages = $messages;
}
/**
* Use this to accept a Seamless Telegram Login authorization request.
*
* <br>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.acceptUrlAuth</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $messageId
* @param int $buttonId
* @param array $extra other optional parameter(s)
* @return TelegramObject UrlAuthResult
* @link https://core.telegram.org/api/url-authorization
*/
public function acceptUrlAuth($messageId, int $buttonId = 0, array $extra = []): TelegramObject
{
if ($messageId instanceof TelegramObject) {
$payload = $messageId->toArray();
} else {
$payload = [
'msg_id' => $messageId,
'button_id' => $buttonId
];
$payload = array_merge($payload, $extra);
}
return new TelegramObject($this->messages->acceptUrlAuth($payload));
}
/**
* Adds a user to a chat and sends a service message on it.
*
* <br>
*
* Note:
* <ol>
* <li>
* The chatId and userId argument can be an array which contains
* <strong>Update</strong> or <strong>Message</strong>
* </li>
* <li>
* The chatId and userId argument can be provided one of these values:
* <ul>
* <li>'@ username' (Username)</li>
* <li>'me' (the currently logged-in user)</li>
* <li>44700 (bot API id [user])</li>
* <li>-492772765 (bot API id [chats])</li>
* <li>-10038575794 (bot API id [channels])</li>
* <li>'https://t.me/danogentili' (t.me URLs)</li>
* <li>'https://t.me/joinchat/asfln1-21fa' (t.me invite links)</li>
* <li>'user#44700' (tg-cli style id [users])</li>
* <li>'chat#492772765' (tg-cli style id (chats))</li>
* <li>'channel#38575794' (tg-cli style id [channels])</li>
* </ul>
* </li>
* </ol>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.addChatUser</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $chatId
* @param mixed $userId
* @param int $forwardLimit
* @return TelegramObject Updates
*/
public function addChatUser($chatId, $userId = '', int $forwardLimit = 1): TelegramObject
{
if ($chatId instanceof TelegramObject) {
$payload = $chatId->toArray();
} else {
$payload = [
'chat_id' => $chatId,
'user_id' => $userId,
'fwd_limit' => $forwardLimit
];
}
return new TelegramObject($this->messages->addChatUser($payload));
}
/**
* Check the validity of a chat invite link and get basic info about it.
*
* <br>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.addChatUser</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $hash
* @return TelegramObject ChatInvite
*/
public function checkChatInvite($hash): TelegramObject
{
if ($hash instanceof TelegramObject) {
$payload = $hash->toArray();
} else {
$payload = [
'hash' => $hash
];
}
return new TelegramObject($this->messages->checkChatInvite($payload));
}
/**
* Clear all drafts.
*
* @return bool Bool
*/
public function clearAllDrafts(): bool
{
return $this->messages->clearAllDrafts();
}
/**
* Clear recent stickers.
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.clearRecentStickers</strong> method payload. It's fields will be sent as payload.
*
* @param bool|TelegramObject $attached
* @return bool Bool
*/
public function clearRecentStickers($attached = false): bool
{
if ($attached instanceof TelegramObject) {
$payload = $attached->toArray();
} else {
$payload = [
'attached' => $attached
];
}
return $this->messages->clearRecentStickers($payload);
}
/**
* Creates a new chat.
*
* <br>
*
* Note:
* <ol>
* <li>The users argument can be an array of array which contains <strong>Update</strong> or <strong>Message</strong></li>
* <li>
* The users argument can be provided one of these values:
* <ul>
* <li>'@ username' (Username)</li>
* <li>'me' (the currently logged-in user)</li>
* <li>44700 (bot API id [user])</li>
* <li>-492772765 (bot API id [chats])</li>
* <li>-10038575794 (bot API id [channels])</li>
* <li>'https://t.me/danogentili' (t.me URLs)</li>
* <li>'https://t.me/joinchat/asfln1-21fa' (t.me invite links)</li>
* <li>'user#44700' (tg-cli style id [users])</li>
* <li>'chat#492772765' (tg-cli style id (chats))</li>
* <li>'channel#38575794' (tg-cli style id [channels])</li>
* </ul>
* </li>
* </ol>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.createChat</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $title
* @param array $users
* @return TelegramObject Updates
*/
public function createChat($title, array $users = []): TelegramObject
{
if ($title instanceof TelegramObject) {
$payload = $title->toArray();
} else {
$payload = [
'title' => $title,
'users' => $users
];
}
return new TelegramObject($this->messages->createChat($payload));
}
/**
* Deletes a user from a chat and sends a service message on it.
*
* <br>
*
* Note:
* <ol>
* <li>The chatId and userId arguments can be an array which contains <strong>Update</strong> or <strong>Message</strong></li>
* <li>
* The chatId and userId arguments can be provided one of these values:
* <ul>
* <li>'@ username' (Username)</li>
* <li>'me' (the currently logged-in user)</li>
* <li>44700 (bot API id [user])</li>
* <li>-492772765 (bot API id [chats])</li>
* <li>-10038575794 (bot API id [channels])</li>
* <li>'https://t.me/danogentili' (t.me URLs)</li>
* <li>'https://t.me/joinchat/asfln1-21fa' (t.me invite links)</li>
* <li>'user#44700' (tg-cli style id [users])</li>
* <li>'chat#492772765' (tg-cli style id (chats))</li>
* <li>'channel#38575794' (tg-cli style id [channels])</li>
* </ul>
* </li>
* </ol>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.deleteChatUser</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $chatId
* @param mixed $userId
* @return TelegramObject Updates
*/
public function deleteChatUser($chatId, $userId): TelegramObject
{
if ($chatId instanceof TelegramObject) {
$payload = $chatId->toArray();
} else {
$payload = [
'chat_id' => $chatId,
'user_id' => $userId
];
}
return new TelegramObject($this->messages->deleteChatUser($payload));
}
/**
* Deletes communication history.
*
* <br>
*
* Note:
* <ol>
* <li>The peer argument can be an array which contains <strong>Update</strong> or <strong>Message</strong></li>
* <li>
* The peer argument can be provided one of these values:
* <ul>
* <li>'@ username' (Username)</li>
* <li>'me' (the currently logged-in user)</li>
* <li>44700 (bot API id [user])</li>
* <li>-492772765 (bot API id [chats])</li>
* <li>-10038575794 (bot API id [channels])</li>
* <li>'https://t.me/danogentili' (t.me URLs)</li>
* <li>'https://t.me/joinchat/asfln1-21fa' (t.me invite links)</li>
* <li>'user#44700' (tg-cli style id [users])</li>
* <li>'chat#492772765' (tg-cli style id (chats))</li>
* <li>'channel#38575794' (tg-cli style id [channels])</li>
* </ul>
* </li>
* </ol>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.deleteHistory</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $peer
* @param int $maxId
* @param array $extra other optional parameter(s)
* @return TelegramObject messages.AffectedMessages
*/
public function deleteHistory($peer, int $maxId = 0, array $extra = []): TelegramObject
{
if ($peer instanceof TelegramObject) {
$payload = $peer->toArray();
} else {
$payload = [
'peer' => $peer,
'max_id' => $maxId,
];
$payload = array_merge($payload, $extra);
}
return new TelegramObject($this->messages->deleteHistory($payload));
}
/**
* Deletes messages by their identifiers.
*
* <br>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.deleteMessages</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $id
* @param bool $revoke
* @return TelegramObject messages.AffectedMessages
*/
public function deleteMessages($id, bool $revoke = false): TelegramObject
{
if ($id instanceof TelegramObject) {
$payload = $id->toArray();
} else {
$payload = [
'id' => $id,
'revoke' => $revoke
];
}
return new TelegramObject($this->messages->deleteMessages($payload));
}
/**
* Delete scheduled messages.
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.deleteScheduledMessages</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $peer
* @param array $id
* @return TelegramObject Updates
*/
public function deleteScheduledMessages($peer, array $id = []): TelegramObject
{
if ($peer instanceof TelegramObject) {
$payload = $peer->toArray();
} else {
$payload = [
'peer' => $peer,
'id' => $id
];
}
return new TelegramObject($this->messages->deleteScheduledMessages($payload));
}
/**
* Edit the description of a group/supergroup/channel.
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.editChatAbout</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $peer
* @param string $about
* @return TelegramObject
*/
public function editChatAbout($peer, string $about = ''): TelegramObject
{
if ($peer instanceof TelegramObject) {
$payload = $peer->toArray();
} else {
$payload = [
'peer' => $peer,
'about' => $about
];
}
return new TelegramObject($this->messages->editChatAbout($payload));
}
/**
* Make a user admin in a legacy group.
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.editChatAdmin</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $chatId
* @param mixed $userId
* @param bool $isAdmin
* @return bool Bool
*/
public function editChatAdmin($chatId, $userId, bool $isAdmin): bool
{
if ($chatId instanceof TelegramObject) {
$payload = $chatId->toArray();
} else {
$payload = [
'chat_id' => $chatId,
'user_id' => $userId,
'is_admin' => $isAdmin
];
}
return $this->messages->editChatAdmin($payload);
}
/**
* Edit the default banned rights of a channel/supergroup/group.
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.editChatDefaultBannedRights</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $peer
* @param array $bannedRights
* @return TelegramObject Updates
*/
public function editChatDefaultBannedRights($peer, array $bannedRights): TelegramObject
{
if ($peer instanceof TelegramObject) {
$payload = $peer->toArray();
} else {
$payload = [
'peer' => $peer,
'banned_rights' => $bannedRights
];
}
return new TelegramObject($this->messages->editChatDefaultBannedRights($payload));
}
/**
* Send a message to target peer.
*
* <br>
*
* Note:
* <ol>
* <li>The peer argument can be an array which contains <strong>Update</strong> or <strong>Message</strong></li>
* <li>
* The peer argument can be provided one of these values:
* <ul>
* <li>'@ username' (Username)</li>
* <li>'me' (the currently logged-in user)</li>
* <li>44700 (bot API id [user])</li>
* <li>-492772765 (bot API id [chats])</li>
* <li>-10038575794 (bot API id [channels])</li>
* <li>'https://t.me/danogentili' (t.me URLs)</li>
* <li>'https://t.me/joinchat/asfln1-21fa' (t.me invite links)</li>
* <li>'user#44700' (tg-cli style id [users])</li>
* <li>'chat#492772765' (tg-cli style id (chats))</li>
* <li>'channel#38575794' (tg-cli style id [channels])</li>
* </ul>
* </li>
* </ol>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.sendMessage</strong> method payload. It's fields will be sent as payload.
*
* @param mixed $peer
* @param string $message
* @param array $extra other optional parameter(s)
* @return TelegramObject Updates
*/
public function sendMessage($peer, string $message = '', array $extra = []): TelegramObject
{
if ($peer instanceof TelegramObject) {
$payload = $peer->toArray();
} else {
$payload = [
'peer' => $peer,
'message' => $message
];
$payload = array_merge($payload, $extra);
}
return new TelegramObject($this->messages->sendMessage($payload));
}
/**
* Get dialog info of specified peers.
*
* <br>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.getPeerDialog</strong> method payload. It's fields will be sent as payload.
*
* @param array ...$peers
* @return TelegramObject
*/
public function getPeerDialogs(...$peers): TelegramObject
{
if ($peers[0] instanceof TelegramObject) {
$payload = $peers[0]->toArray();
} else {
$payload = [
'peers' => $peers
];
}
return new TelegramObject($this->messages->getPeerDialogs($payload));
}
/**
* Gets back the conversation history with one interlocutor / within a chat.
*
* <br>
*
* For convenience, you may pass a {@link \Hu\MadelineProto\TelegramObject TelegramObject} to the first argument which contains
* <strong>messages.getHistory</strong> method payload. It's fields will be sent as payload.
*
* @param array|TelegramObject $params
* @return TelegramObject
*/
public function getHistory($params): TelegramObject
{
if ($params instanceof TelegramObject) {
$payload = $params->toArray();
} else {
$payload = $params;
}
return new TelegramObject($this->messages->getHistory($payload));
}
/**
* Get Client messages instance.
*
* @return messages messages APIFactory.
*/
public function getMessages(): messages
{
return $this->messages;
}
}