diff --git a/README.md b/README.md index 9c7bf46..e2c36ce 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ Test the Testproject: [@TGBaseBot](https://t.me/TGBaseBot) * [Example #4 - Registration Formular](#registration-example-example-4---registration-form-test) +- [Special Forms](#forms) + + * [AlertDialog](#alert-dialog) + * [AutoCleanForm](#autocleanform) + * [PromptDialog](#prompt-dialog) + --- @@ -578,6 +584,82 @@ There is also a second example, where every of these 3 inputs gets requested by Cause its to much Text, i didnt have added it here. You will find it under [TelegramBaseTest/Tests/Register/PerStep.cs](TelegramBaseTest/Tests/Register/PerStep.cs) Beginn there and navigate your way through these Steps in the subfolder. + +--- + + +## Forms + +There are some default types of forms to make the interaction with users easier. +For now we have the following: + + * [AlertDialog](#alert-dialog) + Just a simple dialog with one ok Button. + + * [AutoCleanForm](#autocleanform) + A form which needs to be derived from. It will be delete all in the context sent messages to the user after every new message or on leaving the formular and navigates somewhere else. + Makes sense to create a "feeling" of a clean environment for the user. For instance if you have a multilevel menu. This will remove the previously shown menu, and renders the new sub/top level. + + * [PromptDialog](#prompt-dialog) + A simple dialog which is able to show multiple buttons and a Text message. The user could select one option and will get redirected to a different form, depending on the click. + +### Alert Dialog + +``` + + var fto = new TestForm2(); + + AlertDialog ad = new AlertDialog("This is a message", "Ok", fto); + + await this.NavigateTo(ad); + +``` + + +### AutoCleanForm + + + +### Prompt Dialog + +#### Without Eventhandler (pre-init of form necessary) + +``` + + PromptDialog pd = new PromptDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel")); + + var tf = new TestForm2(); + + pd.ButtonForms.Add("ok", tf); + pd.ButtonForms.Add("cancel", tf); + + await this.NavigateTo(pd); + +``` + + +#### With Eventhandler (no pre-init of form necessary) + +``` + + PromptDialog pd = new PromptDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel")); + + //You could mix here for sure. + pd.ButtonForms.Add("ok", null); + pd.ButtonForms.Add("cancel", null); + + pd.ButtonClicked += async (s, en) => + { + var tf = new TestForm2(); + + //Remember only to navigate from the current running form. (here it is the prompt dialog, cause we have left the above already) + await pd.NavigateTo(tf); + }; + + await this.NavigateTo(pd); + +``` + --- I will add more notes to it soon, so stay tuned. diff --git a/TelegramBaseTest/Tests/ButtonTestForm.cs b/TelegramBaseTest/Tests/ButtonTestForm.cs index 76314e5..9cbb7d6 100644 --- a/TelegramBaseTest/Tests/ButtonTestForm.cs +++ b/TelegramBaseTest/Tests/ButtonTestForm.cs @@ -59,8 +59,6 @@ namespace TelegramBaseTest.Tests var st = new Start(); - await st.Init(); - await this.NavigateTo(st); break; diff --git a/TelegramBaseTest/Tests/ProgressTest.cs b/TelegramBaseTest/Tests/ProgressTest.cs index 11ef4a1..c9ce89a 100644 --- a/TelegramBaseTest/Tests/ProgressTest.cs +++ b/TelegramBaseTest/Tests/ProgressTest.cs @@ -75,8 +75,6 @@ namespace TelegramBaseTest.Tests var sf = new Start(); - await sf.Init(); - await this.NavigateTo(sf); return; diff --git a/TelegramBaseTest/Tests/SimpleForm.cs b/TelegramBaseTest/Tests/SimpleForm.cs index e37038b..3c02813 100644 --- a/TelegramBaseTest/Tests/SimpleForm.cs +++ b/TelegramBaseTest/Tests/SimpleForm.cs @@ -50,8 +50,6 @@ namespace TelegramBaseTest.Tests var st = new Start(); - await st.Init(); - await this.NavigateTo(st); break; diff --git a/TelegramBaseTest/Tests/Start.cs b/TelegramBaseTest/Tests/Start.cs index fed396e..cb60a33 100644 --- a/TelegramBaseTest/Tests/Start.cs +++ b/TelegramBaseTest/Tests/Start.cs @@ -53,6 +53,22 @@ namespace TelegramBaseTest.Tests await this.NavigateTo(reg); + break; + + case "form1": + + var form1 = new TestForm(); + + await this.NavigateTo(form1); + + break; + + case "form2": + + var form2 = new TestForm2(); + + await this.NavigateTo(form2); + break; } @@ -68,6 +84,10 @@ namespace TelegramBaseTest.Tests btn.AddButtonRow(new ButtonBase("#3 Progress Bar", new CallbackData("a", "progress").Serialize())); btn.AddButtonRow(new ButtonBase("#4 Registration Example", new CallbackData("a", "registration").Serialize())); + btn.AddButtonRow(new ButtonBase("#5 Form1 Command", new CallbackData("a", "form1").Serialize())); + + btn.AddButtonRow(new ButtonBase("#6 Form2 Command", new CallbackData("a", "form2").Serialize())); + await this.Device.Send("Choose your test:", btn); } diff --git a/TelegramBaseTest/Tests/TestForm.cs b/TelegramBaseTest/Tests/TestForm.cs index b3a94a2..d2a29c1 100644 --- a/TelegramBaseTest/Tests/TestForm.cs +++ b/TelegramBaseTest/Tests/TestForm.cs @@ -51,8 +51,6 @@ namespace TelegramBaseTest.Tests var tf = new TestForm2(); - await tf.Init(); - await this.NavigateTo(tf); break; diff --git a/TelegramBaseTest/Tests/TestForm2.cs b/TelegramBaseTest/Tests/TestForm2.cs index 7b22190..2f4c8c3 100644 --- a/TelegramBaseTest/Tests/TestForm2.cs +++ b/TelegramBaseTest/Tests/TestForm2.cs @@ -48,18 +48,14 @@ namespace TelegramBaseTest.Tests var tf = new TestForm(); - await tf.Init(); - await this.NavigateTo(tf); } else if (call.Value == "alert") { var fto = new TestForm2(); - await fto.Init(); AlertDialog ad = new AlertDialog("This is a message", "Ok", fto); - - + await this.NavigateTo(ad); } else if (call.Value == "prompt") @@ -68,10 +64,24 @@ namespace TelegramBaseTest.Tests var tf = new TestForm2(); - await tf.Init(); - pd.ButtonForms.Add("ok", tf); pd.ButtonForms.Add("cancel", tf); + + await this.NavigateTo(pd); + } + else if (call.Value == "promptevt") + { + PromptDialog pd = new PromptDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel")); + + pd.ButtonForms.Add("ok", null); + pd.ButtonForms.Add("cancel", null); + + pd.ButtonClicked += async (s, en) => + { + var tf = new TestForm2(); + + await pd.NavigateTo(tf); + }; await this.NavigateTo(pd); } @@ -98,7 +108,11 @@ namespace TelegramBaseTest.Tests //btn.AddButtonRow(new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")), new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1"))); - btn.AddButtonRow(new ButtonBase("Information Prompt", CallbackData.Create("navigate", "alert")), new ButtonBase("Confirmation Prompt", CallbackData.Create("navigate", "prompt"))); + btn.AddButtonRow(new ButtonBase("Information Prompt", CallbackData.Create("navigate", "alert"))); + + btn.AddButtonRow(new ButtonBase("Confirmation Prompt without event", CallbackData.Create("navigate", "prompt"))); + + btn.AddButtonRow(new ButtonBase("Confirmation Prompt with event", CallbackData.Create("navigate", "promptevt"))); await this.Device.SendPhoto(bmp, "Test", btn); diff --git a/TelegramBotBase/Base/MessageResult.cs b/TelegramBotBase/Base/MessageResult.cs index 5ba363e..6a68a21 100644 --- a/TelegramBotBase/Base/MessageResult.cs +++ b/TelegramBotBase/Base/MessageResult.cs @@ -62,7 +62,7 @@ namespace TelegramBotBase.Base } /// - /// Is this a system call ? Starts with a slash and command + /// Is this a system call ? Starts with a slash '/' and a command /// public bool IsSystemCall { diff --git a/TelegramBotBase/Form/PromptDialog.cs b/TelegramBotBase/Form/PromptDialog.cs index 1ea9df4..64943a5 100644 --- a/TelegramBotBase/Form/PromptDialog.cs +++ b/TelegramBotBase/Form/PromptDialog.cs @@ -50,7 +50,6 @@ namespace TelegramBotBase.Form await message.DeleteMessage(); - ButtonBase button = this.Buttons.FirstOrDefault(a => a.Value == call.Value); if (button == null) @@ -73,7 +72,6 @@ namespace TelegramBotBase.Form { ButtonForm btn = new ButtonForm(); - var buttons = this.Buttons.Select(a => new ButtonBase(a.Text, CallbackData.Create("action", a.Value))).ToList(); btn.AddButtonRow(buttons); diff --git a/TelegramBotBase/Properties/AssemblyInfo.cs b/TelegramBotBase/Properties/AssemblyInfo.cs index 7a5e26e..810356b 100644 --- a/TelegramBotBase/Properties/AssemblyInfo.cs +++ b/TelegramBotBase/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.2")] -[assembly: AssemblyFileVersion("1.3.1.2")] +[assembly: AssemblyVersion("1.3.1.3")] +[assembly: AssemblyFileVersion("1.3.1.3")]