Updating ButtonBase to enable Url Buttons
This commit is contained in:
parent
94d153e141
commit
cb4a797b12
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form
|
namespace TelegramBotBase.Form
|
||||||
{
|
{
|
||||||
@ -15,15 +16,35 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
public String Value { get; set; }
|
public String Value { get; set; }
|
||||||
|
|
||||||
|
public String Url { get; set; }
|
||||||
|
|
||||||
public ButtonBase()
|
public ButtonBase()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ButtonBase(String Text, String Value)
|
public ButtonBase(String Text, String Value, String Url = null)
|
||||||
{
|
{
|
||||||
this.Text = Text;
|
this.Text = Text;
|
||||||
this.Value = Value;
|
this.Value = Value;
|
||||||
|
this.Url = Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public InlineKeyboardButton ToInlineButton()
|
||||||
|
{
|
||||||
|
if (this.Url == null)
|
||||||
|
{
|
||||||
|
return InlineKeyboardButton.WithCallbackData(this.Text, this.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ikb = new InlineKeyboardButton();
|
||||||
|
|
||||||
|
ikb.Text = this.Text;
|
||||||
|
ikb.Url = this.Url;
|
||||||
|
|
||||||
|
return ikb;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,14 +14,18 @@ namespace TelegramBotBase.Form
|
|||||||
{
|
{
|
||||||
List<List<ButtonBase>> Buttons = new List<List<ButtonBase>>();
|
List<List<ButtonBase>> Buttons = new List<List<ButtonBase>>();
|
||||||
|
|
||||||
|
|
||||||
|
public IReplyMarkup Markup { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ButtonForm()
|
public ButtonForm()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddButtonRow(List<ButtonBase> row)
|
public void AddButtonRow(IEnumerable<ButtonBase> row)
|
||||||
{
|
{
|
||||||
Buttons.Add(row);
|
Buttons.Add(row.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddButtonRow(params ButtonBase[] row)
|
public void AddButtonRow(params ButtonBase[] row)
|
||||||
@ -66,7 +70,7 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
public InlineKeyboardButton[][] ToArray()
|
public InlineKeyboardButton[][] ToArray()
|
||||||
{
|
{
|
||||||
var ikb = this.Buttons.Select(a => a.Select(b => InlineKeyboardButton.WithCallbackData(b.Text, b.Value)).ToArray()).ToArray();
|
var ikb = this.Buttons.Select(a => a.Select(b => b.ToInlineButton()).ToArray()).ToArray();
|
||||||
|
|
||||||
return ikb;
|
return ikb;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user