|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Greenplugin\TelegramBot\Method; |
|
6
|
|
|
|
|
7
|
|
|
use Greenplugin\TelegramBot\Method\Traits\FillFromArrayTrait; |
|
8
|
|
|
use Greenplugin\TelegramBot\Type\InlineQueryResult\InlineQueryResultType; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class AnswerInlineQueryMethod. |
|
12
|
|
|
* |
|
13
|
|
|
* Use this method to send answers to an inline query. On success, True is returned. |
|
14
|
|
|
* No more than 50 results per query are allowed. |
|
15
|
|
|
* |
|
16
|
|
|
* @see https://core.telegram.org/bots/api#answerinlinequery |
|
17
|
|
|
*/ |
|
18
|
|
|
class AnswerInlineQueryMethod |
|
19
|
|
|
{ |
|
20
|
|
|
use FillFromArrayTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Unique identifier for the answered query. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
public $inlineQueryId; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* A JSON-serialized array of results for the inline query. |
|
31
|
|
|
* |
|
32
|
|
|
* @var InlineQueryResultType[] |
|
33
|
|
|
*/ |
|
34
|
|
|
public $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
|
|
|
* |
|
40
|
|
|
* @var int|null |
|
41
|
|
|
*/ |
|
42
|
|
|
public $cacheTime; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Optional. Pass True, if results may be cached on the server side only for the user that sent the query. |
|
46
|
|
|
* By default, results may be returned to any user who sends the same query. |
|
47
|
|
|
* |
|
48
|
|
|
* @var bool|null |
|
49
|
|
|
*/ |
|
50
|
|
|
public $isPersonal; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Optional. Pass the offset that a client should send in the next query with the same text to receive more results. |
|
54
|
|
|
* Pass an empty string if there are no more results or if you don‘t support pagination. |
|
55
|
|
|
* Offset length can’t exceed 64 bytes. |
|
56
|
|
|
* |
|
57
|
|
|
* @var string|null |
|
58
|
|
|
*/ |
|
59
|
|
|
public $nextOffset; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Optional. If passed, clients will display a button with specified text that switches the user to a private |
|
63
|
|
|
* chat with the bot and sends the bot a start message with the parameter switch_pm_parameter. |
|
64
|
|
|
* |
|
65
|
|
|
* @var string|null |
|
66
|
|
|
*/ |
|
67
|
|
|
public $switchPmText; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* String Optional. Deep-linking parameter for the /start message sent to the bot when user presses the switch |
|
71
|
|
|
* button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed. |
|
72
|
|
|
* |
|
73
|
|
|
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account |
|
74
|
|
|
* to adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’ |
|
75
|
|
|
* button above the results, or even before showing any. The user presses the button, switches to a private chat |
|
76
|
|
|
* with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. |
|
77
|
|
|
* Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where |
|
78
|
|
|
* they wanted to use the bot's inline capabilities. |
|
79
|
|
|
* |
|
80
|
|
|
* @var string|null |
|
81
|
|
|
*/ |
|
82
|
|
|
public $switchPmParameter; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* AnswerInlineQueryMethod constructor. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $inlineQueryId |
|
88
|
|
|
* @param InlineQueryResultType[] $results |
|
89
|
|
|
* @param array|null $data |
|
90
|
|
|
* |
|
91
|
|
|
* @throws \Greenplugin\TelegramBot\Exception\BadArgumentException |
|
92
|
|
|
*/ |
|
93
|
|
|
public function __construct(string $inlineQueryId, array $results, array $data = null) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->inlineQueryId = $inlineQueryId; |
|
96
|
|
|
$this->results = $results; |
|
97
|
|
|
if ($data) { |
|
98
|
|
|
$this->fill($data); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param InlineQueryResultType $result |
|
104
|
|
|
*/ |
|
105
|
|
|
public function addResult(InlineQueryResultType $result) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->results[] = $result; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|