- Updated system call management
- parameters are now easier available - example project added parameter example
This commit is contained in:
parent
e5ae3be86e
commit
3856271e30
13
README.md
13
README.md
@ -140,6 +140,8 @@ Below we have 3 options.
|
||||
|
||||
/form2 - navigates in this context to form2
|
||||
|
||||
/params - demonstrates the use of parameters per command (i.e. /params 1 2 3 test ...)
|
||||
|
||||
|
||||
|
||||
```
|
||||
@ -149,6 +151,8 @@ Below we have 3 options.
|
||||
bb.SystemCalls.Add("/form1");
|
||||
bb.SystemCalls.Add("/form2");
|
||||
|
||||
bb.SystemCalls.Add("/params");
|
||||
|
||||
bb.SystemCall += async (s, en) =>
|
||||
{
|
||||
switch (en.Command)
|
||||
@ -160,12 +164,21 @@ Below we have 3 options.
|
||||
await en.Device.ActiveForm.NavigateTo(form1);
|
||||
|
||||
break;
|
||||
|
||||
case "/form2":
|
||||
|
||||
var form2 = new TestForm2();
|
||||
|
||||
await en.Device.ActiveForm.NavigateTo(form2);
|
||||
|
||||
break;
|
||||
|
||||
case "/params":
|
||||
|
||||
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
||||
|
||||
await en.Device.Send("Your parameters are " + m, replyTo: en.Device.LastMessage);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ namespace TelegramBaseTest
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
String APIKey = "480896099:AAEtq_owUqRH62DR0gYc-ZWRI_TWl8El1YQ";
|
||||
String APIKey = "{YOUR API KEY}";
|
||||
|
||||
BotBase<Start> bb = new BotBase<Start>(APIKey);
|
||||
|
||||
@ -22,6 +22,8 @@ namespace TelegramBaseTest
|
||||
bb.SystemCalls.Add("/form1");
|
||||
bb.SystemCalls.Add("/form2");
|
||||
|
||||
bb.SystemCalls.Add("/params");
|
||||
|
||||
bb.SystemCall += async (s, en) =>
|
||||
{
|
||||
switch (en.Command)
|
||||
@ -33,12 +35,21 @@ namespace TelegramBaseTest
|
||||
await en.Device.ActiveForm.NavigateTo(form1);
|
||||
|
||||
break;
|
||||
|
||||
case "/form2":
|
||||
|
||||
var form2 = new TestForm2();
|
||||
|
||||
await en.Device.ActiveForm.NavigateTo(form2);
|
||||
|
||||
break;
|
||||
|
||||
case "/params":
|
||||
|
||||
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
||||
|
||||
await en.Device.Send("Your parameters are " + m, replyTo: en.Device.LastMessage);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,46 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this a system call ? Starts with a slash and command
|
||||
/// </summary>
|
||||
public bool IsSystemCall
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.MessageText.StartsWith("/"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 => 123,456,789)
|
||||
/// </summary>
|
||||
public List<String> SystemCallParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsSystemCall)
|
||||
return new List<string>();
|
||||
|
||||
//Split by empty space and skip first entry (command itself), return as list
|
||||
return this.MessageText.Split(' ').Skip(1).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns just the System call command (i.e. /start 1 2 3 => /start)
|
||||
/// </summary>
|
||||
public String SystemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsSystemCall)
|
||||
return null;
|
||||
|
||||
return this.MessageText.Split(' ')[0];
|
||||
}
|
||||
}
|
||||
|
||||
public bool Handled { get; set; } = false;
|
||||
|
||||
public String RawData
|
||||
|
||||
@ -14,9 +14,13 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
public String Command { get; set; }
|
||||
|
||||
public List<String> Parameters { get; set; }
|
||||
|
||||
public long DeviceId { get; set; }
|
||||
|
||||
public DeviceSession Device {get;set;}
|
||||
public DeviceSession Device { get; set; }
|
||||
|
||||
public bool Handled { get; set; } = false;
|
||||
|
||||
|
||||
public SystemCallEventArgs()
|
||||
@ -25,9 +29,10 @@ namespace TelegramBotBase.Base
|
||||
|
||||
}
|
||||
|
||||
public SystemCallEventArgs(String Command, long DeviceId, DeviceSession Device)
|
||||
public SystemCallEventArgs(String Command, List<String> Parameters, long DeviceId, DeviceSession Device)
|
||||
{
|
||||
this.Command = Command;
|
||||
this.Parameters = Parameters;
|
||||
this.DeviceId = DeviceId;
|
||||
this.Device = Device;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ namespace TelegramBotBase
|
||||
/// <summary>
|
||||
/// How often could a form navigate to another (within one user action/call/message)
|
||||
/// </summary>
|
||||
private const int NavigationMaximum = 10;
|
||||
private const int NavigationMaximum = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey
|
||||
@ -162,13 +162,13 @@ namespace TelegramBotBase
|
||||
ds.LastAction = DateTime.Now;
|
||||
ds.LastMessage = e.MessageId;
|
||||
|
||||
|
||||
//Is this a systemcall ?
|
||||
if (e.Message.Text != null && this.SystemCalls.Contains(e.Message.Text))
|
||||
if (e.IsSystemCall && this.SystemCalls.Contains(e.SystemCommand))
|
||||
{
|
||||
var sce = new SystemCallEventArgs(e.Message.Text, ds.DeviceId, ds);
|
||||
var sce = new SystemCallEventArgs(e.SystemCommand, e.SystemCallParameters, ds.DeviceId, ds);
|
||||
OnSystemCall(sce);
|
||||
//return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FormBase activeForm = null;
|
||||
@ -340,7 +340,6 @@ namespace TelegramBotBase
|
||||
public void OnSystemCall(SystemCallEventArgs e)
|
||||
{
|
||||
(this.__Events[__evSystemCall] as EventHandler<SystemCallEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -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.2.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.1.0")]
|
||||
[assembly: AssemblyVersion("1.3.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.0.0")]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user