Пример #1
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Rde\Telegram\Connection;
use Rde\Bot;
use Rde\DataChain;
$config = (include_once '../Config/config.php');
$app = new Silex\Application();
$app->post('/hook/{hook}', function ($hook) use($app, $config) {
    $botName = $config[$hook]['bot'];
    $token = $config[$hook]['token'];
    $post = file_get_contents('php://input');
    $postData = new DataChain(json_decode($post));
    $chatId = $postData->message->chat->id->value();
    $bot = Bot::make($botName);
    $message = $bot->parse($postData);
    if (!isset($chatId) || !isset($message)) {
        return 'OK';
    }
    $conn = new Connection($token);
    $conn->sendMessage(['chat_id' => $chatId, 'text' => $message]);
    return 'OK';
});
$app->run();