-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
39 lines (28 loc) · 1.15 KB
/
index.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
<?php
require_once "vendor/autoload.php";
try {
$token = 'YOUR_BOT_API_TOKEN';
$bot = new \TelegramBot\Api\Client($token);
$bot->inlineQuery(function (\TelegramBot\Api\Types\Inline\InlineQuery $inlineQuery) use ($bot) {
/* @var \TelegramBot\Api\BotApi $bot */
$html = file_get_contents('http://stavklass.ru/images/search?utf8=✓&image[text]=' . $inlineQuery->getQuery());
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$img = $xpath->query('//div[@class="image-content"]/a[@class="image"]/img');
$result = [];
for ($i = 0; $i < $img->length; $i++) {
/* @var \DOMNodeList $img */
$node = $img->item($i);
$url = $node->getAttribute('src');
list($width, $height) = getimagesize($url);
$result[] = new \TelegramBot\Api\Types\Inline\InlineQueryResultPhoto(
$url, $url, $url, 'image/jpeg', $width, $height
);
}
$bot->answerInlineQuery($inlineQuery->getId(), $result, 0);
});
$bot->run();
} catch (\TelegramBot\Api\Exception $e) {
$e->getMessage();
}