Ejemplo n.º 1
0
    $response_data = json_decode($response, true);
    $helper = new BotHelper($config, $route);
    $response = $helper->fetchMessage($bot_config, $response_data);
    //If its markup is like a command, just ignore it.
    //TODO this feature will be enabled in future versions.
    if (!$response) {
        return 'OK';
    }
    //now let's reply!
    //https://core.telegram.org/bots/api#sendmessage
    $client = new GuzzleHttp\Client();
    if ($config['source'] == 'file') {
        //try {
        $client->get('https://api.telegram.org/bot' . $bot_config['token'] . '/sendMessage?' . http_build_query($response['data']));
        /*} catch(Exception $e) {
              //You can catch exceptions and log etc here by uncommenting try/catch statement.
          }*/
    } else {
        //try {
        //http://guzzle.readthedocs.org/en/latest/request-options.html#multipart
        $client->post('https://api.telegram.org/bot' . $bot_config['token'] . '/' . $helper->getEndpoint($response['type']), ['multipart' => $response['data']]);
        /*} catch(Exception $e) {
        
                    //You can catch exceptions and log etc here by uncommenting try/catch statement.
         
                }*/
    }
    //Telegram API wants something in return, else it tries infinitely
    return 'OK';
});
$app->run();