-
-
Notifications
You must be signed in to change notification settings - Fork 963
/
Copy pathUpdate.php
89 lines (83 loc) · 3.32 KB
/
Update.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
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* Class Update
*
* @link https://core.telegram.org/bots/api#update
*
* @method int getUpdateId() The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
* @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc.
* @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited
* @method Message getChannelPost() Optional. New post in the channel, can be any kind — text, photo, sticker, etc.
* @method Message getEditedChannelPost() Optional. New version of a post in the channel that is known to the bot and was edited
* @method InlineQuery getInlineQuery() Optional. New incoming inline query
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
*/
class Update extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'message' => Message::class,
'edited_message' => EditedMessage::class,
'channel_post' => ChannelPost::class,
'edited_channel_post' => EditedChannelPost::class,
'inline_query' => InlineQuery::class,
'chosen_inline_result' => ChosenInlineResult::class,
'callback_query' => CallbackQuery::class,
];
}
/**
* Get the update type based on the set properties
*
* @return string|null
*/
public function getUpdateType()
{
$types = [
'message',
'edited_message',
'channel_post',
'edited_channel_post',
'inline_query',
'chosen_inline_result',
'callback_query',
];
foreach ($types as $type) {
if ($this->getProperty($type)) {
return $type;
}
}
return null;
}
/**
* Get update content
*
* @return \Longman\TelegramBot\Entities\CallbackQuery
* |\Longman\TelegramBot\Entities\ChosenInlineResult
* |\Longman\TelegramBot\Entities\InlineQuery
* |\Longman\TelegramBot\Entities\Message
*/
public function getUpdateContent()
{
if ($update_type = $this->getUpdateType()) {
// Instead of just getting the property as an array,
// use the __call method to get the correct Entity object.
$method = 'get' . str_replace('_', '', ucwords($update_type, '_'));
return $this->$method();
}
return null;
}
}