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
Table of Contents
Properties
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
$telegram read-only
private
Telegram
$telegram
Methods
__construct()
public
__construct(Telegram $telegram[, array<string, mixed> $options = [] ]) : mixed
Parameters
- $telegram : Telegram
- $options : array<string, mixed> = []
close()
public
close() : void
getAddress()
The address the listener is bound to, once it is listening.
public
getAddress() : ?string
Return values
?stringlisten()
Binds the socket and starts accepting deliveries.
public
listen() : void
Tags
handle()
private
handle(ServerRequestInterface $request) : Response
Parameters
- $request : ServerRequestInterface