Compare commits

..
14 Commits
Author SHA1 Message Date
FlorianDahn a6d22cdd82 Update version 2019-09-17 16:44:14 +02:00
FlorianDahn ee4a3d765c Merge branch 'master' of https://github.com/MajMcCloud/TelegramBotFramework 2019-09-17 16:43:10 +02:00
FlorianDahn 703c99eb8d - added a custom exception for maximum length messages, saves to time to sent to API
- added a constants file, for have constants to work with
- catching maximum message length
2019-09-17 16:43:02 +02:00
Florian Dahn 138fee9772 Update README.md
adding paypal
2019-09-17 16:33:51 +02:00
Florian Dahn d60399514f Update README.md 2019-09-04 15:13:42 +02:00
FlorianDahn ae0fa3b0e3 Added simple Markdown/HTML Generator
Use with:

"Bold Text".Bold();

"Other text".Italic();

"www.google.de".Link("Google")
2019-08-28 17:33:18 +02:00
FlorianDahn 6a2ac7a309 Added simple Markdown/HTML Generator
Use with:

"Bold Text".Bold();

"Other text".Italic();

"www.google.de".AsLink("Google")
2019-08-28 17:32:08 +02:00
FlorianDahn 1a76b2b3f8 added some forms to obsolete, cause their use is bad for ram management 2019-08-26 01:34:50 +02:00
FlorianDahn 5893108bd3 Update readme 2019-08-23 14:55:54 +02:00
FlorianDahn d668f57711 Update readme 2019-08-23 14:53:24 +02:00
FlorianDahn 56c7754408 - Added ToggleButton as an easy switch control (i.e. for settings page)
- added control id, for easier separating of controls in one form
- added automatic event selection for specific controls, to not raise an event for other controls who has invoked it
- changed Action method
- added example
2019-08-23 14:02:24 +02:00
FlorianDahn 805ffb9ec7 Update version 2019-07-15 13:33:01 +02:00
FlorianDahn aeddd82ea9 Merge branch 'master' of https://github.com/MajMcCloud/TelegramBotFramework 2019-07-15 13:31:07 +02:00
FlorianDahn 1ec14ce680 Updating nuget packages 2019-07-15 13:31:02 +02:00
21 changed files with 466 additions and 26 deletions
+24 -1
View File
@@ -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 ## Index
- [Introduction](#introduction) - [Introduction](#introduction)
- [How to Start](#how-to-start) - [How to Start](#how-to-start)
@@ -46,7 +63,9 @@ Download a release: [Releases](https://github.com/MajMcCloud/TelegramBotFramewor
* [MonthPicker](#month-picker) * [MonthPicker](#month-picker)
+ [TreeView](#tree-view) * [TreeView](#tree-view)
* [ToggleButton](#toggle-button)
--- ---
@@ -715,6 +734,7 @@ await this.NavigateTo(pd);
### Calendar Picker ### Calendar Picker
<img src="images/calendarpicker.PNG?raw=true" /> <img src="images/calendarpicker.PNG?raw=true" />
<img src="images/calendarpicker.gif?raw=true" />
### Month Picker ### Month Picker
<img src="images/monthpicker1.PNG?raw=true" /> <img src="images/monthpicker1.PNG?raw=true" />
@@ -728,6 +748,9 @@ await this.NavigateTo(pd);
<img src="images/treeview4.PNG?raw=true" /> <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. 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"));
}
}
}
+12
View File
@@ -113,6 +113,16 @@ namespace TelegramBaseTest.Tests
await this.NavigateTo(tree); await this.NavigateTo(tree);
break;
case "togglebuttons":
message.Handled = true;
var tb = new Controls.ToggleButtons();
await this.NavigateTo(tb);
break; break;
} }
@@ -138,6 +148,8 @@ namespace TelegramBaseTest.Tests
btn.AddButtonRow(new ButtonBase("#10 TreeView", new CallbackData("a", "treeview").Serialize())); 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); await this.Device.Send("Choose your test:", btn);
} }
+2 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <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="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> </packages>
+11 -1
View File
@@ -15,18 +15,28 @@ namespace TelegramBotBase.Base
public int ID { get; set; } public int ID { get; set; }
public String ControlID
{
get
{
return "#c" + this.ID.ToString();
}
}
/// <summary> /// <summary>
/// Defines if the control should be rendered and invoked with actions /// Defines if the control should be rendered and invoked with actions
/// </summary> /// </summary>
public bool Enabled { get; set; } = true; 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) public virtual async Task Render(MessageResult result)
{ {
+12 -1
View File
@@ -55,7 +55,7 @@ namespace TelegramBotBase.Form
return; return;
var handler = this.Events[__evInit].GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>(); var handler = this.Events[__evInit].GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
foreach(var h in handler) foreach (var h in handler)
{ {
await Async.InvokeAllAsync<InitEventArgs>(h, this, e); await Async.InvokeAllAsync<InitEventArgs>(h, this, e);
} }
@@ -169,6 +169,17 @@ namespace TelegramBotBase.Form
/// <returns></returns> /// <returns></returns>
public async Task ActionControls(MessageResult message) 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) foreach (var b in this.Controls)
{ {
if (!b.Enabled) if (!b.Enabled)
+17
View File
@@ -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;
}
}
+1 -1
View File
@@ -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(); await result.ConfirmAction();
+145
View File
@@ -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;
}
}
}
+4 -4
View File
@@ -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(); await result.ConfirmAction();
if (result.Handled) if (result.Handled)
return; return;
var value = result.RawData; var val = result.RawData;
switch (value) switch (val)
{ {
case "up": case "up":
case "parent": case "parent":
@@ -50,7 +50,7 @@ namespace TelegramBotBase.Controls
break; break;
default: 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) 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.")
{
}
}
}
+8
View File
@@ -15,6 +15,14 @@ namespace TelegramBotBase.Form
{ {
public String ButtonText { get; set; } 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) public AlertDialog(String Message, String ButtonText, FormBase FormToOpen = null) : base(Message)
{ {
this.Buttons.Add(new ButtonBase(ButtonText, "ok")); this.Buttons.Add(new ButtonBase(ButtonText, "ok"));
@@ -18,6 +18,7 @@ namespace TelegramBotBase.Form
public ButtonBase[][] Buttons { get; set; } public ButtonBase[][] Buttons { get; set; }
[Obsolete]
public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>(); public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>();
private EventHandlerList __Events { get; set; } = new EventHandlerList(); private EventHandlerList __Events { get; set; } = new EventHandlerList();
+3 -2
View File
@@ -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) if (this.Url == null)
{ {
return InlineKeyboardButton.WithCallbackData(this.Text, this.Value); return InlineKeyboardButton.WithCallbackData(this.Text, id + this.Value);
} }
var ikb = new InlineKeyboardButton(); var ikb = new InlineKeyboardButton();
+9 -2
View File
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Telegram.Bot.Types.ReplyMarkups; using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Base;
namespace TelegramBotBase.Form namespace TelegramBotBase.Form
{ {
@@ -17,12 +18,18 @@ namespace TelegramBotBase.Form
public IReplyMarkup Markup { get; set; } public IReplyMarkup Markup { get; set; }
public ControlBase DependencyControl { get; set; }
public ButtonForm() public ButtonForm()
{ {
} }
public ButtonForm(ControlBase control)
{
this.DependencyControl = control;
}
public void AddButtonRow(IEnumerable<ButtonBase> row) public void AddButtonRow(IEnumerable<ButtonBase> row)
{ {
Buttons.Add(row.ToList()); Buttons.Add(row.ToList());
@@ -62,7 +69,7 @@ namespace TelegramBotBase.Form
{ {
var sp = SplitTo<ButtonBase>(buttons, buttonsPerRow); var sp = SplitTo<ButtonBase>(buttons, buttonsPerRow);
foreach(var bl in sp) foreach (var bl in sp)
{ {
AddButtonRow(bl); AddButtonRow(bl);
} }
@@ -70,7 +77,7 @@ namespace TelegramBotBase.Form
public InlineKeyboardButton[][] ToArray() 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; return ikb;
} }
+1
View File
@@ -15,6 +15,7 @@ namespace TelegramBotBase.Form
public List<ButtonBase> Buttons { get; set; } public List<ButtonBase> Buttons { get; set; }
[Obsolete]
public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>(); public Dictionary<String, FormBase> ButtonForms { get; set; } = new Dictionary<string, FormBase>();
private EventHandlerList __Events { get; set; } = new EventHandlerList(); private EventHandlerList __Events { get; set; } = new EventHandlerList();
+112
View File
@@ -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;
}
}
}
+3 -3
View File
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("TelegramBotBase Framework")] [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: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Florian Dahn")] [assembly: AssemblyCompany("Florian Dahn")]
[assembly: AssemblyProduct("TelegramBotBase Framework")] [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 // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2.0")] [assembly: AssemblyVersion("1.5.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")] [assembly: AssemblyFileVersion("1.5.2.0")]
+34 -8
View File
@@ -13,6 +13,7 @@ using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles; using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types.ReplyMarkups; using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Base; using TelegramBotBase.Base;
using TelegramBotBase.Exceptions;
using TelegramBotBase.Form; using TelegramBotBase.Form;
namespace TelegramBotBase.Sessions namespace TelegramBotBase.Sessions
@@ -129,6 +130,11 @@ namespace TelegramBotBase.Sessions
InlineKeyboardMarkup markup = buttons; InlineKeyboardMarkup markup = buttons;
if (text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(text.Length);
}
try try
{ {
var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, replyMarkup: markup); var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, messageId, text, replyMarkup: markup);
@@ -158,6 +164,11 @@ namespace TelegramBotBase.Sessions
InlineKeyboardMarkup markup = buttons; InlineKeyboardMarkup markup = buttons;
if (message.Text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(message.Text.Length);
}
try try
{ {
var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, replyMarkup: markup); 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="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) public async Task<Message> Send(String text, 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;
@@ -190,9 +201,14 @@ namespace TelegramBotBase.Sessions
Message m = null; Message m = null;
if (text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(text.Length);
}
try 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)); OnMessageSent(new MessageSentEventArgs(m));
} }
@@ -216,16 +232,21 @@ 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, 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) if (this.ActiveForm == null)
return null; return null;
Message m = null; Message m = null;
if (text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(text.Length);
}
try 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)); OnMessageSent(new MessageSentEventArgs(m));
} }
@@ -249,16 +270,21 @@ 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, 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) if (this.ActiveForm == null)
return null; return null;
Message m = null; Message m = null;
if (text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(text.Length);
}
try 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)); OnMessageSent(new MessageSentEventArgs(m));
} }
@@ -282,7 +308,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) public async Task<Message> SendPhoto(InputOnlineFile file, 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;
@@ -293,7 +319,7 @@ namespace TelegramBotBase.Sessions
try 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)); OnMessageSent(new MessageSentEventArgs(m));
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB