Skip to content

Commit

Permalink
Webhook: added example for SetWebook class
Browse files Browse the repository at this point in the history
  • Loading branch information
DJTommek committed Jul 28, 2022
1 parent 6275237 commit 4b9fec7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/set-webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

include __DIR__ . '/basics.php';

use React\EventLoop\Factory;
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
use unreal4u\TelegramAPI\HttpClientRequestHandler;
use unreal4u\TelegramAPI\Telegram\Methods\SetWebhook;
use unreal4u\TelegramAPI\TgLog;

$loop = Factory::create();
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));

$webhook = new SetWebhook();
$webhook->url = 'https://example.com/';
$webhook->max_connections = 3;
$webhook->allowed_updates = ['message'];
$webhook->drop_pending_updates = true;
$webhook->secret_token = 'some-very-secret-string';

$promise = $tgLog->performApiRequest($webhook);
$promise->then(
function (TelegramTypes $response) {
var_dump('Webhook was successfully set. Run get-webhookinfo.php to get detailed information about webhook from server.');
},
function (\Exception $exception) {
var_dump($exception->getMessage());
}
);

$loop->run();

0 comments on commit 4b9fec7

Please sign in to comment.