Update of Testproject
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Tests;
|
||||
using TelegramBaseTest.Tests;
|
||||
|
||||
namespace TelegramBaseTest
|
||||
{
|
||||
@@ -16,7 +16,7 @@ namespace TelegramBaseTest
|
||||
|
||||
String APIKey = "";
|
||||
|
||||
BotBase<TestForm> bb = new BotBase<TestForm>(APIKey);
|
||||
BotBase<TestForm2> bb = new BotBase<TestForm2>(APIKey);
|
||||
|
||||
bb.SystemCalls.Add("/start");
|
||||
bb.SystemCalls.Add("/form1");
|
||||
|
||||
@@ -33,21 +33,33 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Telegram.Bot, Version=14.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Telegram.Bot.14.4.0\lib\net45\Telegram.Bot.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tests\TestForm.cs" />
|
||||
<Compile Include="Tests\TestForm2.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj">
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBaseTest.Tests
|
||||
{
|
||||
public class TestForm : FormBase
|
||||
{
|
||||
|
||||
|
||||
String LastMessage { get; set; }
|
||||
|
||||
public override async Task Init(params object[] param)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override async Task Opened()
|
||||
{
|
||||
await this.Device.Send("Welcome to Form 1");
|
||||
}
|
||||
|
||||
public override async Task Closed()
|
||||
{
|
||||
await this.Device.Send("Ciao from Form 1");
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
switch (message.Command)
|
||||
{
|
||||
case "reply":
|
||||
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case "navigate":
|
||||
|
||||
var tf = new TestForm2();
|
||||
|
||||
await tf.Init();
|
||||
|
||||
await this.NavigateTo(tf);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
if (message.RawMessageData == null)
|
||||
return;
|
||||
|
||||
this.LastMessage = message.RawMessageData.Message.Text;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
if (message.Command == "reply")
|
||||
{
|
||||
|
||||
await this.Device.Send("Last message: " + this.LastMessage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBaseTest.Tests
|
||||
{
|
||||
public class TestForm2 : FormBase
|
||||
{
|
||||
|
||||
public override async Task Init(params object[] param)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override async Task Opened()
|
||||
{
|
||||
await this.Device.Send("Welcome to Form 2");
|
||||
}
|
||||
|
||||
public override async Task Closed()
|
||||
{
|
||||
await this.Device.Send("Ciao from Form 2");
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
var call = message.GetData<CallbackData>();
|
||||
|
||||
await message.ConfirmAction();
|
||||
|
||||
await message.DeleteMessage();
|
||||
|
||||
if (call.Value == "testform1")
|
||||
{
|
||||
|
||||
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")
|
||||
{
|
||||
PromptDialog pd = new PromptDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel"));
|
||||
|
||||
var tf = new TestForm2();
|
||||
|
||||
await tf.Init();
|
||||
|
||||
pd.ButtonForms.Add("ok", tf);
|
||||
pd.ButtonForms.Add("cancel", tf);
|
||||
|
||||
await this.NavigateTo(pd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
Bitmap bmp = new Bitmap(800, 600);
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
|
||||
g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
|
||||
|
||||
g.DrawString("Test Image", new Font("Arial", 24, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Black, new PointF(50, 50));
|
||||
|
||||
}
|
||||
|
||||
await this.Device.SetAction(Telegram.Bot.Types.Enums.ChatAction.UploadPhoto);
|
||||
|
||||
ButtonForm btn = new ButtonForm();
|
||||
|
||||
//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")));
|
||||
|
||||
|
||||
await this.Device.SendPhoto(bmp, "Test", btn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="net452" />
|
||||
<package id="Telegram.Bot" version="14.4.0" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user