TelegramPHP Documentation

Server
in package

FinalYes

The other update source: an HTTP listener Telegram posts updates to.

Telegram requires the public endpoint to be HTTPS, so in practice this listens on plain HTTP behind a reverse proxy that terminates TLS. Requests are checked against the secret_token registered with setWebhook - the only thing that distinguishes a real delivery from anyone else who found the URL - and answered 200 as soon as the update is queued, because Telegram retries anything slower.

$telegram = new Telegram([
    'token' => $token,
    'webhook' => ['listen' => '0.0.0.0:8080', 'path' => '/hook', 'secret_token' => $secret],
]);
$telegram->setWebhook('https://bot.example.com/hook', secret_token: $secret);
$telegram->run();
Tags
link
https://core.telegram.org/bots/api#setwebhook
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Properties

$http  : ?HttpServer
$options  : array<string, mixed>
$socket  : ?SocketServer
$telegram  : Telegram

Methods

__construct()  : mixed
close()  : void
getAddress()  : ?string
The address the listener is bound to, once it is listening.
listen()  : void
Binds the socket and starts accepting deliveries.
handle()  : Response

Properties

$http

private ?HttpServer $http = null

$options

private array<string, mixed> $options

$socket

private ?SocketServer $socket = null

Methods

__construct()

public __construct(Telegram $telegram[, array<string, mixed> $options = [] ]) : mixed
Parameters
$telegram : Telegram
$options : array<string, mixed> = []

getAddress()

The address the listener is bound to, once it is listening.

public getAddress() : ?string
Return values
?string

listen()

Binds the socket and starts accepting deliveries.

public listen() : void
Tags
throws
PollingException

When the address cannot be bound.

handle()

private handle(ServerRequestInterface $request) : Response
Parameters
$request : ServerRequestInterface
Return values
Response
On this page

Search results