|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace unreal4u\TelegramAPI\Telegram\Methods; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
|
8
|
|
|
use unreal4u\TelegramAPI\Abstracts\TelegramMethods; |
|
9
|
|
|
use unreal4u\TelegramAPI\Abstracts\TelegramTypes; |
|
10
|
|
|
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse; |
|
11
|
|
|
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean; |
|
12
|
|
|
use unreal4u\TelegramAPI\Telegram\Types\Inline\Query\Result; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Use this method to send answers to an inline query. On success, True is returned. |
|
16
|
|
|
* No more than 50 results per query are allowed. |
|
17
|
|
|
* |
|
18
|
|
|
* Objects defined as-is july 2016 |
|
19
|
|
|
* |
|
20
|
|
|
* @see https://core.telegram.org/bots/api#answerinlinequery |
|
21
|
|
|
*/ |
|
22
|
|
|
class AnswerInlineQuery extends TelegramMethods |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Unique identifier for the answered query |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $inline_query_id = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* A JSON-serialized array (of InlineQueryResult) of results for the inline query |
|
32
|
|
|
* @var array[] |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $results = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Optional. The maximum amount of time in seconds that the result of the inline query may be cached on the server. |
|
38
|
|
|
* Defaults to 300. |
|
39
|
|
|
* @var int |
|
40
|
|
|
*/ |
|
41
|
|
|
public $cache_time = 300; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Optional. Pass True, if results may be cached on the server side only for the user that sent the query. By |
|
45
|
|
|
* default, results may be returned to any user who sends the same query |
|
46
|
|
|
* @var bool |
|
47
|
|
|
*/ |
|
48
|
|
|
public $is_personal = false; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Optional. Pass the offset that a client should send in the next query with the same text to receive more results. |
|
52
|
|
|
* Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t |
|
53
|
|
|
* exceed 64 bytes. |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
public $next_offset = ''; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Optional. If passed, clients will display a button with specified text that switches the user to a private chat |
|
60
|
|
|
* with the bot and sends the bot a start message with the parameter switch_pm_parameter |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
public $switch_pm_text = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Optional. Parameter for the start message sent to the bot when user presses the switch button |
|
67
|
|
|
* |
|
68
|
|
|
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to |
|
69
|
|
|
* adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’ button above the |
|
70
|
|
|
* results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in |
|
71
|
|
|
* doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a |
|
72
|
|
|
* switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline |
|
73
|
|
|
* capabilities. |
|
74
|
|
|
* |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
public $switch_pm_parameter = ''; |
|
78
|
|
|
|
|
79
|
|
|
public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes |
|
80
|
|
|
{ |
|
81
|
|
|
return new ResultBoolean($data->getResultBoolean(), $logger); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function performSpecialConditions(): TelegramMethods |
|
85
|
|
|
{ |
|
86
|
|
|
$this->results = json_encode($this->results); |
|
87
|
|
|
|
|
88
|
|
|
return parent::performSpecialConditions(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getMandatoryFields(): array |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
'inline_query_id', |
|
95
|
|
|
'results', |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Use this method to add a result, this will delete all additional unneeded information from the subclass |
|
101
|
|
|
* |
|
102
|
|
|
* @param Result $result |
|
103
|
|
|
* @return AnswerInlineQuery |
|
104
|
|
|
* @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField |
|
105
|
|
|
*/ |
|
106
|
|
|
public function addResult(Result $result): AnswerInlineQuery |
|
107
|
|
|
{ |
|
108
|
|
|
$this->results[] = $result->export(); |
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Use this method to get list of added results |
|
114
|
|
|
* |
|
115
|
|
|
* @return AnswerInlineQuery[] |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getResults(): array |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->results; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|