Compare commits

..
21 Commits
Author SHA1 Message Date
Florian Dahn 567a9f937f Update README.md 2020-11-23 13:51:25 +01:00
FlorianDahn 95b4ff77c5 Update README.md 2020-11-23 13:48:13 +01:00
FlorianDahn ba82c11d66 Update README.md 2020-11-23 13:46:28 +01:00
FlorianDahn c2e33da277 Adding SaveSessionState to SessionBase
Feature request: https://github.com/MajMcCloud/TelegramBotFramework/issues/2
2020-11-22 23:15:31 +01:00
FlorianDahn 259fa54236 Update ModalDialog.cs
- Adding await keyword
2020-11-03 23:52:35 +01:00
FlorianDahn f790a16e85 Merge branch 'master' of https://github.com/MajMcCloud/TelegramBotFramework 2020-11-03 20:38:40 +01:00
FlorianDahn 97fea333f7 Update ConfirmDialog.cs
- adding additional checks to ConfirmDialog
- adding AutoCloseOnClick property, to close this modal form after button click
2020-11-03 20:38:36 +01:00
FlorianDahn e1b31b0b9a Update PromptDialog.cs
- adding additional checks to promptdialog
2020-11-03 20:38:07 +01:00
Florian Dahn 7aca5a648f Update README.md 2020-10-31 16:22:47 +01:00
FlorianDahn f24c309f63 Update DeviceSession.cs
- adding ParseMode to Edit functions
- adding a Send method which the parameter of the DeviceId
2020-10-22 22:14:40 +02:00
FlorianDahn ba9fd8062c Update PromptDialog.cs
- added ReceivedMessage for further use
2020-10-20 19:11:04 +02:00
FlorianDahn b37c31f2bd Update BotBase.cs
- Bugfix, Unhandled actions has been producing a loop
2020-10-20 19:10:30 +02:00
FlorianDahn 2c34a178ee Update DeviceSession.cs
- adding caption parameter
2020-10-12 23:16:42 +02:00
FlorianDahn 2f030f3c12 Updates to ButtonGrid
- adding IsNavigationBarVisible property to ButtonGrid
- adding SubHeadLayout row for column "descriptions" like a table design
- uses FilterDuplicate with ByRow enabled to keep the full row on matches
2020-10-05 14:24:34 +02:00
FlorianDahn a364562fd3 Update ButtonForm.cs
- Modifying FilterDuplicate to allow full row filter or not
This will keep only the matches, or the full row where it matches.
2020-10-05 14:22:47 +02:00
FlorianDahn 8ef8733a2b Update DeviceSession.cs
- Adding the name parameter to SendPhoto methods
- Adding caption parameter to SendVideo methods
2020-10-05 14:21:57 +02:00
FlorianDahn 049b2081ec Update SessionBase.cs
Use of Fallback form has been missed in Session loading. Added now.
2020-09-15 23:46:30 +02:00
FlorianDahn 48b76a84be Update SessionBase.cs
- improving handling for Sessions loading with no default constructors available.
2020-09-15 16:42:40 +02:00
FlorianDahn 31c8231b2d Adding NavigationBarVisibility property to hide/show navigation buttons auto/never/always 2020-09-15 16:38:36 +02:00
FlorianDahn e9504f3b36 Update ButtonForm.cs
- adding method for adding one single button row
- fix for ToList method if no buttons are available
2020-09-15 16:36:54 +02:00
FlorianDahn 8592f4279d Update ButtonGrid.cs
Fix "Page 1 of 0" when no rows are existing.
2020-09-08 15:32:04 +02:00
10 changed files with 240 additions and 74 deletions
+8 -13
View File
@@ -159,17 +159,10 @@ public class StartForm : FormBase
}
//Gets invoked if the form gets opened (with Form.NavigateTo(NewForm))
public override async Task Opened()
{
//Opened() got replaced with event handler
}
//Closed() got replaced with event handler
//Gets invoked if the form gets leaved
public override async Task Closed()
{
}
//Gets invoked on every Message/Action/Data in this context
public override async Task Load(MessageResult message)
@@ -302,11 +295,13 @@ public class SimpleForm : AutoCleanForm
{
public SimpleForm()
{
this.DeleteSide = eSide.Both;
this.DeleteMode = eDeleteMode.OnLeavingForm;
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
this.Opened += SimpleForm_Opened;
}
public override async Task Opened()
private async Task SimpleForm_Opened(object sender, EventArgs e)
{
await this.Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
}
@@ -687,7 +682,7 @@ public async override Task Render(MessageResult message)
```
There is also a second example, where every of these 3 inputs gets requested by a different formular (class). Just for imagination of the possiblites.
Cause its to much Text, i didnt have added it here. You will find it under [TelegramBaseTest/Tests/Register/PerStep.cs](TelegramBaseTest/Tests/Register/PerStep.cs)
Cause its to much Text, i didnt have added it here. You will find it under [TelegramBotBaseTest/Tests/Register/PerStep.cs](TelegramBotBaseTest/Tests/Register/PerStep.cs)
Beginn there and navigate your way through these Steps in the subfolder.
+6 -11
View File
@@ -33,7 +33,7 @@ namespace TelegramBotBase
/// <summary>
/// List of all running/active sessions
/// </summary>
public SessionBase Sessions { get; set; }
public SessionBase<T> Sessions { get; set; }
/// <summary>
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
@@ -79,7 +79,8 @@ namespace TelegramBotBase
this.BotCommands = new List<BotCommand>();
this.Sessions = new SessionBase();
this.Sessions = new SessionBase<T>();
this.Sessions.BotBase = this;
}
/// <summary>
@@ -193,10 +194,7 @@ namespace TelegramBotBase
this.Client.TelegramClient.StopReceiving();
if (this.StateMachine != null)
{
this.Sessions.SaveSessionStates(this.StateMachine);
}
this.Sessions.SaveSessionStates();
}
/// <summary>
@@ -442,11 +440,8 @@ namespace TelegramBotBase
if (uhc.Handled)
{
if (ds.FormSwitched)
{
continue;
}
else
e.Handled = true;
if (!ds.FormSwitched)
{
break;
}
+71 -6
View File
@@ -65,6 +65,9 @@ namespace TelegramBotBase.Controls
public String SearchQuery { get; set; }
public eNavigationBarVisibility NavigationBarVisibility { get; set; } = eNavigationBarVisibility.always;
/// <summary>
/// Index of the current page
/// </summary>
@@ -83,6 +86,11 @@ namespace TelegramBotBase.Controls
/// </summary>
public List<ButtonBase> HeadLayoutButtonRow { get; set; }
/// <summary>
/// Layout of columns which should be displayed below the header
/// </summary>
public List<ButtonBase> SubHeadLayoutButtonRow { get; set; }
/// <summary>
/// Defines which type of Button Keyboard should be rendered.
/// </summary>
@@ -156,7 +164,9 @@ namespace TelegramBotBase.Controls
if (!result.IsFirstHandler)
return;
var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText) ?? ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText)
?? ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
if (button == null)
{
@@ -233,7 +243,9 @@ namespace TelegramBotBase.Controls
{
case eKeyboardType.InlineKeyBoard:
var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData) ?? ButtonsForm.ToList().FirstOrDefault(a => a.Value == result.RawData);
var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
?? ButtonsForm.ToList().FirstOrDefault(a => a.Value == result.RawData);
if (button == null)
{
@@ -323,7 +335,7 @@ namespace TelegramBotBase.Controls
if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
{
form = form.FilterDuplicate(this.SearchQuery);
form = form.FilterDuplicate(this.SearchQuery, true);
}
else
{
@@ -340,6 +352,18 @@ namespace TelegramBotBase.Controls
form.InsertButtonRow(0, this.HeadLayoutButtonRow);
}
if (this.SubHeadLayoutButtonRow != null && SubHeadLayoutButtonRow.Count > 0)
{
if (this.IsNavigationBarVisible)
{
form.InsertButtonRow(2, this.SubHeadLayoutButtonRow);
}
else
{
form.InsertButtonRow(1, this.SubHeadLayoutButtonRow);
}
}
switch (this.KeyboardType)
{
//Reply Keyboard could only be updated with a new keyboard.
@@ -413,13 +437,14 @@ namespace TelegramBotBase.Controls
bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
}
if (this.IsNavigationBarVisible)
{
//🔍
List<ButtonBase> lst = new List<ButtonBase>();
lst.Add(new ButtonBase(PreviousPageLabel, "$previous$"));
lst.Add(new ButtonBase(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"));
lst.Add(new ButtonBase(NextPageLabel, "$next$"));
if (this.EnableSearch)
{
lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
@@ -428,6 +453,7 @@ namespace TelegramBotBase.Controls
bf.InsertButtonRow(0, lst);
bf.AddButtonRow(lst);
}
return bf;
}
@@ -436,7 +462,25 @@ namespace TelegramBotBase.Controls
{
get
{
if ((this.KeyboardType == eKeyboardType.InlineKeyBoard && ButtonsForm.Rows > Constants.Telegram.MaxInlineKeyBoardRows) | (this.KeyboardType == eKeyboardType.ReplyKeyboard && ButtonsForm.Rows > Constants.Telegram.MaxReplyKeyboardRows))
if (this.KeyboardType == eKeyboardType.InlineKeyBoard && TotalRows > Constants.Telegram.MaxInlineKeyBoardRows)
{
return true;
}
if (this.KeyboardType == eKeyboardType.ReplyKeyboard && TotalRows > Constants.Telegram.MaxReplyKeyboardRows)
{
return true;
}
return false;
}
}
public bool IsNavigationBarVisible
{
get
{
if (this.NavigationBarVisibility == eNavigationBarVisibility.always | (this.NavigationBarVisibility == eNavigationBarVisibility.auto && PagingNecessary))
{
return true;
}
@@ -466,6 +510,18 @@ namespace TelegramBotBase.Controls
}
}
/// <summary>
/// Returns the number of all rows (layout + navigation + content);
/// </summary>
public int TotalRows
{
get
{
return this.LayoutRows + ButtonsForm.Rows;
}
}
/// <summary>
/// Contains the Number of Rows which are used by the layout.
/// </summary>
@@ -473,11 +529,17 @@ namespace TelegramBotBase.Controls
{
get
{
int layoutRows = 2;
int layoutRows = 0;
if (this.NavigationBarVisibility == eNavigationBarVisibility.always | this.NavigationBarVisibility == eNavigationBarVisibility.auto)
layoutRows += 2;
if (this.HeadLayoutButtonRow != null && this.HeadLayoutButtonRow.Count > 0)
layoutRows++;
if (this.SubHeadLayoutButtonRow != null && this.SubHeadLayoutButtonRow.Count > 0)
layoutRows++;
return layoutRows;
}
}
@@ -496,6 +558,9 @@ namespace TelegramBotBase.Controls
bf = bf.FilterDuplicate(this.SearchQuery);
}
if (bf.Rows == 0)
return 1;
return (int)Math.Ceiling((decimal)(bf.Rows / (decimal)(MaximumRow - 3)));
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace TelegramBotBase.Enums
{
public enum eNavigationBarVisibility
{
/// <summary>
/// Shows it depending on the amount of items.
/// </summary>
auto = 0,
/// <summary>
/// Will not show it at any time.
/// </summary>
never = 1,
/// <summary>
/// Will show it at any time.
/// </summary>
always = 2
}
}
+16 -2
View File
@@ -61,6 +61,11 @@ namespace TelegramBotBase.Form
this.DependencyControl = control;
}
public void AddButtonRow(String Text, String Value, String Url = null)
{
Buttons.Add(new List<ButtonBase>() { new ButtonBase(Text, Value, Url) });
}
public void AddButtonRow(IEnumerable<ButtonBase> row)
{
Buttons.Add(row.ToList());
@@ -129,7 +134,7 @@ namespace TelegramBotBase.Form
public List<ButtonBase> ToList()
{
return this.Buttons.Aggregate((a, b) => a.Union(b).ToList());
return this.Buttons.DefaultIfEmpty(new List<ButtonBase>()).Aggregate((a, b) => a.Union(b).ToList());
}
public InlineKeyboardButton[][] ToInlineButtonArray()
@@ -205,7 +210,7 @@ namespace TelegramBotBase.Form
/// Creates a copy of this form and filters by the parameter.
/// </summary>
/// <returns></returns>
public ButtonForm FilterDuplicate(String filter)
public ButtonForm FilterDuplicate(String filter, bool ByRow = false)
{
var bf = new ButtonForm()
{
@@ -221,8 +226,17 @@ namespace TelegramBotBase.Form
if (b2.Text.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) == -1)
continue;
//Copy full row, when at least one match has found.
if (ByRow)
{
lst.AddRange(b);
break;
}
else
{
lst.Add(b2);
}
}
if (lst.Count > 0)
bf.Buttons.Add(lst);
+14
View File
@@ -15,6 +15,11 @@ namespace TelegramBotBase.Form
{
public String Message { get; set; }
/// <summary>
/// Automatically close form on button click
/// </summary>
public bool AutoCloseOnClick { get; set; } = true;
public List<ButtonBase> Buttons { get; set; }
private EventHandlerList __Events { get; set; } = new EventHandlerList();
@@ -49,6 +54,12 @@ namespace TelegramBotBase.Form
public override async Task Action(MessageResult message)
{
if (message.Handled)
return;
if (!message.IsFirstHandler)
return;
var call = message.GetData<CallbackData>();
if (call == null)
return;
@@ -67,6 +78,9 @@ namespace TelegramBotBase.Form
}
OnButtonClicked(new ButtonClickedEventArgs(button));
if (AutoCloseOnClick)
await CloseForm();
}
+1 -1
View File
@@ -22,7 +22,7 @@ namespace TelegramBotBase.Form
await this.OnClosed(new EventArgs());
this.ParentForm?.ReturnFromModal(this);
await this.ParentForm?.ReturnFromModal(this);
}
}
}
+13
View File
@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Attributes;
using TelegramBotBase.Base;
@@ -25,6 +26,11 @@ namespace TelegramBotBase.Form
public String BackLabel { get; set; } = Localizations.Default.Language["PromptDialog_Back"];
/// <summary>
/// Contains the RAW received message.
/// </summary>
public Message ReceivedMessage { get; set; }
public PromptDialog()
{
@@ -40,6 +46,9 @@ namespace TelegramBotBase.Form
if (message.Handled)
return;
if (!message.IsFirstHandler)
return;
if (this.ShowBackButton && message.MessageText == BackLabel)
{
await this.CloseForm();
@@ -50,6 +59,8 @@ namespace TelegramBotBase.Form
if (this.Value == null)
{
this.Value = message.MessageText;
ReceivedMessage = message.Message;
}
@@ -73,6 +84,8 @@ namespace TelegramBotBase.Form
}
message.Handled = true;
OnCompleted(new EventArgs());
await this.CloseForm();
+34 -2
View File
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using TelegramBotBase.Args;
@@ -14,12 +16,15 @@ namespace TelegramBotBase
/// <summary>
/// Base class for managing all active sessions
/// </summary>
public class SessionBase
public class SessionBase<T>
where T : FormBase
{
public MessageClient Client { get; set; }
public Dictionary<long, DeviceSession> SessionList { get; set; }
public BotBase<T> BotBase { get; set; }
public SessionBase()
{
@@ -130,7 +135,22 @@ namespace TelegramBotBase
continue;
}
var form = t.GetConstructor(new Type[] { }).Invoke(new object[] { }) as FormBase;
var form = t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase;
//No default constructor, fallback
if (form == null)
{
if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
continue;
form = statemachine.FallbackStateForm.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase;
//Fallback failed, due missing default constructor
if (form == null)
continue;
}
if (s.Values != null && s.Values.Count > 0)
{
@@ -278,5 +298,17 @@ namespace TelegramBotBase
statemachine.SaveFormStates(new SaveStatesEventArgs(sc));
}
/// <summary>
/// Saves all open states into the machine.
/// </summary>
public void SaveSessionStates()
{
if (this.BotBase.StateMachine == null)
return;
this.SaveSessionStates(this.BotBase.StateMachine);
}
}
}
+29 -16
View File
@@ -143,7 +143,7 @@ namespace TelegramBotBase.Sessions
/// <param name="text"></param>
/// <param name="buttons"></param>
/// <returns></returns>
public async Task<Message> Edit(int messageId, String text, ButtonForm buttons = null)
public async Task<Message> Edit(int messageId, String text, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Default)
{
InlineKeyboardMarkup markup = buttons;
@@ -154,7 +154,7 @@ namespace TelegramBotBase.Sessions
try
{
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, replyMarkup: markup);
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, parseMode, replyMarkup: markup);
}
catch
{
@@ -172,7 +172,7 @@ namespace TelegramBotBase.Sessions
/// <param name="text"></param>
/// <param name="buttons"></param>
/// <returns></returns>
public async Task<Message> Edit(int messageId, String text, InlineKeyboardMarkup markup)
public async Task<Message> Edit(int messageId, String text, InlineKeyboardMarkup markup, ParseMode parseMode = ParseMode.Default)
{
if (text.Length > Constants.Telegram.MaxMessageLength)
{
@@ -181,7 +181,7 @@ namespace TelegramBotBase.Sessions
try
{
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, replyMarkup: markup);
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, parseMode, replyMarkup: markup);
}
catch
{
@@ -199,7 +199,7 @@ namespace TelegramBotBase.Sessions
/// <param name="text"></param>
/// <param name="buttons"></param>
/// <returns></returns>
public async Task<Message> Edit(Message message, ButtonForm buttons = null)
public async Task<Message> Edit(Message message, ButtonForm buttons = null, ParseMode parseMode = ParseMode.Default)
{
InlineKeyboardMarkup markup = buttons;
@@ -210,7 +210,7 @@ namespace TelegramBotBase.Sessions
try
{
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, replyMarkup: markup);
return await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, parseMode, replyMarkup: markup);
}
catch
{
@@ -250,7 +250,7 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> Send(String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true)
public async Task<Message> Send(long deviceId, String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true)
{
if (this.ActiveForm == null)
return null;
@@ -271,7 +271,7 @@ namespace TelegramBotBase.Sessions
try
{
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
m = await (this.Client.TelegramClient.SendTextMessageAsync(deviceId, text, parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
OnMessageSent(new MessageSentEventArgs(m));
}
@@ -287,6 +287,19 @@ namespace TelegramBotBase.Sessions
return m;
}
/// <summary>
/// Sends a simple text message
/// </summary>
/// <param name="text"></param>
/// <param name="buttons"></param>
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> Send(String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default, bool MarkdownV2AutoEscape = true)
{
return await Send(this.DeviceId, text, buttons, replyTo, disableNotification, parseMode, MarkdownV2AutoEscape);
}
/// <summary>
/// Sends a simple text message
/// </summary>
@@ -381,7 +394,7 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendPhoto(InputOnlineFile file, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
public async Task<Message> SendPhoto(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
{
if (this.ActiveForm == null)
return null;
@@ -392,7 +405,7 @@ namespace TelegramBotBase.Sessions
try
{
m = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
m = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, caption: caption, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
OnMessageSent(new MessageSentEventArgs(m));
}
@@ -417,13 +430,13 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendPhoto(Image image, String name, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
public async Task<Message> SendPhoto(Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
{
using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png))
{
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
return await SendPhoto(fts, buttons, replyTo, disableNotification);
return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
}
}
@@ -436,13 +449,13 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendPhoto(Bitmap image, String name, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
public async Task<Message> SendPhoto(Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
{
using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png))
{
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
return await SendPhoto(fts, buttons, replyTo, disableNotification);
return await SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
}
}
@@ -454,7 +467,7 @@ namespace TelegramBotBase.Sessions
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendVideo(InputOnlineFile file, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
public async Task<Message> SendVideo(InputOnlineFile file, String caption = null, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
{
if (this.ActiveForm == null)
return null;
@@ -465,7 +478,7 @@ namespace TelegramBotBase.Sessions
try
{
m = await this.Client.TelegramClient.SendVideoAsync(this.DeviceId, file, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
m = await this.Client.TelegramClient.SendVideoAsync(this.DeviceId, file, caption: caption, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
OnMessageSent(new MessageSentEventArgs(m));
}