Download the PHP package toropyga/telegram without Composer
On this page you can find all versions of the php package toropyga/telegram. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package telegram
Telegram
Sending messages on behalf of a Telegram bot
Content
- General description
- Installation
- Configuration
- Work description
- Including the class
- Initialising the class
- Setting the method of interaction with the Telegram API when sending messages
- Supported methods
- Setting the parse mode
- Converting text markup
- Setting the bot token
- Configuring the webhook
- Removing the webhook
- Getting webhook information
- Setting the recipient chat ID
- Enabling debug logging
- Getting logs
- Sending a text message
- Sending a file
General description
PHP library for sending Telegram bot messages, media files, and webhook requests through the Telegram Bot API.
To work, you need PHP version 8.1 or higher and the json, curl, and dom extensions.
The package also uses Base and NetContent.
The Telegram class remains the backward-compatible facade. Its responsibilities are split into TelegramMessageSender, TelegramWebhook, TelegramTextConverter, and TelegramPayloadBuilder.
Installation
Install the package with Composer:
Configuration
Default values can be supplied to the constructor or configured with constants declared before creating the class:
TELEGRAM_TOKEN- Telegram bot token;TELEGRAM_ID- recipient chat ID;TELEGRAM_DEBUG- enable or disable debug logging;TELEGRAM_LOG_NAME- log file name.
Work description
Including the class
or use composer
Initialising the class
or with automatic connection of the NetContent class
or use constants configured before creating the class
Setting the method of interaction with the Telegram API when sending messages
Supported methods
- 'sendMessage' - send a text message;
- 'sendPhoto' - send a photo or image;
- 'sendDocument' - send a document;
- 'sendVideo' - send a video;
- 'sendAudio' - send an audio file;
- 'sendVoice' - send a voice message;
-
'sendAnimation' - send an animation.
Setting the parse mode
Supported values are HTML, Markdown, MarkdownV2, and an empty string for plain text.
Converting text markup
The class provides static helpers for converting between HTML, Telegram Markdown, and MarkdownV2:
For custom conversions, use convertText($text, $from, $to). Supported formats are html, markdown, markdownv2, and plain.
Setting the bot token
Configuring the webhook
Removing the webhook
Getting webhook information
Setting the recipient chat ID
Enabling debug logging
When enabled, debug messages are stored in the internal log. Do not log bot tokens in production.
Getting logs
Returns the event log and configured log file name.
Sending a text message
Sending a message with the configured default parameters:
Sending a file
Sending a document to a user:
Sending a photo with the configured default parameters:
All versions of telegram with dependencies
toropyga/base Version ^2.0.0
toropyga/netcontent Version ^5.0.0
ext-json Version *
ext-curl Version *
ext-dom Version *