Adding new example project for Inline- and ReplyMarkup combination
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using InlineAndReplyCombination.Baseclasses;
|
||||
using InlineAndReplyCombination.Forms.Steps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace InlineAndReplyCombination.Forms
|
||||
{
|
||||
public class StartForm : AutoCleanForm
|
||||
{
|
||||
ButtonGrid buttonGrid;
|
||||
|
||||
public StartForm()
|
||||
{
|
||||
this.Init += StartForm_Init;
|
||||
|
||||
}
|
||||
|
||||
private async Task StartForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
||||
{
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRow("Start registration", "start");
|
||||
|
||||
buttonGrid = new ButtonGrid(bf);
|
||||
|
||||
buttonGrid.Title = "Welcome to The InlineAndReplyCombination Bot!";
|
||||
buttonGrid.ButtonClicked += ButtonGrid_ButtonClicked;
|
||||
buttonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.ReplyKeyboard;
|
||||
|
||||
AddControl(buttonGrid);
|
||||
|
||||
}
|
||||
|
||||
private async Task ButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
||||
{
|
||||
if(e.Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch(e.Button.Value)
|
||||
{
|
||||
case "start":
|
||||
|
||||
var mf = new MainForm();
|
||||
|
||||
mf.UserDetails = new Model.UserDetails();
|
||||
|
||||
await NavigateTo(mf);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using InlineAndReplyCombination.Baseclasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace InlineAndReplyCombination.Forms.Steps
|
||||
{
|
||||
public class MainForm : MultipleChoiceForm
|
||||
{
|
||||
|
||||
ButtonGrid InlineButtonGrid;
|
||||
|
||||
public static List<Tuple<String, String>> AllowedInlineInputs = null;
|
||||
|
||||
static MainForm()
|
||||
{
|
||||
AllowedInlineInputs = new List<Tuple<string, string>>()
|
||||
{
|
||||
new("< 18", "<18"),
|
||||
new("18 to 25", "18t25"),
|
||||
new("25 to 35", "25t35"),
|
||||
new("35 to 50", "35t50"),
|
||||
new("over 50", "o50")
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
|
||||
Init += MainForm_Init;
|
||||
|
||||
ReplyButtonTitle = "Start over";
|
||||
CurrentStep = 1;
|
||||
}
|
||||
|
||||
private async Task MainForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
||||
{
|
||||
|
||||
//Inline Keyboard
|
||||
var bf_ages = new ButtonForm();
|
||||
|
||||
//Add all options in a single column
|
||||
bf_ages.AddSplitted(AllowedInlineInputs.Select(a => new ButtonBase(a.Item1, a.Item2)), 1);
|
||||
|
||||
bf_ages.AddButtonRow("Some invalid input", "Invalid");
|
||||
|
||||
InlineButtonGrid = new ButtonGrid(bf_ages);
|
||||
InlineButtonGrid.ConfirmationText = "Thank you";
|
||||
InlineButtonGrid.Title = "Please choose your age:";
|
||||
InlineButtonGrid.ButtonClicked += InlineButtonGrid_ButtonClicked;
|
||||
|
||||
InlineButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.InlineKeyBoard;
|
||||
|
||||
AddControl(InlineButtonGrid);
|
||||
|
||||
}
|
||||
|
||||
private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
||||
{
|
||||
//Not found
|
||||
if (!AllowedInlineInputs.Any(a => a.Item2 == e.Button.Value))
|
||||
{
|
||||
await Device.Send("Invalid input!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.UserDetails.AgeRange = e.Button?.Value ?? "unknown";
|
||||
|
||||
var sf = new SecondForm();
|
||||
|
||||
await NavigateTo(sf);
|
||||
}
|
||||
|
||||
|
||||
public override async Task PressReplyButton()
|
||||
{
|
||||
var sf = new StartForm();
|
||||
|
||||
await NavigateTo(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using InlineAndReplyCombination.Baseclasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace InlineAndReplyCombination.Forms.Steps
|
||||
{
|
||||
public class SecondForm : MultipleChoiceForm
|
||||
{
|
||||
|
||||
ButtonGrid InlineButtonGrid;
|
||||
|
||||
public static List<Tuple<String, String>> AllowedInlineInputs = null;
|
||||
|
||||
static SecondForm()
|
||||
{
|
||||
AllowedInlineInputs = new List<Tuple<string, string>>()
|
||||
{
|
||||
new("Green", "green"),
|
||||
new("Yellow", "yellow"),
|
||||
new("Red", "red"),
|
||||
new("Purple", "purple"),
|
||||
new("Black", "black"),
|
||||
new("Gold", "gold")
|
||||
};
|
||||
}
|
||||
|
||||
public SecondForm()
|
||||
{
|
||||
|
||||
Init += SecondForm_Init;
|
||||
|
||||
ReplyButtonTitle = "Go back";
|
||||
CurrentStep = 2;
|
||||
|
||||
}
|
||||
|
||||
private async Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
||||
{
|
||||
|
||||
//Inline Keyboard
|
||||
var bf_ages = new ButtonForm();
|
||||
|
||||
//Add all options in a single column
|
||||
bf_ages.AddSplitted(AllowedInlineInputs.Select(a => new ButtonBase(a.Item1, a.Item2)), 1);
|
||||
|
||||
InlineButtonGrid = new ButtonGrid(bf_ages);
|
||||
InlineButtonGrid.ConfirmationText = "Thank you";
|
||||
InlineButtonGrid.Title = "Please choose your favourite color:";
|
||||
InlineButtonGrid.ButtonClicked += InlineButtonGrid_ButtonClicked;
|
||||
|
||||
InlineButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.InlineKeyBoard;
|
||||
|
||||
AddControl(InlineButtonGrid);
|
||||
|
||||
}
|
||||
|
||||
private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
||||
{
|
||||
//Not found
|
||||
if (!AllowedInlineInputs.Any(a => a.Item2 == e.Button.Value))
|
||||
{
|
||||
await Device.Send("Invalid input!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.UserDetails.FavouriteColor = e.Button?.Value ?? "unknown";
|
||||
|
||||
var tf = new ThirdForm();
|
||||
|
||||
await NavigateTo(tf);
|
||||
}
|
||||
|
||||
|
||||
public override async Task PressReplyButton()
|
||||
{
|
||||
var mf = new MainForm();
|
||||
|
||||
await NavigateTo(mf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using InlineAndReplyCombination.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Attributes;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace InlineAndReplyCombination.Forms.Steps
|
||||
{
|
||||
public class Summary : AutoCleanForm
|
||||
{
|
||||
[SaveState]
|
||||
public UserDetails UserDetails { get; set; }
|
||||
|
||||
ButtonGrid ReplyButtonGrid { get; set; }
|
||||
|
||||
public Summary()
|
||||
{
|
||||
Init += Summary_Init;
|
||||
|
||||
}
|
||||
|
||||
private async Task Summary_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
||||
{
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRow("Go back", "back");
|
||||
bf.AddButtonRow("Return to Start", "start");
|
||||
|
||||
|
||||
|
||||
ReplyButtonGrid = new ButtonGrid(bf);
|
||||
ReplyButtonGrid.Title = "Thank you for your time!";
|
||||
ReplyButtonGrid.ButtonClicked += ReplyButtonGrid_ButtonClicked;
|
||||
|
||||
AddControl(ReplyButtonGrid);
|
||||
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
if (UserDetails == null)
|
||||
{
|
||||
var sf = new StartForm();
|
||||
await NavigateTo(sf);
|
||||
return;
|
||||
}
|
||||
|
||||
await Device.Send($"Your inputs are:\r\n\r\nYour age: {UserDetails.AgeRange}\r\nYour favourite color: {UserDetails.FavouriteColor}\r\nYour favourite city: {UserDetails.FavouriteCity}");
|
||||
}
|
||||
|
||||
private async Task ReplyButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
||||
{
|
||||
switch (e.Button.Value ?? "")
|
||||
{
|
||||
case "start":
|
||||
|
||||
var sf = new StartForm();
|
||||
|
||||
await NavigateTo(sf);
|
||||
|
||||
break;
|
||||
|
||||
case "back":
|
||||
|
||||
var tf = new ThirdForm();
|
||||
|
||||
tf.UserDetails = UserDetails;
|
||||
|
||||
await NavigateTo(tf);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using InlineAndReplyCombination.Baseclasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace InlineAndReplyCombination.Forms.Steps
|
||||
{
|
||||
public class ThirdForm : MultipleChoiceForm
|
||||
{
|
||||
|
||||
ButtonGrid InlineButtonGrid;
|
||||
|
||||
public static List<Tuple<String, String>> AllowedInlineInputs = null;
|
||||
|
||||
static ThirdForm()
|
||||
{
|
||||
AllowedInlineInputs = new List<Tuple<string, string>>()
|
||||
{
|
||||
new("Berlin", "Berlin"),
|
||||
new("Vienna", "Vienna"),
|
||||
new("Rome", "Rome"),
|
||||
new("London", "London"),
|
||||
new("Moscow", "Moscow"),
|
||||
new("Bukarest", "Bukarest")
|
||||
};
|
||||
}
|
||||
|
||||
public ThirdForm()
|
||||
{
|
||||
Init += SecondForm_Init;
|
||||
|
||||
ReplyButtonTitle = "Go back";
|
||||
CurrentStep = 3;
|
||||
|
||||
}
|
||||
|
||||
private async Task SecondForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
||||
{
|
||||
|
||||
//Inline Keyboard
|
||||
var bf_ages = new ButtonForm();
|
||||
|
||||
//Add all options in a single column
|
||||
bf_ages.AddSplitted(AllowedInlineInputs.Select(a => new ButtonBase(a.Item1, a.Item2)), 1);
|
||||
|
||||
InlineButtonGrid = new ButtonGrid(bf_ages);
|
||||
InlineButtonGrid.ConfirmationText = "Thank you";
|
||||
InlineButtonGrid.Title = "Please choose your favourite city:";
|
||||
InlineButtonGrid.ButtonClicked += InlineButtonGrid_ButtonClicked;
|
||||
|
||||
InlineButtonGrid.KeyboardType = TelegramBotBase.Enums.EKeyboardType.InlineKeyBoard;
|
||||
|
||||
AddControl(InlineButtonGrid);
|
||||
|
||||
}
|
||||
|
||||
private async Task InlineButtonGrid_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
||||
{
|
||||
//Not found
|
||||
if (!AllowedInlineInputs.Any(a => a.Item2 == e.Button.Value))
|
||||
{
|
||||
await Device.Send("Invalid input!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.UserDetails.FavouriteCity = e.Button?.Value ?? "unknown";
|
||||
|
||||
var sum = new Summary();
|
||||
sum.UserDetails = this.UserDetails;
|
||||
await NavigateTo(sum);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task PressReplyButton()
|
||||
{
|
||||
var sf = new SecondForm();
|
||||
|
||||
await NavigateTo(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user