Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 4b9fec7

Browse files
committed
Webhook: added example for SetWebook class
1 parent 6275237 commit 4b9fec7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

examples/set-webhook.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
include __DIR__ . '/basics.php';
6+
7+
use React\EventLoop\Factory;
8+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
9+
use unreal4u\TelegramAPI\HttpClientRequestHandler;
10+
use unreal4u\TelegramAPI\Telegram\Methods\SetWebhook;
11+
use unreal4u\TelegramAPI\TgLog;
12+
13+
$loop = Factory::create();
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
15+
16+
$webhook = new SetWebhook();
17+
$webhook->url = 'https://example.com/';
18+
$webhook->max_connections = 3;
19+
$webhook->allowed_updates = ['message'];
20+
$webhook->drop_pending_updates = true;
21+
$webhook->secret_token = 'some-very-secret-string';
22+
23+
$promise = $tgLog->performApiRequest($webhook);
24+
$promise->then(
25+
function (TelegramTypes $response) {
26+
var_dump('Webhook was successfully set. Run get-webhookinfo.php to get detailed information about webhook from server.');
27+
},
28+
function (\Exception $exception) {
29+
var_dump($exception->getMessage());
30+
}
31+
);
32+
33+
$loop->run();

0 commit comments

Comments
 (0)