Ejemplo n.º 1
1
<?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();
}
Ejemplo n.º 2
0
<?php

require_once "vendor/autoload.php";
try {
    $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY');
    $bot->command('devanswer', function ($message) use($bot) {
        preg_match_all('/{"text":"(.*?)",/s', file_get_contents('http://devanswers.ru/'), $result);
        $bot->sendMessage($message->getChat()->getId(), str_replace("<br/>", "\n", json_decode('"' . $result[1][0] . '"')));
    });
    $bot->command('qaanswer', function ($message) use($bot) {
        $bot->sendMessage($message->getChat()->getId(), file_get_contents('http://qaanswers.ru/qwe.php'));
    });
    $bot->run();
} catch (\TelegramBot\Api\Exception $e) {
    $e->getMessage();
}