From e81f535f7528d46b77934e80f9ab7736a037375f Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Sun, 15 May 2022 15:42:53 +0200 Subject: [PATCH] New methods for SendingVideo - adding SendVideo by byte array - adding SendLocalVideo to send videofile from disk --- TelegramBotBase/Sessions/DeviceSession.cs | 74 ++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index bbe4e5a..059d040 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -453,7 +453,7 @@ namespace TelegramBotBase.Sessions /// /// Sends an video /// - /// + /// /// /// /// @@ -480,6 +480,78 @@ namespace TelegramBotBase.Sessions } } + /// + /// Sends an video + /// + /// + /// + /// + /// + /// + /// + public async Task SendVideo(String filename, byte[] video, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown) + { + if (this.ActiveForm == null) + return null; + + InlineKeyboardMarkup markup = buttons; + + try + { + MemoryStream ms = new MemoryStream(video); + + InputOnlineFile fts = new InputOnlineFile(ms, filename); + + var t = API(a => a.SendVideoAsync(this.DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification)); + + var o = GetOrigin(new StackTrace()); + OnMessageSent(new MessageSentEventArgs(await t, o)); + + return await t; + } + catch + { + return null; + } + } + + /// + /// Sends an local file as video + /// + /// + /// + /// + /// + /// + /// + public async Task SendLocalVideo(String filepath, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown) + { + if (this.ActiveForm == null) + return null; + + InlineKeyboardMarkup markup = buttons; + + try + { + FileStream fs = new FileStream(filepath, FileMode.Open); + + var filename = Path.GetFileName(filepath); + + InputOnlineFile fts = new InputOnlineFile(fs, filename); + + var t = API(a => a.SendVideoAsync(this.DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification)); + + var o = GetOrigin(new StackTrace()); + OnMessageSent(new MessageSentEventArgs(await t, o)); + + return await t; + } + catch + { + return null; + } + } + /// /// Sends an document ///