- adding new SentData Event in FormBase for User uploads (for Photo, Audio, Video, Contact, Location, Document)

- adding RequestUserLocation and RequestUserContact to Device class
- Update to Device class
- updating examples
- adding example for data upload
- small documentary Updates (Readme.md)
This commit is contained in:
FlorianDahn
2019-03-27 14:01:48 +07:00
parent 5cd54fc746
commit b14fa2dc87
12 changed files with 348 additions and 19 deletions
+142
View File
@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
namespace TelegramBaseTest.Tests
{
public class DataForm : AutoCleanForm
{
public override async Task SentData(DataResult data)
{
String tmp = "";
InputOnlineFile file;
switch (data.Type)
{
case Telegram.Bot.Types.Enums.MessageType.Contact:
tmp += "Firstname: " + data.Contact.FirstName + "\r\n";
tmp += "Lastname: " + data.Contact.LastName + "\r\n";
tmp += "Phonenumber: " + data.Contact.PhoneNumber + "\r\n";
tmp += "UserId: " + data.Contact.UserId + "\r\n";
await this.Device.Send("Your contact: \r\n" + tmp, replyTo: data.MessageId);
break;
case Telegram.Bot.Types.Enums.MessageType.Document:
file = new InputOnlineFile(data.Document.FileId);
await this.Device.SendDocument(file, "Your uploaded document");
break;
case Telegram.Bot.Types.Enums.MessageType.Video:
file = new InputOnlineFile(data.Document.FileId);
await this.Device.SendDocument(file, "Your uploaded video");
break;
case Telegram.Bot.Types.Enums.MessageType.Audio:
file = new InputOnlineFile(data.Document.FileId);
await this.Device.SendDocument(file, "Your uploaded audio");
break;
case Telegram.Bot.Types.Enums.MessageType.Location:
tmp += "Lat: " + data.Location.Latitude + "\r\n";
tmp += "Lng: " + data.Location.Longitude + "\r\n";
await this.Device.Send("Your location: \r\n" + tmp, replyTo: data.MessageId);
break;
case Telegram.Bot.Types.Enums.MessageType.Photo:
InputOnlineFile photo = new InputOnlineFile(data.Photos.Last().FileId);
await this.Device.Send("Your image: ", replyTo: data.MessageId);
await this.Client.TelegramClient.SendPhotoAsync(this.Device.DeviceId, photo);
break;
default:
await this.Device.Send("Unknown response");
break;
}
}
public override async Task Action(MessageResult message)
{
await message.ConfirmAction();
if (message.Handled)
return;
switch (message.RawData)
{
case "contact":
await this.Device.RequestContact();
break;
case "location":
await this.Device.RequestLocation();
break;
case "back":
message.Handled = true;
var start = new Start();
await this.NavigateTo(start);
break;
}
}
public override async Task Render(MessageResult message)
{
ButtonForm bf = new ButtonForm();
bf.AddButtonRow(new ButtonBase("Request User contact", "contact"));
bf.AddButtonRow(new ButtonBase("Request User location", "location"));
bf.AddButtonRow(new ButtonBase("Back", "back"));
InlineKeyboardMarkup ikv = bf;
await this.Device.Send("Please upload a contact, photo, video, audio, document or location.", bf);
}
}
}
+12
View File
@@ -69,6 +69,16 @@ namespace TelegramBaseTest.Tests
await this.NavigateTo(form2);
break;
case "data":
message.Handled = true;
var data = new DataForm();
await this.NavigateTo(data);
break;
}
@@ -88,6 +98,8 @@ namespace TelegramBaseTest.Tests
btn.AddButtonRow(new ButtonBase("#6 Form2 Command", new CallbackData("a", "form2").Serialize()));
btn.AddButtonRow(new ButtonBase("#7 Data Handling", new CallbackData("a", "data").Serialize()));
await this.Device.Send("Choose your test:", btn);
}
+4 -1
View File
@@ -60,7 +60,10 @@ namespace TelegramBaseTest.Tests
}
else if (call.Value == "prompt")
{
PromptDialog pd = new PromptDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel"));
PromptDialog pd = new PromptDialog("Please confirm");
pd.AddButton(new ButtonBase("Ok", "ok"));
pd.AddButton(new ButtonBase("Cancel", "cancel"));
var tf = new TestForm2();