setWebhook() public method

$params = [ 'url' => '', 'certificate' => '', ];
public setWebhook ( array $params ) : TelegramResponse
$params array
return TelegramResponse
コード例 #1
0
ファイル: App.php プロジェクト: antoniomadonna/rome-bus-bot
 /**
  * App constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->match('/', function () {
         return '/';
     });
     /**
      * process messages
      */
     $this->match('update', function () {
         $telegram = new Client(BOT_TOKEN);
         $handler = new Handler($telegram);
         return $handler->handle();
     });
     /**
      * update hook settings/api
      */
     $this->match('hook', function () {
         $telegram = new Api(BOT_TOKEN);
         $telegram->removeWebhook();
         if (USE_WEBHOOK) {
             $telegram->setWebhook(WEBHOOK, '../server-setup/files/cert/nginx.crt');
             return 'hook set';
         }
         return 'hook-removed';
     });
 }
コード例 #2
0
ファイル: index.php プロジェクト: matthewbaggett/kickbot
<?php

require_once "../bootstrap.php";
use Symfony\Component\Yaml\Yaml;
use Telegram\Bot\Api as TelegramApi;
$config = Yaml::parse(file_get_contents('../config.yml'));
$telegram = new TelegramApi($config['telegram_api_key']);
$app = new \Slim\App();
$app->get('/telegram/webhook/{key}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {
    $key = $request->getAttribute('key');
    error_log($request->getBody());
    $response->getBody()->write("Hello telegram!");
    return $response;
});
$app->get('/hello/{name}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, {$name}");
    return $response;
})->setName('hello');
$app->get('telegram/setup', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {
    global $config, $telegram;
    $telegramCallbackAuth = $telegram->setWebhook("https://kickbot.telegram.thru.io/telegram/webhook/{$config['telegram_api_key']}");
    \Kint::dump($telegramCallbackAuth);
    exit;
});
$app->get('.well-known/acme-challenge/El1K2GOuLyDvjk9-uM8P-Fge_oDMeYHYBL_VVvdvT4s', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {
    $response->getBody()->write("El1K2GOuLyDvjk9-uM8P-Fge_oDMeYHYBL_VVvdvT4s.BjQMlU5nwgsexb_DdA7zyb5OWcbghyA_u5G5PCeY610");
    return $response;
});
$app->run();
コード例 #3
0
ファイル: setwebhook.php プロジェクト: aleritty/yaitb
<?php

require_once 'EDITME/config.php';
require_once 'boot.php';
use Telegram\Bot\Api;
$telegram = new Api($BOTTOKEN);
$response = $telegram->setWebhook($BASEURL . "webhook");
echo "<pre>";
print_r($response);
echo "</pre>";
コード例 #4
0
<?php

use Telegram\Bot\Api;
require 'vendor/autoload.php';
require 'config.php';
if (isset($_GET['url'])) {
    $url = $_GET['url'];
} else {
    $url = $_SERVER['HTTP_HOST'];
}
if (filter_var('https://' . $url, FILTER_VALIDATE_URL) == false) {
    echo 'Invalid url for get certificate: ' . $url;
    die;
}
$g = stream_context_create(array("ssl" => array("capture_peer_cert" => true, "verify_peer" => false, "verify_peer_name" => false)));
$r = stream_socket_client("ssl://{$url}:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
if (!$r) {
    echo 'Domain dont exists or dont is over ssl';
    die;
}
$cont = stream_context_get_params($r);
openssl_x509_export($cont["options"]["ssl"]["peer_certificate"], $certificate);
$certificate = trim($certificate, "\n");
echo '<pre>';
echo $certificate;
echo '</pre>';
$telegram = new Api($config['token']);
$response = $telegram->setWebhook('https://' . $url, $certificate);
var_dump(['url' => 'https://' . $url, 'response' => $response]);
コード例 #5
0
ファイル: midna.php プロジェクト: e0th/Midna
namespace Midna;

use RedBeanPHP\R;
use Telegram\Bot\Api;
require_once __DIR__ . '/../../vendor/autoload.php';
define('MIDNA_TOKEN', 'xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('MIDNA_HOOK', 'https://example.com/path/to/this/file.php');
define('MIDNA_CERT', '/path/to/your/ssl/certificate.pem');
$telegram = new Api(MIDNA_TOKEN);
R::setup('sqlite:' . __DIR__ . '/../../database/database.db');
$telegram->addCommand(new Commands\Start());
$telegram->addCommand(new Commands\Help());
$telegram->commandsHandler(true);
if (php_sapi_name() == 'cli') {
    if ($argv[1] == 'start') {
        print "Starting Midna" . PHP_EOL;
        $bean = R::dispense('messages');
        $bean->message_id = 0;
        $bean->message_date = 0;
        R::store($bean);
        $telegram->setWebhook(['url' => MIDNA_HOOK, 'certificate' => MIDNA_CERT]);
    } else {
        if ($argv[1] == 'stop') {
            print "Stopping Midna" . PHP_EOL;
            $telegram->removeWebhook();
        }
    }
    exit;
}
R::close();