Update DeviceSession.cs

- adding EditReplyMarkup to Device methods
- adding GetChatTitle method to get easier the name of a chat/group/channel
- some cleanup
This commit is contained in:
FlorianDahn 2020-04-15 20:27:46 +02:00
parent d24f8e7ac5
commit ef667d12d8

View File

@ -35,6 +35,18 @@ namespace TelegramBotBase.Sessions
/// </summary>
public String ChatTitle { get; set; }
/// <summary>
/// Returns the ChatTitle depending on groups/channels or users
/// </summary>
/// <returns></returns>
public String GetChatTitle()
{
return LastMessage?.Chat.Title
?? LastMessage?.Chat.Username
?? LastMessage?.Chat.FirstName
?? ChatTitle;
}
/// <summary>
/// When did any last action happend (message received or button clicked)
/// </summary>
@ -132,9 +144,6 @@ namespace TelegramBotBase.Sessions
/// <returns></returns>
public async Task<Message> Edit(int messageId, String text, ButtonForm buttons = null)
{
if (this.ActiveForm == null)
return null;
InlineKeyboardMarkup markup = buttons;
if (text.Length > Constants.Telegram.MaxMessageLength)
@ -164,9 +173,6 @@ namespace TelegramBotBase.Sessions
/// <returns></returns>
public async Task<Message> Edit(int messageId, String text, InlineKeyboardMarkup markup)
{
if (this.ActiveForm == null)
return null;
if (text.Length > Constants.Telegram.MaxMessageLength)
{
throw new MaxLengthException(text.Length);
@ -194,9 +200,6 @@ namespace TelegramBotBase.Sessions
/// <returns></returns>
public async Task<Message> Edit(Message message, ButtonForm buttons = null)
{
if (this.ActiveForm == null)
return null;
InlineKeyboardMarkup markup = buttons;
if (message.Text.Length > Constants.Telegram.MaxMessageLength)
@ -217,6 +220,27 @@ namespace TelegramBotBase.Sessions
return null;
}
/// <summary>
/// Edits the reply keyboard markup (buttons)
/// </summary>
/// <param name="messageId"></param>
/// <param name="bf"></param>
/// <returns></returns>
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
{
try
{
return await this.Client.TelegramClient.EditMessageReplyMarkupAsync(this.DeviceId, messageId, bf);
}
catch
{
}
return null;
}
/// <summary>
/// Sends a simple text message
/// </summary>