1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the TelegramBot package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Longman\TelegramBot\Entities; |
12
|
|
|
|
13
|
|
|
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery; |
14
|
|
|
use Longman\TelegramBot\Entities\Payments\ShippingQuery; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Update |
18
|
|
|
* |
19
|
|
|
* @link https://core.telegram.org/bots/api#update |
20
|
|
|
* |
21
|
|
|
* @method int getUpdateId() The update's unique identifier. Update identifiers start from a certain positive number and increase |
22
|
|
|
* 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 |
23
|
|
|
* sequence, should they get out of order. |
24
|
|
|
* @method Message getMessage() Optional. New incoming message of any kind — text, photo, sticker, etc. |
25
|
|
|
* @method Message getEditedMessage() Optional. New version of a message that is known to the bot and was edited |
26
|
|
|
* @method Message getChannelPost() Optional. New post in the channel, can be any kind — text, photo, sticker, etc. |
27
|
|
|
* @method Message getEditedChannelPost() Optional. New version of a post in the channel that is known to the bot and was edited |
28
|
|
|
* @method InlineQuery getInlineQuery() Optional. New incoming inline query |
29
|
|
|
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner. |
30
|
|
|
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query |
31
|
|
|
* @method ShippingQuery getShippingQuery() Optional. New incoming shipping query. Only for invoices with flexible price |
32
|
|
|
* @method PreCheckoutQuery getPreCheckoutQuery() Optional. New incoming pre-checkout query. Contains full information about checkout |
33
|
|
|
*/ |
34
|
|
|
class Update extends Entity |
35
|
|
|
{ |
36
|
|
|
const TYPE_MESSAGE = 'message'; |
37
|
|
|
const TYPE_EDITED_MESSAGE = 'edited_message'; |
38
|
|
|
const TYPE_CHANNEL_POST = 'channel_post'; |
39
|
|
|
const TYPE_EDITED_CHANNEL_POST = 'edited_channel_post'; |
40
|
|
|
const TYPE_INLINE_QUERY = 'inline_query'; |
41
|
|
|
const TYPE_CHOSEN_INLINE_QUERY = 'chosen_inline_result'; |
42
|
|
|
const TYPE_CALLBACK_QUERY = 'callback_query'; |
43
|
|
|
const TYPE_SHIPPING_QUERY = 'shipping_query'; |
44
|
|
|
const TYPE_PRE_CHECKOUT_QUERY = 'pre_checkout_query'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
5 |
|
protected function subEntities() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
5 |
|
self::TYPE_MESSAGE => Message::class, |
53
|
5 |
|
self::TYPE_EDITED_MESSAGE => EditedMessage::class, |
54
|
5 |
|
self::TYPE_CHANNEL_POST => ChannelPost::class, |
55
|
5 |
|
self::TYPE_EDITED_CHANNEL_POST => EditedChannelPost::class, |
56
|
5 |
|
self::TYPE_INLINE_QUERY => InlineQuery::class, |
57
|
5 |
|
self::TYPE_CHOSEN_INLINE_QUERY => ChosenInlineResult::class, |
58
|
5 |
|
self::TYPE_CALLBACK_QUERY => CallbackQuery::class, |
59
|
5 |
|
self::TYPE_SHIPPING_QUERY => ShippingQuery::class, |
60
|
5 |
|
self::TYPE_PRE_CHECKOUT_QUERY => PreCheckoutQuery::class, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the update type based on the set properties |
66
|
|
|
* |
67
|
|
|
* @return string|null |
68
|
|
|
*/ |
69
|
2 |
|
public function getUpdateType() |
70
|
|
|
{ |
71
|
2 |
|
$types = array_keys($this->subEntities()); |
72
|
|
|
|
73
|
2 |
|
foreach ($types as $type) { |
74
|
2 |
|
if ($this->getProperty($type)) { |
75
|
2 |
|
return $type; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
return null; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get update content |
84
|
|
|
* |
85
|
|
|
* @return \Longman\TelegramBot\Entities\CallbackQuery |
86
|
|
|
* |\Longman\TelegramBot\Entities\ChosenInlineResult |
87
|
|
|
* |\Longman\TelegramBot\Entities\InlineQuery |
88
|
|
|
* |\Longman\TelegramBot\Entities\Message |
89
|
|
|
*/ |
90
|
|
|
public function getUpdateContent() |
91
|
|
|
{ |
92
|
|
|
if ($update_type = $this->getUpdateType()) { |
93
|
|
|
// Instead of just getting the property as an array, |
94
|
|
|
// use the __call method to get the correct Entity object. |
95
|
|
|
$method = 'get' . str_replace('_', '', ucwords($update_type, '_')); |
96
|
|
|
|
97
|
|
|
return $this->$method(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return null; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|