From e9543a690b1a332727d8ac1d054b59c48a3efe07 Mon Sep 17 00:00:00 2001
From: Wizou <11647984+wiz0u@users.noreply.github.com>
Date: Fri, 25 Jul 2025 01:03:30 +0200
Subject: [PATCH] Examples for download abort, and uploading streamable video
(fix #325, thx @patelriki13)
---
.github/workflows/telegram-api.yml | 3 ++-
EXAMPLES.md | 37 +++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/telegram-api.yml b/.github/workflows/telegram-api.yml
index 9a69fd9..efd921a 100644
--- a/.github/workflows/telegram-api.yml
+++ b/.github/workflows/telegram-api.yml
@@ -12,7 +12,7 @@ jobs:
if: contains(github.event.issue.labels.*.name, 'telegram api')
runs-on: ubuntu-latest
steps:
- - uses: dessant/support-requests@v3.0.0
+ - uses: dessant/support-requests@v4
with:
support-label: 'telegram api'
issue-comment: >
@@ -26,3 +26,4 @@ jobs:
If the above links didn't answer your problem, [click here to ask your question on **StackOverflow**](https://stackoverflow.com/questions/ask?tags=c%23+wtelegramclient+telegram-api) so the whole community can help and benefit.
close-issue: true
+ issue-close-reason: 'not planned'
diff --git a/EXAMPLES.md b/EXAMPLES.md
index e32e10d..ac2daf1 100644
--- a/EXAMPLES.md
+++ b/EXAMPLES.md
@@ -210,7 +210,7 @@ that simplifies the download of a photo/document/file once you get a reference t
See [Examples/Program_DownloadSavedMedia.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_DownloadSavedMedia.cs?ts=4#L28) that download all media files you forward to yourself (Saved Messages)
-_Note: To abort an ongoing download, you can throw an exception via the `progress` callback argument._
+_Note: To abort an ongoing download, you can throw an exception via the `progress` callback argument. Example: `(t,s) => ct.ThrowIfCancellationRequested()`_
## Upload a media file and post it with caption to a chat
@@ -224,6 +224,41 @@ var inputFile = await client.UploadFileAsync(Filepath);
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
```
+
+## Upload a streamable video with optional custom thumbnail
+```csharp
+var chats = await client.Messages_GetAllChats();
+InputPeer peer = chats.chats[1234567890]; // the chat we want
+const string videoPath = @"C:\...\video.mp4";
+const string thumbnailPath = @"C:\...\thumbnail.jpg";
+
+// Extract video information using FFMpegCore or similar library
+var mediaInfo = await FFmpeg.GetMediaInfo(videoPath);
+var videoStream = mediaInfo.VideoStreams.FirstOrDefault();
+int width = videoStream?.Width ?? 0;
+int height = videoStream?.Height ?? 0;
+int duration = (int)mediaInfo.Duration.TotalSeconds;
+
+// Upload video file
+var inputFile = await Client.UploadFileAsync(videoPath);
+
+// Prepare InputMedia structure with video attributes
+var media = new InputMediaUploadedDocument(inputFile, "video/mp4",
+ new DocumentAttributeVideo { w = width, h = height, duration = duration,
+ flags = DocumentAttributeVideo.Flags.supports_streaming });
+if (thumbnailPath != null)
+{
+ // upload custom thumbnail and complete InputMedia structure
+ var inputThumb = await client.UploadFileAsync(thumbnailPath);
+ media.thumb = inputThumb;
+ media.flags |= InputMediaUploadedDocument.Flags.has_thumb;
+}
+
+// Send the media message
+await client.SendMessageAsync(peer, "caption", media);
+```
+*Note: This example requires FFMpegCore NuGet package for video metadata extraction. You can also manually set width, height, and duration if you know the video properties.*
+
## Send a grouped media album using photos from various sources
```csharp