mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-08-29 12:26:25 +00:00
update readmes
This commit is contained in:
54
LivePhotosBot/README.md
Normal file
54
LivePhotosBot/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# LivePhotosBot
|
||||
|
||||
This long-polling example demonstrates receiving, sending, grouping, editing, and selling Telegram Live Photos. It also shows how a regular photo and video from one album can be reused as the two parts of a Live Photo.
|
||||
|
||||
## Behavior, commands, and triggers
|
||||
|
||||
The bot defines no commands. It prints every incoming update to standard output in addition to the trigger-specific output below.
|
||||
|
||||
| Trigger | Behavior |
|
||||
| --- | --- |
|
||||
| Standalone Live Photo | Logs its file identifiers, dimensions, duration, thumbnail, MIME type, size, and caption. It resends the Live Photo, sends the same media as paid content costing 1 Star, and then edits the resent message with `TelegramMediaLivePhoto`. |
|
||||
| Live Photo gallery | Logs every item and resends the gallery with `sendMediaGroup`. |
|
||||
| Paid-media message containing Live Photos | Logs each Live Photo and replies with the number found. Paid-media messages without a Live Photo get no reply from this handler. |
|
||||
| Edited Live Photo | Logs the file ID and updated caption. |
|
||||
| Media group containing at least one regular photo and one regular video | Uses the first photo as the cover and the first video as the motion part, then replies with a Live Photo. Albums missing either type are ignored by this handler. |
|
||||
|
||||
## Live Photo handling
|
||||
|
||||
The bot does not download or transform media. It reuses Telegram file IDs: the received Live Photo is passed directly to `sendLivePhoto`, while its main file ID and thumbnail file ID are used to construct `TelegramMediaLivePhoto` and `TelegramPaidMediaLivePhoto`. If Telegram supplies no thumbnail, the code falls back to the main file ID for the photo field.
|
||||
|
||||
The standalone handler performs its requests in order: resend, send paid media, then edit the resent message. Consequently, a failure while sending paid media prevents the edit for that update.
|
||||
|
||||
## Telegram setup and permissions
|
||||
|
||||
1. Create a bot with BotFather and obtain its token.
|
||||
2. Add the bot to the chat where you want to exercise the example and allow it to send messages and media.
|
||||
3. In a group, make the bot an administrator or disable Group Privacy Mode so it receives ordinary, non-command media albums and Live Photos.
|
||||
4. To complete the standalone Live Photo flow, use a channel and grant the bot permission to post there: Telegram restricts `sendPaidMedia` to channel chats. In other chat types, the initial resend may succeed but the paid-media request can fail before the edit runs.
|
||||
|
||||
The program does not request or validate permissions itself. API errors use the library's normal handling.
|
||||
|
||||
## Arguments
|
||||
|
||||
The first argument is the required bot token. Optional flags are exact and case-sensitive, can follow the token in either order, and unknown extra arguments are ignored.
|
||||
|
||||
| Argument | Effect |
|
||||
| --- | --- |
|
||||
| `<BOT_TOKEN>` | Bot token. Omitting it fails before polling starts. |
|
||||
| `debug` | Prints formatted KSLog diagnostics to standard output. |
|
||||
| `testServer` | Uses Telegram's Bot API test environment. |
|
||||
|
||||
## Launch
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
./gradlew :LivePhotosBot:run --args="<BOT_TOKEN>"
|
||||
```
|
||||
|
||||
For example, to enable both optional flags:
|
||||
|
||||
```bash
|
||||
./gradlew :LivePhotosBot:run --args="<BOT_TOKEN> debug testServer"
|
||||
```
|
||||
@@ -37,16 +37,10 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
/**
|
||||
* This bot demonstrates Live Photos support introduced in Telegram Bot API.
|
||||
* Starts the long-polling example for receiving, sending, grouping, editing, and selling Live Photos.
|
||||
*
|
||||
* Key concepts demonstrated:
|
||||
* - [dev.inmo.tgbotapi.types.files.LivePhotoFile] — the LivePhoto class: a photo with an attached short video
|
||||
* - [TelegramMediaLivePhoto] — InputMediaLivePhoto: used in sendMediaGroup and editMessageMedia
|
||||
* - [LivePhotoContent] — the content type carried in Message.live_photo / ExternalReplyInfo.live_photo
|
||||
* - [sendLivePhoto] — method to send a live photo
|
||||
* - [PaidMedia.LivePhoto] — PaidMediaLivePhoto: a live photo inside paid media content
|
||||
* - [TelegramPaidMediaLivePhoto] — InputPaidMediaLivePhoto: used in sendPaidMedia
|
||||
* - sendMediaGroup and editMessageMedia with live photos
|
||||
* @param args bot token followed by the optional, case-sensitive `debug` and `testServer` flags; unknown trailing
|
||||
* arguments are ignored
|
||||
*/
|
||||
@OptIn(RiskFeature::class)
|
||||
suspend fun main(vararg args: String) {
|
||||
|
||||
Reference in New Issue
Block a user