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\Commands\SystemCommands; |
12
|
|
|
|
13
|
|
|
use Longman\TelegramBot\Commands\SystemCommand; |
14
|
|
|
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultArticle; |
15
|
|
|
use Longman\TelegramBot\Entities\InputMessageContent\InputTextMessageContent; |
16
|
|
|
use Longman\TelegramBot\Request; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Inline query command |
20
|
|
|
*/ |
21
|
|
|
class InlinequeryCommand extends SystemCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name = 'inlinequery'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $description = 'Reply to inline query'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $version = '1.1.0'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Command execute method |
40
|
|
|
* |
41
|
|
|
* @return mixed |
42
|
|
|
* @throws \Longman\TelegramBot\Exception\TelegramException |
43
|
|
|
*/ |
44
|
|
|
public function execute() |
45
|
|
|
{ |
46
|
|
|
$update = $this->getUpdate(); |
47
|
|
|
$inline_query = $update->getInlineQuery(); |
48
|
|
|
$query = $inline_query->getQuery(); |
49
|
|
|
|
50
|
|
|
$data = ['inline_query_id' => $inline_query->getId()]; |
51
|
|
|
$results = []; |
52
|
|
|
|
53
|
|
|
if ($query !== '') { |
54
|
|
|
$articles = [ |
55
|
|
|
[ |
56
|
|
|
'id' => '001', |
57
|
|
|
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', |
58
|
|
|
'description' => 'you enter: ' . $query, |
59
|
|
|
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]), |
60
|
|
|
], |
61
|
|
|
[ |
62
|
|
|
'id' => '002', |
63
|
|
|
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', |
64
|
|
|
'description' => 'you enter: ' . $query, |
65
|
|
|
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]), |
66
|
|
|
], |
67
|
|
|
[ |
68
|
|
|
'id' => '003', |
69
|
|
|
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', |
70
|
|
|
'description' => 'you enter: ' . $query, |
71
|
|
|
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]), |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
foreach ($articles as $article) { |
76
|
|
|
$results[] = new InlineQueryResultArticle($article); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$data['results'] = '[' . implode(',', $results) . ']'; |
81
|
|
|
|
82
|
|
|
return Request::answerInlineQuery($data); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|