Skip to content

Commit 70f478d

Browse files
authored
Merge pull request #146 from DJTommek/pr/set-webhook
Webhook $secret_token
2 parents 9317795 + 315ae79 commit 70f478d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-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+
echo '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();

src/Telegram/Methods/SetWebhook.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ class SetWebhook extends TelegramMethods
8383
*/
8484
public $drop_pending_updates;
8585

86+
/**
87+
* Optional. A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request,
88+
* 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the
89+
* request comes from a webhook set by you.
90+
*
91+
* @var string
92+
*/
93+
public $secret_token;
94+
8695
public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
8796
{
8897
return new ResultBoolean($data->getResultBoolean(), $logger);

0 commit comments

Comments
 (0)