Compare commits

...
5 Commits
Author SHA1 Message Date
FlorianDahn 19f3c9c195 Merge branch 'master' of https://github.com/MajMcCloud/TelegramBotFramework 2019-03-20 16:57:15 +07:00
FlorianDahn c6666f72bc - Improvements to system calls
- system calls now async with await
- added start command to example
- added "handled" property to system call event args
2019-03-20 16:57:10 +07:00
Florian Dahn bf7f6f851a Update README.md 2019-03-20 14:00:11 +07:00
FlorianDahn 816bf4cbbe Merge branch 'master' of https://github.com/MajMcCloud/TelegramBotFramework 2019-03-20 13:44:48 +07:00
FlorianDahn da80af86e3 Small fix in Systemcall management 2019-03-20 13:44:44 +07:00
6 changed files with 62 additions and 31 deletions
+15 -9
View File
@@ -8,19 +8,12 @@
[![license](https://img.shields.io/github/license/MajMcCloud/telegrambotframework.svg?style=flat-square&maxAge=2592000&label=License)](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md) [![license](https://img.shields.io/github/license/MajMcCloud/telegrambotframework.svg?style=flat-square&maxAge=2592000&label=License)](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
[![downloads](https://img.shields.io/nuget/dt/TelegramBotBase.svg?style=flat-square&label=Package%20Downloads)](https://www.nuget.org/packages/TelegramBotBase) [![downloads](https://img.shields.io/nuget/dt/TelegramBotBase.svg?style=flat-square&label=Package%20Downloads)](https://www.nuget.org/packages/TelegramBotBase)
Hey guys, Test the Testproject: [@TGBaseBot](https://t.me/TGBaseBot)
here we are. After some time and thoughts i give my TelegramBot framework to public.
It is based on C#.
It is a module which is based on the original [TelegramBotLibrary](https://github.com/TelegramBots/Telegram.Bot) you will find in nuget.
It gives you features which will look/feel like WinForms or have a good way to create apps with actions and forms.
--- ---
## Index ## Index
- [Introduction](#introduction)
- [How to Start](#how-to-start) - [How to Start](#how-to-start)
- [Message Handling](#message-handling) - [Message Handling](#message-handling)
* [Example #0 - System Calls](#add-some-system-calls-example-0---system-calls) * [Example #0 - System Calls](#add-some-system-calls-example-0---system-calls)
@@ -34,6 +27,19 @@ It gives you features which will look/feel like WinForms or have a good way to c
* [Example #4 - Registration Formular](#registration-example-example-4---registration-form-test) * [Example #4 - Registration Formular](#registration-example-example-4---registration-form-test)
---
## Introduction
Hey guys,
here we are. After some time and thoughts i give my TelegramBot framework to public.
It is based on C#.
It is a module which is based on the original [TelegramBotLibrary](https://github.com/TelegramBots/Telegram.Bot) you will find in nuget.
It gives you features which will look/feel like WinForms or have a good way to create apps with actions and forms.
--- ---
## How to start: ## How to start:
+10 -2
View File
@@ -21,13 +21,19 @@ namespace TelegramBaseTest
bb.SystemCalls.Add("/start"); bb.SystemCalls.Add("/start");
bb.SystemCalls.Add("/form1"); bb.SystemCalls.Add("/form1");
bb.SystemCalls.Add("/form2"); bb.SystemCalls.Add("/form2");
bb.SystemCalls.Add("/params"); bb.SystemCalls.Add("/params");
bb.SystemCall += async (s, en) => bb.SystemCall += async (s, en) =>
{ {
switch (en.Command) switch (en.Command)
{ {
case "/start":
var start = new Start();
await en.Device.ActiveForm.NavigateTo(start);
break;
case "/form1": case "/form1":
var form1 = new TestForm(); var form1 = new TestForm();
@@ -48,7 +54,9 @@ namespace TelegramBaseTest
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b); String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
await en.Device.Send("Your parameters are " + m, replyTo: en.Device.LastMessage); await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId);
en.Handled = true;
break; break;
} }
+19 -1
View File
@@ -44,6 +44,10 @@ namespace TelegramBotBase.Form
} }
/// <summary>
/// Gets invoked if gets navigated to this form
/// </summary>
/// <returns></returns>
public virtual async Task Opened() public virtual async Task Opened()
{ {
@@ -62,17 +66,31 @@ namespace TelegramBotBase.Form
} }
/// <summary>
/// Gets invoked if the form gets loaded and on every message belongs to this context
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Load(MessageResult message) public virtual async Task Load(MessageResult message)
{ {
} }
/// <summary>
/// Gets invoked if the user has clicked a button.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Action(MessageResult message) public virtual async Task Action(MessageResult message)
{ {
} }
/// <summary>
/// Gets invoked at the end of the cycle to "Render" text, images, buttons, etc...
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public virtual async Task Render(MessageResult message) public virtual async Task Render(MessageResult message)
{ {
+5 -1
View File
@@ -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;
using TelegramBotBase.Sessions; using TelegramBotBase.Sessions;
namespace TelegramBotBase.Base namespace TelegramBotBase.Base
@@ -22,6 +23,8 @@ namespace TelegramBotBase.Base
public bool Handled { get; set; } = false; public bool Handled { get; set; } = false;
public Message OriginalMessage { get; set; }
public SystemCallEventArgs() public SystemCallEventArgs()
{ {
@@ -29,10 +32,11 @@ namespace TelegramBotBase.Base
} }
public SystemCallEventArgs(String Command, List<String> Parameters, long DeviceId, DeviceSession Device) public SystemCallEventArgs(String Command, List<String> Parameters, Message Message, long DeviceId, DeviceSession Device)
{ {
this.Command = Command; this.Command = Command;
this.Parameters = Parameters; this.Parameters = Parameters;
this.OriginalMessage = Message;
this.DeviceId = DeviceId; this.DeviceId = DeviceId;
this.Device = Device; this.Device = Device;
} }
+10 -15
View File
@@ -42,6 +42,8 @@ namespace TelegramBotBase
private static object __evSystemCall = new object(); private static object __evSystemCall = new object();
public delegate Task SystemCallEventHandler(object sender, SystemCallEventArgs e);
private static object __evException = new object(); private static object __evException = new object();
private static object __evUnhandledCall = new object(); private static object __evUnhandledCall = new object();
@@ -219,9 +221,10 @@ namespace TelegramBotBase
//Is this a systemcall ? //Is this a systemcall ?
if (e.IsSystemCall && this.SystemCalls.Contains(e.SystemCommand)) if (e.IsSystemCall && this.SystemCalls.Contains(e.SystemCommand))
{ {
var sce = new SystemCallEventArgs(e.SystemCommand, e.SystemCallParameters, ds.DeviceId, ds); var sce = new SystemCallEventArgs(e.SystemCommand, e.SystemCallParameters, e.Message, ds.DeviceId, ds);
OnSystemCall(sce); await OnSystemCall(sce);
if (sce.Handled)
return; return;
} }
@@ -379,21 +382,13 @@ namespace TelegramBotBase
/// <summary> /// <summary>
/// Will be called if a system call gets raised /// Will be called if a system call gets raised
/// </summary> /// </summary>
public event EventHandler<SystemCallEventArgs> SystemCall public event SystemCallEventHandler SystemCall;
{
add
{
this.__Events.AddHandler(__evSystemCall, value);
}
remove
{
this.__Events.RemoveHandler(__evSystemCall, value);
}
}
public void OnSystemCall(SystemCallEventArgs e)
public async Task OnSystemCall(SystemCallEventArgs e)
{ {
(this.__Events[__evSystemCall] as EventHandler<SystemCallEventArgs>)?.Invoke(this, e); if (this.SystemCall != null)
await SystemCall(this, e);
} }
/// <summary> /// <summary>
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.0")] [assembly: AssemblyVersion("1.3.1.2")]
[assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyFileVersion("1.3.1.2")]