Skip to content

Commit

Permalink
Merge pull request #146 from DJTommek/pr/set-webhook
Browse files Browse the repository at this point in the history
Webhook $secret_token
  • Loading branch information
unreal4u authored Jul 28, 2022
2 parents 9317795 + 315ae79 commit 70f478d
Show file tree
Hide file tree
Showing 2 changed files with 42 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) {
echo '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();
9 changes: 9 additions & 0 deletions src/Telegram/Methods/SetWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class SetWebhook extends TelegramMethods
*/
public $drop_pending_updates;

/**
* Optional. A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request,
* 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the
* request comes from a webhook set by you.
*
* @var string
*/
public $secret_token;

public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
{
return new ResultBoolean($data->getResultBoolean(), $logger);
Expand Down

0 comments on commit 70f478d

Please sign in to comment.