- Added comments

- added Edit method
This commit is contained in:
FlorianDahn 2019-05-04 18:59:05 +02:00
parent 94fe263676
commit ea971979e2
2 changed files with 55 additions and 4 deletions

View File

@ -21,15 +21,33 @@ namespace TelegramBotBase.Form
public enum eDeleteMode
{
/// <summary>
/// Don't delete any message.
/// </summary>
None = 0,
/// <summary>
/// Delete messages on every callback/action.
/// </summary>
OnEveryCall = 1,
/// <summary>
/// Delete on leaving this form.
/// </summary>
OnLeavingForm = 2
}
public enum eSide
{
/// <summary>
/// Delete only messages from this bot.
/// </summary>
BotOnly = 0,
/// <summary>
/// Delete only user messages.
/// </summary>
UserOnly = 1,
/// <summary>
/// Delete all messages in this context.
/// </summary>
Both = 2
}

View File

@ -83,7 +83,7 @@ namespace TelegramBotBase.Sessions
}
}
public EventHandlerList __Events = new EventHandlerList();
private EventHandlerList __Events = new EventHandlerList();
private static object __evMessageSent = new object();
private static object __evMessageReceived = new object();
@ -138,6 +138,39 @@ namespace TelegramBotBase.Sessions
return null;
}
/// <summary>
/// Edits the text message
/// </summary>
/// <param name="messageId"></param>
/// <param name="text"></param>
/// <param name="buttons"></param>
/// <returns></returns>
public async Task<Message> Edit(Message message, ButtonForm buttons = null)
{
if (this.ActiveForm == null)
return null;
InlineKeyboardMarkup markup = null;
if (buttons != null)
{
markup = buttons;
}
try
{
var m = await this.Client.TelegramClient.EditMessageTextAsync(this.DeviceId, message.MessageId, message.Text, replyMarkup: markup);
return m;
}
catch
{
}
return null;
}
/// <summary>
/// Sends a simple text message
/// </summary>
@ -163,7 +196,7 @@ namespace TelegramBotBase.Sessions
{
m = await (this.Client.TelegramClient.SendTextMessageAsync(this.DeviceId, text, replyToMessageId: replyTo, replyMarkup: markup, disableNotification: disableNotification));
OnMessageSent(new MessageSentEventArgs( m));
OnMessageSent(new MessageSentEventArgs(m));
}
catch (ApiRequestException ex)
{
@ -330,7 +363,7 @@ namespace TelegramBotBase.Sessions
}
var m = await this.Client.TelegramClient.SendDocumentAsync(this.DeviceId, document, caption, replyMarkup: markup, disableNotification: disableNotification, replyToMessageId: replyTo);
OnMessageSent(new MessageSentEventArgs(m));
return m;
@ -384,7 +417,7 @@ namespace TelegramBotBase.Sessions
try
{
await this.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, messageId);
return true;
}
catch (ApiRequestException ex)