Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d22cdd82 | ||
|
|
ee4a3d765c | ||
|
|
703c99eb8d | ||
|
|
138fee9772 | ||
|
|
d60399514f | ||
|
|
ae0fa3b0e3 | ||
|
|
6a2ac7a309 | ||
|
|
1a76b2b3f8 | ||
|
|
5893108bd3 | ||
|
|
d668f57711 | ||
|
|
56c7754408 | ||
|
|
805ffb9ec7 | ||
|
|
aeddd82ea9 | ||
|
|
1ec14ce680 |
@@ -17,6 +17,23 @@ Download a release: [Releases](https://github.com/MajMcCloud/TelegramBotFramewor
|
||||
|
||||
---
|
||||
|
||||
Donations
|
||||
|
||||
Bitcoin: 1NqyGWmZg8HLp9qQELbf6bChEoba3mxaFc
|
||||
|
||||
ETH: 0x795B70CFC27C69603ce115F2b450cbAC5a5460D0
|
||||
|
||||
Litecoin: LM5iCN6Nz22wAi8LSFnKgdGGWEtxWfJZXv
|
||||
|
||||
DASH: Xb2qyVefvbKTXusHoxZ4Soja2S6R4vLsSr
|
||||
|
||||
Paypal: https://paypal.me/majmccloud
|
||||
|
||||
|
||||
Thanks !
|
||||
|
||||
---
|
||||
|
||||
## Index
|
||||
- [Introduction](#introduction)
|
||||
- [How to Start](#how-to-start)
|
||||
@@ -46,7 +63,9 @@ Download a release: [Releases](https://github.com/MajMcCloud/TelegramBotFramewor
|
||||
|
||||
* [MonthPicker](#month-picker)
|
||||
|
||||
+ [TreeView](#tree-view)
|
||||
* [TreeView](#tree-view)
|
||||
|
||||
* [ToggleButton](#toggle-button)
|
||||
|
||||
---
|
||||
|
||||
@@ -715,6 +734,7 @@ await this.NavigateTo(pd);
|
||||
### Calendar Picker
|
||||
<img src="images/calendarpicker.PNG?raw=true" />
|
||||
|
||||
<img src="images/calendarpicker.gif?raw=true" />
|
||||
|
||||
### Month Picker
|
||||
<img src="images/monthpicker1.PNG?raw=true" />
|
||||
@@ -728,6 +748,9 @@ await this.NavigateTo(pd);
|
||||
<img src="images/treeview4.PNG?raw=true" />
|
||||
|
||||
|
||||
### Toggle Button
|
||||
<img src="images/togglebutton.gif?raw=true" />
|
||||
|
||||
---
|
||||
|
||||
I will add more notes to it soon, so stay tuned.
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Controls;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBaseTest.Tests.Controls
|
||||
{
|
||||
public class ToggleButtons : AutoCleanForm
|
||||
{
|
||||
public ToggleButtons()
|
||||
{
|
||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
||||
|
||||
this.Init += ToggleButtons_Init;
|
||||
}
|
||||
|
||||
private async Task ToggleButtons_Init(object sender, TelegramBotBase.Base.InitEventArgs e)
|
||||
{
|
||||
|
||||
var tb = new ToggleButton();
|
||||
tb.Checked = true;
|
||||
tb.Toggled += Tb_Toggled;
|
||||
|
||||
this.AddControl(tb);
|
||||
|
||||
tb = new ToggleButton();
|
||||
tb.Checked = false;
|
||||
tb.Toggled += Tb_Toggled;
|
||||
|
||||
this.AddControl(tb);
|
||||
|
||||
tb = new ToggleButton();
|
||||
tb.Checked = true;
|
||||
tb.Toggled += Tb_Toggled;
|
||||
|
||||
this.AddControl(tb);
|
||||
|
||||
}
|
||||
|
||||
private void Tb_Toggled(object sender, EventArgs e)
|
||||
{
|
||||
var tb = sender as ToggleButton;
|
||||
Console.WriteLine(tb.ID.ToString() + " was pressed, and toggled to " + (tb.Checked ? "Checked" : "Unchecked"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,16 @@ namespace TelegramBaseTest.Tests
|
||||
|
||||
await this.NavigateTo(tree);
|
||||
|
||||
break;
|
||||
|
||||
case "togglebuttons":
|
||||
|
||||
message.Handled = true;
|
||||
|
||||
var tb = new Controls.ToggleButtons();
|
||||
|
||||
await this.NavigateTo(tb);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -138,6 +148,8 @@ namespace TelegramBaseTest.Tests
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#10 TreeView", new CallbackData("a", "treeview").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#11 ToggleButtons", new CallbackData("a", "togglebuttons").Serialize()));
|
||||
|
||||
await this.Device.Send("Choose your test:", btn);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="net452" />
|
||||
<package id="Telegram.Bot" version="14.10.0" targetFramework="net452" />
|
||||
<package id="Telegram.Bot" version="14.12.0" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -15,18 +15,28 @@ namespace TelegramBotBase.Base
|
||||
|
||||
public int ID { get; set; }
|
||||
|
||||
public String ControlID
|
||||
{
|
||||
get
|
||||
{
|
||||
return "#c" + this.ID.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the control should be rendered and invoked with actions
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public virtual async Task Action(MessageResult result)
|
||||
public virtual async Task Action(MessageResult result, String value = null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual async Task Render(MessageResult result)
|
||||
{
|
||||
|
||||
|
||||
@@ -169,6 +169,17 @@ namespace TelegramBotBase.Form
|
||||
/// <returns></returns>
|
||||
public async Task ActionControls(MessageResult message)
|
||||
{
|
||||
//Looking for the control by id, if not listened, raise event for all
|
||||
if (message.RawData.StartsWith("#c"))
|
||||
{
|
||||
var c = this.Controls.FirstOrDefault(a => a.ControlID == message.RawData.Split('_')[0]);
|
||||
if (c != null)
|
||||
{
|
||||
await c.Action(message, message.RawData.Split('_')[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var b in this.Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TelegramBotBase.Constants
|
||||
{
|
||||
public static class Telegram
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum length of message text before the API throws an exception. (We will catch it before)
|
||||
/// </summary>
|
||||
public const int MaxMessageLength = 4096;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace TelegramBotBase.Controls
|
||||
|
||||
|
||||
|
||||
public override async Task Action(MessageResult result)
|
||||
public override async Task Action(MessageResult result, String value = null)
|
||||
{
|
||||
await result.ConfirmAction();
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Controls
|
||||
{
|
||||
public class ToggleButton : ControlBase
|
||||
{
|
||||
|
||||
public String UncheckedIcon { get; set; } = "⚪";
|
||||
|
||||
public String CheckedIcon { get; set; } = "⚫";
|
||||
|
||||
public String CheckedString { get; set; } = "On";
|
||||
|
||||
public String UncheckedString { get; set; } = "Off";
|
||||
|
||||
public String Title { get; set; } = "Toggle";
|
||||
|
||||
public int? MessageId { get; set; }
|
||||
|
||||
public bool Checked { get; set; }
|
||||
|
||||
private bool RenderNecessary = true;
|
||||
|
||||
private static readonly object __evToggled = new object();
|
||||
|
||||
private readonly EventHandlerList Events = new EventHandlerList();
|
||||
|
||||
|
||||
public ToggleButton()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ToggleButton(String CheckedString, String UncheckedString)
|
||||
{
|
||||
this.CheckedString = CheckedString;
|
||||
this.UncheckedString = UncheckedString;
|
||||
}
|
||||
|
||||
public event EventHandler Toggled
|
||||
{
|
||||
add
|
||||
{
|
||||
this.Events.AddHandler(__evToggled, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.Events.RemoveHandler(__evToggled, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnToggled(EventArgs e)
|
||||
{
|
||||
(this.Events[__evToggled] as EventHandler)?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult result, String value = null)
|
||||
{
|
||||
|
||||
if (result.Handled)
|
||||
return;
|
||||
|
||||
await result.ConfirmAction();
|
||||
|
||||
switch (value ?? "unknown")
|
||||
{
|
||||
case "on":
|
||||
|
||||
if (this.Checked)
|
||||
return;
|
||||
|
||||
RenderNecessary = true;
|
||||
|
||||
this.Checked = true;
|
||||
|
||||
OnToggled(new EventArgs());
|
||||
|
||||
break;
|
||||
|
||||
case "off":
|
||||
|
||||
if (!this.Checked)
|
||||
return;
|
||||
|
||||
RenderNecessary = true;
|
||||
|
||||
this.Checked = false;
|
||||
|
||||
OnToggled(new EventArgs());
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
RenderNecessary = false;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
result.Handled = true;
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult result)
|
||||
{
|
||||
if (!RenderNecessary)
|
||||
return;
|
||||
|
||||
var bf = new ButtonForm(this);
|
||||
|
||||
ButtonBase bOn = new ButtonBase((this.Checked ? CheckedIcon : UncheckedIcon) + " " + CheckedString, "on");
|
||||
|
||||
ButtonBase bOff = new ButtonBase((!this.Checked ? CheckedIcon : UncheckedIcon) + " " + UncheckedString, "off");
|
||||
|
||||
bf.AddButtonRow(bOn, bOff);
|
||||
|
||||
if (this.MessageId != null)
|
||||
{
|
||||
var m = await this.Device.Edit(this.MessageId.Value, this.Title, bf);
|
||||
}
|
||||
else
|
||||
{
|
||||
var m = await this.Device.Send(this.Title, bf, disableNotification: true);
|
||||
if (m != null)
|
||||
{
|
||||
this.MessageId = m.MessageId;
|
||||
}
|
||||
}
|
||||
|
||||
this.RenderNecessary = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,16 +29,16 @@ namespace TelegramBotBase.Controls
|
||||
}
|
||||
|
||||
|
||||
public override async Task Action(MessageResult result)
|
||||
public override async Task Action(MessageResult result, String value = null)
|
||||
{
|
||||
await result.ConfirmAction();
|
||||
|
||||
if (result.Handled)
|
||||
return;
|
||||
|
||||
var value = result.RawData;
|
||||
var val = result.RawData;
|
||||
|
||||
switch (value)
|
||||
switch (val)
|
||||
{
|
||||
case "up":
|
||||
case "parent":
|
||||
@@ -50,7 +50,7 @@ namespace TelegramBotBase.Controls
|
||||
break;
|
||||
default:
|
||||
|
||||
var n = (this.VisibleNode != null ? this.VisibleNode.FindNodeByValue(value) : this.Nodes.FirstOrDefault(a => a.Value == value));
|
||||
var n = (this.VisibleNode != null ? this.VisibleNode.FindNodeByValue(val) : this.Nodes.FirstOrDefault(a => a.Value == val));
|
||||
|
||||
if (n != null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TelegramBotBase.Exceptions
|
||||
{
|
||||
public class MaxLengthException : Exception
|
||||
{
|
||||
public MaxLengthException(int length) : base($"Your messages with a length of {length} is too long for telegram. Actually is {Constants.Telegram.MaxMessageLength} characters allowed. Please split it.")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,14 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
public String ButtonText { get; set; }
|
||||
|
||||
public AlertDialog(String Message, String ButtonText) : base(Message)
|
||||
{
|
||||
this.Buttons.Add(new ButtonBase(ButtonText, "ok"));
|
||||
this.ButtonText = ButtonText;
|
||||
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public AlertDialog(String Message, String ButtonText, FormBase FormToOpen = null) : base(Message)
|
||||
{
|
||||
this.Buttons.Add(new ButtonBase(ButtonText, "ok"));
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public ButtonBase[][] Buttons { get; set; }
|
||||
|
||||
[Obsolete]
|
||||
public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>();
|
||||
|
||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||
|
||||
@@ -31,11 +31,12 @@ namespace TelegramBotBase.Form
|
||||
}
|
||||
|
||||
|
||||
public InlineKeyboardButton ToInlineButton()
|
||||
public InlineKeyboardButton ToInlineButton(ButtonForm form)
|
||||
{
|
||||
String id = (form.DependencyControl != null ? form.DependencyControl.ControlID + "_" : "");
|
||||
if (this.Url == null)
|
||||
{
|
||||
return InlineKeyboardButton.WithCallbackData(this.Text, this.Value);
|
||||
return InlineKeyboardButton.WithCallbackData(this.Text, id + this.Value);
|
||||
}
|
||||
|
||||
var ikb = new InlineKeyboardButton();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Form
|
||||
{
|
||||
@@ -17,12 +18,18 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public IReplyMarkup Markup { get; set; }
|
||||
|
||||
public ControlBase DependencyControl { get; set; }
|
||||
|
||||
public ButtonForm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ButtonForm(ControlBase control)
|
||||
{
|
||||
this.DependencyControl = control;
|
||||
}
|
||||
|
||||
public void AddButtonRow(IEnumerable<ButtonBase> row)
|
||||
{
|
||||
Buttons.Add(row.ToList());
|
||||
@@ -70,7 +77,7 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public InlineKeyboardButton[][] ToArray()
|
||||
{
|
||||
var ikb = this.Buttons.Select(a => a.Select(b => b.ToInlineButton()).ToArray()).ToArray();
|
||||
var ikb = this.Buttons.Select(a => a.Select(b => b.ToInlineButton(this)).ToArray()).ToArray();
|
||||
|
||||
return ikb;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public List<ButtonBase> Buttons { get; set; }
|
||||
|
||||
[Obsolete]
|
||||
public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>();
|
||||
|
||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace TelegramBotBase.Markdown
|
||||
{
|
||||
public static class Generator
|
||||
{
|
||||
public static ParseMode OutputMode { get; set; } = ParseMode.Markdown;
|
||||
|
||||
/// <summary>
|
||||
/// Generates a link with title in Markdown or HTML
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="tooltip"></param>
|
||||
/// <returns></returns>
|
||||
public static String Link(this String url, String title = null, String tooltip = null)
|
||||
{
|
||||
switch (OutputMode)
|
||||
{
|
||||
case ParseMode.Markdown:
|
||||
return "[" + (title ?? url) + "](" + url + " " + (tooltip ?? "") + ")";
|
||||
case ParseMode.Html:
|
||||
return $"<a href=\"{url}\" title=\"{tooltip ?? ""}\">{title ?? ""}</b>";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Link to the User, title is optional.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="title"></param>
|
||||
/// <returns></returns>
|
||||
public static String MentionUser(this long userId, String title = null)
|
||||
{
|
||||
return Link("tg://user?id=" + userId.ToString(), title);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bold link in Markdown or HTML
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static String Bold(this String text)
|
||||
{
|
||||
switch (OutputMode)
|
||||
{
|
||||
case ParseMode.Markdown:
|
||||
return "**" + text + "**";
|
||||
case ParseMode.Html:
|
||||
return "<b>" + text + "</b>";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a italic link in Markdown or HTML
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static String Italic(this String text)
|
||||
{
|
||||
switch (OutputMode)
|
||||
{
|
||||
case ParseMode.Markdown:
|
||||
return "__" + text + "__";
|
||||
case ParseMode.Html:
|
||||
return "<i>" + text + "</i>";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a monospace link in Markdown or HTML
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static String Monospace(this String text)
|
||||
{
|
||||
switch (OutputMode)
|
||||
{
|
||||
case ParseMode.Markdown:
|
||||
return "`" + text + "`";
|
||||
case ParseMode.Html:
|
||||
return "<code>" + text + "</code>";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a multi monospace link in Markdown or HTML
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static String MultiMonospace(this String text)
|
||||
{
|
||||
switch (OutputMode)
|
||||
{
|
||||
case ParseMode.Markdown:
|
||||
return "```" + text + "```";
|
||||
case ParseMode.Html:
|
||||
return "<pre>" + text + "</pre>";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("TelegramBotBase Framework")]
|
||||
[assembly: AssemblyDescription("A simple addon for the original C# Telegram Bot library.")]
|
||||
[assembly: AssemblyDescription("This is a context based application framework for the C# TelegramBot library.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Florian Dahn")]
|
||||
[assembly: AssemblyProduct("TelegramBotBase Framework")]
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.4.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.4.2.0")]
|
||||
[assembly: AssemblyVersion("1.5.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.5.2.0")]
|
||||
|
||||
@@ -13,6 +13,7 @@ using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Exceptions;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Sessions
|
||||
@@ -129,6 +130,11 @@ namespace TelegramBotBase.Sessions
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
if (text.Length > Constants.Telegram.MaxMessageLength)
|
||||
{
|
||||
throw new MaxLengthException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, replyMarkup: markup);
|
||||
@@ -158,6 +164,11 @@ namespace TelegramBotBase.Sessions
|
||||
|
||||
InlineKeyboardMarkup markup = buttons;
|
||||
|
||||
if (message.Text.Length > Constants.Telegram.MaxMessageLength)
|
||||
{
|
||||
throw new MaxLengthException(message.Text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, replyMarkup: markup);
|
||||
@@ -181,7 +192,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)
|
||||
public async Task<Message> Send(String text, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
|
||||
{
|
||||
if (this.ActiveForm == null)
|
||||
return null;
|
||||
@@ -190,9 +201,14 @@ namespace TelegramBotBase.Sessions
|
||||
|
||||
Message m = null;
|
||||
|
||||
if (text.Length > Constants.Telegram.MaxMessageLength)
|
||||
{
|
||||
throw new MaxLengthException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
OnMessageSent(new MessageSentEventArgs(m));
|
||||
}
|
||||
@@ -216,16 +232,21 @@ namespace TelegramBotBase.Sessions
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Message> Send(String text, InlineKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false)
|
||||
public async Task<Message> Send(String text, InlineKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
|
||||
{
|
||||
if (this.ActiveForm == null)
|
||||
return null;
|
||||
|
||||
Message m = null;
|
||||
|
||||
if (text.Length > Constants.Telegram.MaxMessageLength)
|
||||
{
|
||||
throw new MaxLengthException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
OnMessageSent(new MessageSentEventArgs(m));
|
||||
}
|
||||
@@ -249,16 +270,21 @@ namespace TelegramBotBase.Sessions
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Message> Send(String text, ReplyKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false)
|
||||
public async Task<Message> Send(String text, ReplyKeyboardMarkup markup, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
|
||||
{
|
||||
if (this.ActiveForm == null)
|
||||
return null;
|
||||
|
||||
Message m = null;
|
||||
|
||||
if (text.Length > Constants.Telegram.MaxMessageLength)
|
||||
{
|
||||
throw new MaxLengthException(text.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
|
||||
|
||||
OnMessageSent(new MessageSentEventArgs(m));
|
||||
}
|
||||
@@ -282,7 +308,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)
|
||||
public async Task<Message> SendPhoto(InputOnlineFile file, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false, ParseMode parseMode = ParseMode.Default)
|
||||
{
|
||||
if (this.ActiveForm == null)
|
||||
return null;
|
||||
@@ -293,7 +319,7 @@ namespace TelegramBotBase.Sessions
|
||||
|
||||
try
|
||||
{
|
||||
m = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
|
||||
m = await this.Client.TelegramClient.SendPhotoAsync(this.DeviceId, file, parseMode: parseMode, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification);
|
||||
|
||||
OnMessageSent(new MessageSentEventArgs(m));
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 307 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 185 KiB |
Reference in New Issue
Block a user