Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19f3c9c195 | ||
|
|
c6666f72bc | ||
|
|
bf7f6f851a | ||
|
|
816bf4cbbe | ||
|
|
da80af86e3 |
@@ -8,19 +8,12 @@
|
|||||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||||
[](https://www.nuget.org/packages/TelegramBotBase)
|
[](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:
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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>
|
||||||
|
|||||||
@@ -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")]
|
||||||
|
|||||||
Reference in New Issue
Block a user