-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathInlinequeryCommand.php
100 lines (85 loc) · 3.2 KB
/
InlinequeryCommand.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
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* This file is part of the PHP Telegram Bot example-bot package.
* https://github.com/php-telegram-bot/example-bot/
*
* (c) PHP Telegram Bot Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Inline query command
*
* Command that handles inline queries and returns a list of results.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultContact;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultLocation;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultVenue;
use Longman\TelegramBot\Entities\InputMessageContent\InputTextMessageContent;
use Longman\TelegramBot\Entities\ServerResponse;
class InlinequeryCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = 'inlinequery';
/**
* @var string
*/
protected $description = 'Handle inline query';
/**
* @var string
*/
protected $version = '1.2.0';
/**
* Main command execution
*
* @return ServerResponse
*/
public function execute(): ServerResponse
{
$inline_query = $this->getInlineQuery();
$query = $inline_query->getQuery();
$results = [];
if ($query !== '') {
// https://core.telegram.org/bots/api#inlinequeryresultarticle
$results[] = new InlineQueryResultArticle([
'id' => '001',
'title' => 'Simple text using InputTextMessageContent',
'description' => 'this will return Text',
// Here you can put any other Input...MessageContent you like.
// It will keep the style of an article, but post the specific message type back to the user.
'input_message_content' => new InputTextMessageContent([
'message_text' => 'The query that got you here: ' . $query,
]),
]);
// https://core.telegram.org/bots/api#inlinequeryresultcontact
$results[] = new InlineQueryResultContact([
'id' => '002',
'phone_number' => '12345678',
'first_name' => 'Best',
'last_name' => 'Friend',
]);
// https://core.telegram.org/bots/api#inlinequeryresultlocation
$results[] = new InlineQueryResultLocation([
'id' => '003',
'title' => 'The center of the world!',
'latitude' => 40.866667,
'longitude' => 34.566667,
]);
// https://core.telegram.org/bots/api#inlinequeryresultvenue
$results[] = new InlineQueryResultVenue([
'id' => '004',
'title' => 'No-Mans-Land',
'address' => 'In the middle of Nowhere',
'latitude' => 33,
'longitude' => -33,
]);
}
return $inline_query->answer($results);
}
}