DiscordPHP-BridgeBot Documentation

TelegramConfig
in package

FinalYes

What the Telegram connector needs to start, read from the same environment the bot itself was.

Kept here rather than in the core's Config, which is the point of the connector model: installing a network should not mean the core grows fields for settings it will never read.

Secrets only ever come from the environment — never from the JSON store, which is runtime state a server admin edits through chat and which should be safe to read, back up, or paste into an issue.

Tags
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Constants

DEFAULT_PREFIX  : mixed = '!'
What commands typed in a Telegram chat start with.
MAX_POLL_TIMEOUT  : mixed = 50
Telegram holds a long poll open for at most this many seconds.

Properties

$baseUrl  : string|null
$caBundle  : string|null
$caBundleSource  : string|null
$ownerId  : string|null
$pollTimeout  : int
$prefix  : string
$token  : string

Methods

baseUrlProblem()  : string|null
Why `TELEGRAM_BASE_URL` cannot be used, or `null` when it can or is unset.
botId()  : string|null
The bot's own numeric id, which Telegram puts in front of every token.
fromEnvironment()  : self
isConfigured()  : bool
Whether the environment carries enough to install this connector at all.
socketOptions()  : array<string, mixed>
The `socket_options` TelegramPHP should connect with.
__construct()  : mixed
caBundle()  : array{0: ?string, 1: ?string}
The CA bundle to verify Telegram's certificate with, and where it came from.
numericId()  : string|null
A numeric user id, or `null` for anything else — an `@name` can change hands.

Constants

DEFAULT_PREFIX

What commands typed in a Telegram chat start with.

public mixed DEFAULT_PREFIX = '!'

MAX_POLL_TIMEOUT

Telegram holds a long poll open for at most this many seconds.

public mixed MAX_POLL_TIMEOUT = 50

Properties

$caBundleSource read-only

public string|null $caBundleSource = null

Methods

baseUrlProblem()

Why `TELEGRAM_BASE_URL` cannot be used, or `null` when it can or is unset.

public baseUrlProblem() : string|null

Checked before the first request rather than left to fail there: a URL without a scheme reaches ReactPHP, which refuses it with "Invalid request URL given" and names neither the setting nor the value. The value is repeated with any token in it masked, in case a whole method URL was pasted in.

Return values
string|null

botId()

The bot's own numeric id, which Telegram puts in front of every token.

public botId() : string|null

Used to recognise the bot's own messages coming back, and needed before the API has answered anything — so it is read off the token rather than fetched.

Return values
string|null

fromEnvironment()

public static fromEnvironment(Environment $environment[, callable(string): Array|null $ini = null ]) : self
Parameters
$environment : Environment
$ini : callable(string): Array|null = null

Reads a php.ini directive; ini_get unless a test says otherwise.

Tags
throws
RuntimeException

when a required value is missing.

Return values
self

isConfigured()

Whether the environment carries enough to install this connector at all.

public static isConfigured(Environment $environment) : bool
Parameters
$environment : Environment
Return values
bool

socketOptions()

The `socket_options` TelegramPHP should connect with.

public socketOptions() : array<string, mixed>

Only ever a CA bundle. A Windows PHP build typically ships without an openssl.cafile, so TLS to api.telegram.org fails outright with "unable to get local issuer certificate"; pointing the connector at a cacert.pem — set, or found in php.ini — is the fix. Everything else is left at ReactPHP's defaults; in particular, verification is never disabled.

Return values
array<string, mixed>

__construct()

private __construct(string $token, string|null $baseUrl, int $pollTimeout, string|null $caBundle[, string $prefix = self::DEFAULT_PREFIX ][, string|null $ownerId = null ][, string|null $caBundleSource = null ]) : mixed
Parameters
$token : string

From @BotFather. Never logged.

$baseUrl : string|null

A self-hosted Bot API server, or null for Telegram's own.

$pollTimeout : int

How long each long poll is held open, in seconds.

$caBundle : string|null

The CA bundle TLS to Telegram is verified with; see caBundle().

$prefix : string = self::DEFAULT_PREFIX

What commands typed in a Telegram chat start with.

$ownerId : string|null = null

The operator's numeric Telegram user id, for the top rung in chat.

$caBundleSource : string|null = null

Where $caBundle came from — the variable or the php.ini directive — for the log.

caBundle()

The CA bundle to verify Telegram's certificate with, and where it came from.

private static caBundle(Environment $environment, callable(string): Array $ini) : array{0: ?string, 1: ?string}

TELEGRAM_CA_BUNDLE when it is set, as given. Otherwise whatever php.ini names: openssl.cafile first, since that is what PHP's own streams read, then curl.cainfo — on Windows often the only one set, because it is the one installers and guides mention, and PHP's streams never read it.

A php.ini path that is not a file is passed over. Handing TLS a bundle that does not exist fails every connection, where leaving it unset still lets the platform's own certificate store be tried.

Parameters
$environment : Environment
$ini : callable(string): Array
Return values
array{0: ?string, 1: ?string}

numericId()

A numeric user id, or `null` for anything else — an `@name` can change hands.

private static numericId(string|null $value) : string|null
Parameters
$value : string|null
Return values
string|null
On this page

Search results