setWebhook() public method

If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. \param $url String HTTPS url to send updates to. Use an empty string to remove webhook integration \param $certificate InputFile Upload your public key certificate so that the root certificate in use can be checked \return the JSON Telegram's reply
public setWebhook ( $url, $certificate = "" )
Example #1
0
<?php 
//previsto da chiamare solo php start.php con 1 eventuale parametro che può essere
//hookset per settare il link di webhook
//hookremove per rimuovere il link di webhook
//getupdates per eseguzione a polling (con cron o manualmente)
//e non si imposta il primo paramentro da shell si assume di avere impostato il webhook e di utilizzare quello
include 'settings_t.php';
include 'getUpdates.php';
//istanzia oggetto Telegram
$bot_id = TELEGRAM_BOT;
$bot = new Telegram($bot_id);
//valuta se l'interfaccia è di tipo CLI per vedere il parametro e settare o rimuovere il webhook e poi esce (se lanciato da riga di comando)
if (php_sapi_name() == 'cli') {
    if ($argv[1] == 'sethook') {
        //setta il webhook
        $bot->setWebhook(BOT_WEBHOOK);
    } else {
        if ($argv[1] == 'removehook') {
            //rimuove il webhook
            $bot->removeWebhook();
        } else {
            if ($argv[1] == 'getupdates') {
                //esegue il getupdates manuale
                getUpdates($bot);
            }
        }
    }
    exit;
}
//legge
$bot->init();
Example #2
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get("/sethook", function () {
    Telegram::setWebhook('https://cantareirabot.herokuapp.com/webhook');
});
Route::any('/webhook', function () {
    $updates = Telegram::commandsHandler(true);
});
Example #3
0
// Published under the MIT License, Copyright (c) 2015 Pius Ladenburger
/* Telegram Bot Info */
define('TOKEN', 'TOKE_RECEIVED_FROM_TELEGRAM');
define('NAME', 'BOT_NAME');
define('MAX_CALLS', 7);
// maximum calls per hour
/* MySQL Database Info */
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', 'USERNAME');
define('MYSQL_PASSWORD', 'PASSWORD');
define('MYSQL_NAME', 'BOT');
require './advanced/class.DB.php';
require './advanced/class.session.php';
require './class.telegram.php';
$bot = new Telegram(TOKEN, NAME);
// $DB = new \System\Database\MySQL(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_NAME);
// Incoming update
$request = json_decode(file_get_contents('php://input'), true);
if ($request['update_id']) {
    // Message received
    // BOT CODE HERE
    // API: https://core.telegram.org/bots/api#getting-updates
}
if ($_GET['setHook']) {
    // uncomment, type in your webhook domain and visit example.com/path/to/bot/?setHook=1 to register the hook
    echo $bot->setWebhook('https://example.com/telegram_bot');
} else {
    // uncomment if you need some troubleshooting
    // include ('./advanced/debug.php');
}