Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
567a9f937f | ||
|
|
95b4ff77c5 | ||
|
|
ba82c11d66 | ||
|
|
c2e33da277 | ||
|
|
259fa54236 | ||
|
|
f790a16e85 | ||
|
|
97fea333f7 | ||
|
|
e1b31b0b9a | ||
|
|
7aca5a648f | ||
|
|
f24c309f63 | ||
|
|
ba9fd8062c | ||
|
|
b37c31f2bd | ||
|
|
2c34a178ee | ||
|
|
2f030f3c12 | ||
|
|
a364562fd3 | ||
|
|
8ef8733a2b | ||
|
|
049b2081ec | ||
|
|
48b76a84be | ||
|
|
31c8231b2d | ||
|
|
e9504f3b36 | ||
|
|
8592f4279d |
@@ -159,17 +159,10 @@ public class StartForm : FormBase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gets invoked if the form gets opened (with Form.NavigateTo(NewForm))
|
//Opened() got replaced with event handler
|
||||||
public override async Task Opened()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
//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
|
//Gets invoked on every Message/Action/Data in this context
|
||||||
public override async Task Load(MessageResult message)
|
public override async Task Load(MessageResult message)
|
||||||
@@ -302,11 +295,13 @@ public class SimpleForm : AutoCleanForm
|
|||||||
{
|
{
|
||||||
public SimpleForm()
|
public SimpleForm()
|
||||||
{
|
{
|
||||||
this.DeleteSide = eSide.Both;
|
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
|
||||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
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");
|
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.
|
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.
|
Beginn there and navigate your way through these Steps in the subfolder.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace TelegramBotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of all running/active sessions
|
/// List of all running/active sessions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SessionBase Sessions { get; set; }
|
public SessionBase<T> Sessions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
/// 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.BotCommands = new List<BotCommand>();
|
||||||
|
|
||||||
this.Sessions = new SessionBase();
|
this.Sessions = new SessionBase<T>();
|
||||||
|
this.Sessions.BotBase = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -193,10 +194,7 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
this.Client.TelegramClient.StopReceiving();
|
this.Client.TelegramClient.StopReceiving();
|
||||||
|
|
||||||
if (this.StateMachine != null)
|
this.Sessions.SaveSessionStates();
|
||||||
{
|
|
||||||
this.Sessions.SaveSessionStates(this.StateMachine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -442,11 +440,8 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
if (uhc.Handled)
|
if (uhc.Handled)
|
||||||
{
|
{
|
||||||
if (ds.FormSwitched)
|
e.Handled = true;
|
||||||
{
|
if (!ds.FormSwitched)
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
public String SearchQuery { get; set; }
|
public String SearchQuery { get; set; }
|
||||||
|
|
||||||
|
public eNavigationBarVisibility NavigationBarVisibility { get; set; } = eNavigationBarVisibility.always;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Index of the current page
|
/// Index of the current page
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -83,6 +86,11 @@ namespace TelegramBotBase.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ButtonBase> HeadLayoutButtonRow { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Defines which type of Button Keyboard should be rendered.
|
/// Defines which type of Button Keyboard should be rendered.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -156,7 +164,9 @@ namespace TelegramBotBase.Controls
|
|||||||
if (!result.IsFirstHandler)
|
if (!result.IsFirstHandler)
|
||||||
return;
|
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)
|
if (button == null)
|
||||||
{
|
{
|
||||||
@@ -233,7 +243,9 @@ namespace TelegramBotBase.Controls
|
|||||||
{
|
{
|
||||||
case eKeyboardType.InlineKeyBoard:
|
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)
|
if (button == null)
|
||||||
{
|
{
|
||||||
@@ -323,7 +335,7 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
|
if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
|
||||||
{
|
{
|
||||||
form = form.FilterDuplicate(this.SearchQuery);
|
form = form.FilterDuplicate(this.SearchQuery, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -340,6 +352,18 @@ namespace TelegramBotBase.Controls
|
|||||||
form.InsertButtonRow(0, this.HeadLayoutButtonRow);
|
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)
|
switch (this.KeyboardType)
|
||||||
{
|
{
|
||||||
//Reply Keyboard could only be updated with a new keyboard.
|
//Reply Keyboard could only be updated with a new keyboard.
|
||||||
@@ -413,13 +437,14 @@ namespace TelegramBotBase.Controls
|
|||||||
bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
|
bf.AddButtonRow(new ButtonBase(NoItemsLabel, "$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.IsNavigationBarVisible)
|
||||||
|
{
|
||||||
//🔍
|
//🔍
|
||||||
List<ButtonBase> lst = new List<ButtonBase>();
|
List<ButtonBase> lst = new List<ButtonBase>();
|
||||||
lst.Add(new ButtonBase(PreviousPageLabel, "$previous$"));
|
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(String.Format(Localizations.Default.Language["ButtonGrid_CurrentPage"], this.CurrentPageIndex + 1, this.PageCount), "$site$"));
|
||||||
lst.Add(new ButtonBase(NextPageLabel, "$next$"));
|
lst.Add(new ButtonBase(NextPageLabel, "$next$"));
|
||||||
|
|
||||||
|
|
||||||
if (this.EnableSearch)
|
if (this.EnableSearch)
|
||||||
{
|
{
|
||||||
lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
|
lst.Insert(2, new ButtonBase("🔍 " + (this.SearchQuery ?? ""), "$search$"));
|
||||||
@@ -428,6 +453,7 @@ namespace TelegramBotBase.Controls
|
|||||||
bf.InsertButtonRow(0, lst);
|
bf.InsertButtonRow(0, lst);
|
||||||
|
|
||||||
bf.AddButtonRow(lst);
|
bf.AddButtonRow(lst);
|
||||||
|
}
|
||||||
|
|
||||||
return bf;
|
return bf;
|
||||||
}
|
}
|
||||||
@@ -436,7 +462,25 @@ namespace TelegramBotBase.Controls
|
|||||||
{
|
{
|
||||||
get
|
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;
|
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>
|
/// <summary>
|
||||||
/// Contains the Number of Rows which are used by the layout.
|
/// Contains the Number of Rows which are used by the layout.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -473,11 +529,17 @@ namespace TelegramBotBase.Controls
|
|||||||
{
|
{
|
||||||
get
|
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)
|
if (this.HeadLayoutButtonRow != null && this.HeadLayoutButtonRow.Count > 0)
|
||||||
layoutRows++;
|
layoutRows++;
|
||||||
|
|
||||||
|
if (this.SubHeadLayoutButtonRow != null && this.SubHeadLayoutButtonRow.Count > 0)
|
||||||
|
layoutRows++;
|
||||||
|
|
||||||
return layoutRows;
|
return layoutRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,6 +558,9 @@ namespace TelegramBotBase.Controls
|
|||||||
bf = bf.FilterDuplicate(this.SearchQuery);
|
bf = bf.FilterDuplicate(this.SearchQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bf.Rows == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
return (int)Math.Ceiling((decimal)(bf.Rows / (decimal)(MaximumRow - 3)));
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,6 +61,11 @@ namespace TelegramBotBase.Form
|
|||||||
this.DependencyControl = control;
|
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)
|
public void AddButtonRow(IEnumerable<ButtonBase> row)
|
||||||
{
|
{
|
||||||
Buttons.Add(row.ToList());
|
Buttons.Add(row.ToList());
|
||||||
@@ -129,7 +134,7 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
public List<ButtonBase> ToList()
|
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()
|
public InlineKeyboardButton[][] ToInlineButtonArray()
|
||||||
@@ -205,7 +210,7 @@ namespace TelegramBotBase.Form
|
|||||||
/// Creates a copy of this form and filters by the parameter.
|
/// Creates a copy of this form and filters by the parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ButtonForm FilterDuplicate(String filter)
|
public ButtonForm FilterDuplicate(String filter, bool ByRow = false)
|
||||||
{
|
{
|
||||||
var bf = new ButtonForm()
|
var bf = new ButtonForm()
|
||||||
{
|
{
|
||||||
@@ -221,8 +226,17 @@ namespace TelegramBotBase.Form
|
|||||||
if (b2.Text.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) == -1)
|
if (b2.Text.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//Copy full row, when at least one match has found.
|
||||||
|
if (ByRow)
|
||||||
|
{
|
||||||
|
lst.AddRange(b);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
lst.Add(b2);
|
lst.Add(b2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lst.Count > 0)
|
if (lst.Count > 0)
|
||||||
bf.Buttons.Add(lst);
|
bf.Buttons.Add(lst);
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ namespace TelegramBotBase.Form
|
|||||||
{
|
{
|
||||||
public String Message { get; set; }
|
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; }
|
public List<ButtonBase> Buttons { get; set; }
|
||||||
|
|
||||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||||
@@ -49,6 +54,12 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
|
if (message.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!message.IsFirstHandler)
|
||||||
|
return;
|
||||||
|
|
||||||
var call = message.GetData<CallbackData>();
|
var call = message.GetData<CallbackData>();
|
||||||
if (call == null)
|
if (call == null)
|
||||||
return;
|
return;
|
||||||
@@ -67,6 +78,9 @@ namespace TelegramBotBase.Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
OnButtonClicked(new ButtonClickedEventArgs(button));
|
OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||||
|
|
||||||
|
if (AutoCloseOnClick)
|
||||||
|
await CloseForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace TelegramBotBase.Form
|
|||||||
await this.OnClosed(new EventArgs());
|
await this.OnClosed(new EventArgs());
|
||||||
|
|
||||||
|
|
||||||
this.ParentForm?.ReturnFromModal(this);
|
await this.ParentForm?.ReturnFromModal(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.ComponentModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
using TelegramBotBase.Attributes;
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
@@ -25,6 +26,11 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
public String BackLabel { get; set; } = Localizations.Default.Language["PromptDialog_Back"];
|
public String BackLabel { get; set; } = Localizations.Default.Language["PromptDialog_Back"];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the RAW received message.
|
||||||
|
/// </summary>
|
||||||
|
public Message ReceivedMessage { get; set; }
|
||||||
|
|
||||||
public PromptDialog()
|
public PromptDialog()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -40,6 +46,9 @@ namespace TelegramBotBase.Form
|
|||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!message.IsFirstHandler)
|
||||||
|
return;
|
||||||
|
|
||||||
if (this.ShowBackButton && message.MessageText == BackLabel)
|
if (this.ShowBackButton && message.MessageText == BackLabel)
|
||||||
{
|
{
|
||||||
await this.CloseForm();
|
await this.CloseForm();
|
||||||
@@ -50,6 +59,8 @@ namespace TelegramBotBase.Form
|
|||||||
if (this.Value == null)
|
if (this.Value == null)
|
||||||
{
|
{
|
||||||
this.Value = message.MessageText;
|
this.Value = message.MessageText;
|
||||||
|
|
||||||
|
ReceivedMessage = message.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,6 +84,8 @@ namespace TelegramBotBase.Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message.Handled = true;
|
||||||
|
|
||||||
OnCompleted(new EventArgs());
|
OnCompleted(new EventArgs());
|
||||||
|
|
||||||
await this.CloseForm();
|
await this.CloseForm();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
@@ -14,12 +16,15 @@ namespace TelegramBotBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for managing all active sessions
|
/// Base class for managing all active sessions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SessionBase
|
public class SessionBase<T>
|
||||||
|
where T : FormBase
|
||||||
{
|
{
|
||||||
public MessageClient Client { get; set; }
|
public MessageClient Client { get; set; }
|
||||||
|
|
||||||
public Dictionary<long, DeviceSession> SessionList { get; set; }
|
public Dictionary<long, DeviceSession> SessionList { get; set; }
|
||||||
|
|
||||||
|
public BotBase<T> BotBase { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public SessionBase()
|
public SessionBase()
|
||||||
{
|
{
|
||||||
@@ -130,7 +135,22 @@ namespace TelegramBotBase
|
|||||||
continue;
|
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)
|
if (s.Values != null && s.Values.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -278,5 +298,17 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
statemachine.SaveFormStates(new SaveStatesEventArgs(sc));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="buttons"></param>
|
/// <param name="buttons"></param>
|
||||||
/// <returns></returns>
|
/// <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;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
@@ -172,7 +172,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="buttons"></param>
|
/// <param name="buttons"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
if (text.Length > Constants.Telegram.MaxMessageLength)
|
||||||
{
|
{
|
||||||
@@ -181,7 +181,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
@@ -199,7 +199,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <param name="buttons"></param>
|
/// <param name="buttons"></param>
|
||||||
/// <returns></returns>
|
/// <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;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
@@ -250,7 +250,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
if (this.ActiveForm == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -271,7 +271,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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));
|
OnMessageSent(new MessageSentEventArgs(m));
|
||||||
}
|
}
|
||||||
@@ -287,6 +287,19 @@ namespace TelegramBotBase.Sessions
|
|||||||
return m;
|
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>
|
/// <summary>
|
||||||
/// Sends a simple text message
|
/// Sends a simple text message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -381,7 +394,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
if (this.ActiveForm == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -392,7 +405,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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));
|
OnMessageSent(new MessageSentEventArgs(m));
|
||||||
}
|
}
|
||||||
@@ -417,13 +430,13 @@ namespace TelegramBotBase.Sessions
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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))
|
using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png))
|
||||||
{
|
{
|
||||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
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="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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))
|
using (var fileStream = Tools.Images.ToStream(image, ImageFormat.Png))
|
||||||
{
|
{
|
||||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
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="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
if (this.ActiveForm == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -465,7 +478,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
|
|
||||||
try
|
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));
|
OnMessageSent(new MessageSentEventArgs(m));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user