Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93fda551e1 | ||
|
|
8b22fd7b74 | ||
|
|
254c002d4a | ||
|
|
d833b1e088 | ||
|
|
084395e962 | ||
|
|
cc4c743721 | ||
|
|
4e55fd42d6 | ||
|
|
83e09aec2a | ||
|
|
a63f71268c | ||
|
|
d56b26a788 | ||
|
|
c1018ac5a0 | ||
|
|
064399ed77 | ||
|
|
121a788c17 | ||
|
|
40199a1d81 | ||
|
|
794dee7f58 | ||
|
|
88309e607b | ||
|
|
a71eed5054 | ||
|
|
2a873cc29b | ||
|
|
f401216eff | ||
|
|
0cb4f02a8d | ||
|
|
62b6bafbd3 | ||
|
|
89332244e3 | ||
|
|
43f4ab1061 | ||
|
|
1f438186f4 | ||
|
|
f447b058d0 | ||
|
|
40ba9bd8ab | ||
|
|
ca473f78ed | ||
|
|
ab702dbc9f | ||
|
|
23dc1ff1d6 | ||
|
|
e044d725c9 | ||
|
|
4825beea7e | ||
|
|
78d65868ff | ||
|
|
d7aca80d59 | ||
|
|
73863c4154 | ||
|
|
e3b1a32535 | ||
|
|
571049eeb4 | ||
|
|
30222d640d | ||
|
|
e6a48115a6 | ||
|
|
b278015dd4 | ||
|
|
91e0c54728 | ||
|
|
788f935c02 | ||
|
|
d1089fe716 | ||
|
|
1d3db0116e | ||
|
|
e95301f727 | ||
|
|
4ba91803fe |
@@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace DependencyInjection.Database;
|
||||||
|
|
||||||
|
public class BotDbContext : DbContext
|
||||||
|
{
|
||||||
|
public BotDbContext(DbContextOptions options) : base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace DependencyInjection.Database;
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string LastMessage { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.11" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using DependencyInjection.Database;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.DependencyInjection;
|
||||||
|
|
||||||
|
namespace DependencyInjection.Forms
|
||||||
|
{
|
||||||
|
public class ConfirmationForm : FormBase
|
||||||
|
{
|
||||||
|
private readonly BotDbContext _dbContext;
|
||||||
|
|
||||||
|
public ConfirmationForm(BotDbContext dbContext)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
var user = await _dbContext.Users.FindAsync(Device.DeviceId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await this.NavigateTo<StartForm>();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
await message.ConfirmAction("Go back");
|
||||||
|
|
||||||
|
switch (message.RawData)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "back":
|
||||||
|
|
||||||
|
await this.NavigateTo<StartForm>();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
var user = await _dbContext.Users.FindAsync(Device.DeviceId);
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var bf = new ButtonForm();
|
||||||
|
bf.AddButtonRow("Back", "back");
|
||||||
|
|
||||||
|
await Device.Send($"ConfirmationForm: Your last message was: {user.LastMessage}. Click \"Back\" to get back.", bf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using DependencyInjection.Database;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using TelegramBotBase.Builder;
|
||||||
|
|
||||||
|
namespace DependencyInjection
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var serviceCollection = new ServiceCollection()
|
||||||
|
.AddDbContext<BotDbContext>(x => x.UseInMemoryDatabase("TelegramBotBase"));
|
||||||
|
|
||||||
|
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
|
var bot = BotBaseBuilder.Create()
|
||||||
|
.WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ??
|
||||||
|
throw new Exception("API_KEY is not set"))
|
||||||
|
.DefaultMessageLoop()
|
||||||
|
.WithServiceProvider<StartForm>(serviceProvider)
|
||||||
|
.NoProxy()
|
||||||
|
.NoCommands()
|
||||||
|
.NoSerialization()
|
||||||
|
.DefaultLanguage()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
await bot.Start();
|
||||||
|
await Task.Delay(-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using DependencyInjection.Database;
|
||||||
|
using DependencyInjection.Forms;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.DependencyInjection;
|
||||||
|
|
||||||
|
namespace DependencyInjection;
|
||||||
|
|
||||||
|
public class StartForm : FormBase
|
||||||
|
{
|
||||||
|
private readonly BotDbContext _dbContext;
|
||||||
|
|
||||||
|
public StartForm(BotDbContext dbContext)
|
||||||
|
{
|
||||||
|
_dbContext = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
var user = await _dbContext.Users.FindAsync(Device.DeviceId);
|
||||||
|
if (user is null)
|
||||||
|
{
|
||||||
|
user = new User
|
||||||
|
{
|
||||||
|
Id = Device.DeviceId,
|
||||||
|
LastMessage = "<unknown>"
|
||||||
|
};
|
||||||
|
|
||||||
|
_dbContext.Users.Add(user);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.IsAction)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
user.LastMessage = string.IsNullOrWhiteSpace(message.MessageText) ? "<unknown>" : message.MessageText;
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
await message.ConfirmAction("Ok");
|
||||||
|
|
||||||
|
switch(message.RawData)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "open":
|
||||||
|
|
||||||
|
await this.NavigateTo(typeof(ConfirmationForm));
|
||||||
|
|
||||||
|
var new_form = await this.NavigateTo<ConfirmationForm>();
|
||||||
|
|
||||||
|
if (new_form == null)
|
||||||
|
{
|
||||||
|
await Device.Send("Cant open ConfirmationForm");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
var user = await _dbContext.Users.FindAsync(Device.DeviceId);
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
|
bf.AddButtonRow("Open confirmation", "open");
|
||||||
|
|
||||||
|
await Device.Send($"Your last message's text was: `{user.LastMessage}`", bf);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ namespace InlineAndReplyCombination
|
|||||||
|
|
||||||
await BotBaseInstance.UploadBotCommands();
|
await BotBaseInstance.UploadBotCommands();
|
||||||
|
|
||||||
|
BotBaseInstance.BotCommand += BotBaseInstance_BotCommand;
|
||||||
|
|
||||||
|
|
||||||
await BotBaseInstance.Start();
|
await BotBaseInstance.Start();
|
||||||
|
|
||||||
@@ -37,5 +39,28 @@ namespace InlineAndReplyCombination
|
|||||||
|
|
||||||
await BotBaseInstance.Stop();
|
await BotBaseInstance.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task BotBaseInstance_BotCommand(object sender, TelegramBotBase.Args.BotCommandEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch(e.Command)
|
||||||
|
{
|
||||||
|
case "/start":
|
||||||
|
|
||||||
|
|
||||||
|
var start = new StartForm();
|
||||||
|
|
||||||
|
await e.Device.ActiveForm.NavigateTo(start);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,14 @@
|
|||||||
|
|
||||||
**Support group: [@tgbotbase](https://t.me/tgbotbase)**
|
**Support group: [@tgbotbase](https://t.me/tgbotbase)**
|
||||||
|
|
||||||
**Discord Server: [https://discord.gg/p3PPhYbTf](https://discord.gg/p3PPhYbTf)**
|
**Discord Server: [https://discord.gg/V3PxreDYfE](https://discord.gg/V3PxreDYfE)**
|
||||||
|
|
||||||
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|
||||||
|
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
||||||
|
|
||||||
Bitcoin: `1GoUJYMwAvBipQTfw2FKydAz12J8RDyeJs` / `bc1qqwlp0p5ley29lsu6jhe0qv7s7963kfc7d0m53d`
|
Bitcoin: `1GoUJYMwAvBipQTfw2FKydAz12J8RDyeJs` / `bc1qqwlp0p5ley29lsu6jhe0qv7s7963kfc7d0m53d`
|
||||||
|
|
||||||
Etherium: `0xAf3835104c2C3E5b3e721FA2c7365955e87DB931`
|
Etherium: `0xAf3835104c2C3E5b3e721FA2c7365955e87DB931`
|
||||||
@@ -57,6 +59,7 @@ BitTorrent: `TYVZSykaVT1nKZnz9hjDgBRNB9VavU1bpW`
|
|||||||
* [TaggedButtonGrid](#tagged-button-grid)
|
* [TaggedButtonGrid](#tagged-button-grid)
|
||||||
* [CheckedButtonList](#checked-button-list)
|
* [CheckedButtonList](#checked-button-list)
|
||||||
* [MultiToggleButton](#multi-toggle-button)
|
* [MultiToggleButton](#multi-toggle-button)
|
||||||
|
- [Localizations](#localizations)
|
||||||
- [Groups](#groups)
|
- [Groups](#groups)
|
||||||
* [SplitterForm](#splitter-form)
|
* [SplitterForm](#splitter-form)
|
||||||
* [GroupForm](#group-form)
|
* [GroupForm](#group-form)
|
||||||
@@ -641,7 +644,7 @@ await this.NavigateTo(cd);
|
|||||||
|
|
||||||
A minimal control which allows to manage a classic "text" message and update its later without having to keep track of the message id.
|
A minimal control which allows to manage a classic "text" message and update its later without having to keep track of the message id.
|
||||||
|
|
||||||
<img src=".github/images/label.gif?raw=true" />
|
<img src=".github/images/label.gif?raw=true" style="width:500px" />
|
||||||
|
|
||||||
Check the example project [TelegramBotBase.Test/Tests/Controls/LabelForm.cs](TelegramBotBase.Test/Tests/Controls/LabelForm.cs)
|
Check the example project [TelegramBotBase.Test/Tests/Controls/LabelForm.cs](TelegramBotBase.Test/Tests/Controls/LabelForm.cs)
|
||||||
|
|
||||||
@@ -712,6 +715,19 @@ Check the example project [TelegramBotBase.Test/Tests/Controls/CheckedButtonList
|
|||||||
|
|
||||||
Check the example project [TelegramBotBase.Test/Tests/Controls/MultiToggleButtonForm.cs](TelegramBotBase.Test/Tests/Controls/MultiToggleButtonForm.cs)
|
Check the example project [TelegramBotBase.Test/Tests/Controls/MultiToggleButtonForm.cs](TelegramBotBase.Test/Tests/Controls/MultiToggleButtonForm.cs)
|
||||||
|
|
||||||
|
|
||||||
|
## Localizations
|
||||||
|
|
||||||
|
The current available languages for controls are:
|
||||||
|
|
||||||
|
- English
|
||||||
|
- German
|
||||||
|
- Persian
|
||||||
|
|
||||||
|
You can add other languages easily by creating a subclass of the [TelegramBotBase/Localizations/Localization.cs](TelegramBotBase/Localizations/Localization.cs) class.
|
||||||
|
|
||||||
|
To set the default language set the *Language* property on the static [TelegramBotBase/Localizations/Default.cs](TelegramBotBase/Localizations/Default.cs) instance.
|
||||||
|
|
||||||
## Groups
|
## Groups
|
||||||
|
|
||||||
For groups, there are multiple different tools which help to work with and allows bot also to manage
|
For groups, there are multiple different tools which help to work with and allows bot also to manage
|
||||||
@@ -1081,3 +1097,8 @@ Having already a web application and want to add a TelegramBot side-by-side with
|
|||||||
Want to use Inline- and ReplyMarkup at the same time ? Here is an example how you can do that:
|
Want to use Inline- and ReplyMarkup at the same time ? Here is an example how you can do that:
|
||||||
|
|
||||||
- [Examples/InlineAndReplyCombination](Examples/InlineAndReplyCombination)
|
- [Examples/InlineAndReplyCombination](Examples/InlineAndReplyCombination)
|
||||||
|
|
||||||
|
|
||||||
|
Alpha: Full Dependency Injection example within this framework.
|
||||||
|
|
||||||
|
- [Examples/DependencyInjection](Examples/DependencyInjection)
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
|
|
||||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException($"{nameof(FallbackStateForm)} is not a subclass of {nameof(FormBase)}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -16,15 +16,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.0"/>
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj"/>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace TelegramBotBase.Example.Tests.Controls;
|
|||||||
public class LabelForm : AutoCleanForm
|
public class LabelForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
|
||||||
TelegramBotBase.Controls.Inline.LabelControl _label;
|
TelegramBotBase.Controls.Inline.Label _label;
|
||||||
|
|
||||||
ButtonGrid _buttonGrid;
|
ButtonGrid _buttonGrid;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class LabelForm : AutoCleanForm
|
|||||||
private Task LabelForm_Init(object sender, InitEventArgs e)
|
private Task LabelForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
//The "label" control
|
//The "label" control
|
||||||
_label = new LabelControl("My test label");
|
_label = new Label("My test label");
|
||||||
|
|
||||||
AddControl(_label);
|
AddControl(_label);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Base
|
||||||
|
{
|
||||||
|
public class ErrorResult : EventArgs
|
||||||
|
{
|
||||||
|
public ErrorResult(Exception exception)
|
||||||
|
{
|
||||||
|
Exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception Exception { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ public class FormBase : IDisposable
|
|||||||
|
|
||||||
public MessageClient Client { get; set; }
|
public MessageClient Client { get; set; }
|
||||||
|
|
||||||
|
IServiceProvider _serviceProvider = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// has this formular already been disposed ?
|
/// has this formular already been disposed ?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace TelegramBotBase.Base;
|
|||||||
public class MessageClient
|
public class MessageClient
|
||||||
{
|
{
|
||||||
private static readonly object EvOnMessageLoop = new();
|
private static readonly object EvOnMessageLoop = new();
|
||||||
|
private static readonly object EvOnReceiveError = new();
|
||||||
|
|
||||||
private static object __evOnMessage = new();
|
private static object __evOnMessage = new();
|
||||||
|
|
||||||
@@ -27,6 +28,14 @@ public class MessageClient
|
|||||||
|
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
private CancellationTokenSource _cancellationTokenSource;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before
|
||||||
|
// start polling. If set to true Telegram.Bot.Polling.ReceiverOptions.AllowedUpdates
|
||||||
|
// should be set to not null, otherwise Telegram.Bot.Polling.ReceiverOptions.AllowedUpdates
|
||||||
|
// will effectively be set to receive all Telegram.Bot.Types.Updates.
|
||||||
|
/// </summary>
|
||||||
|
public bool ThrowPendingUpdates { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public MessageClient(string apiKey)
|
public MessageClient(string apiKey)
|
||||||
{
|
{
|
||||||
@@ -113,6 +122,8 @@ public class MessageClient
|
|||||||
|
|
||||||
var receiverOptions = new ReceiverOptions();
|
var receiverOptions = new ReceiverOptions();
|
||||||
|
|
||||||
|
receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
|
||||||
|
|
||||||
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions,
|
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions,
|
||||||
_cancellationTokenSource.Token);
|
_cancellationTokenSource.Token);
|
||||||
}
|
}
|
||||||
@@ -128,22 +139,12 @@ public class MessageClient
|
|||||||
await OnMessageLoop(new UpdateResult(update, null));
|
await OnMessageLoop(new UpdateResult(update, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
public async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (exception is ApiRequestException exApi)
|
await OnReceiveError(new ErrorResult(exception));
|
||||||
{
|
|
||||||
Console.WriteLine($"Telegram API Error:\n[{exApi.ErrorCode}]\n{exApi.Message}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine(exception.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will return the current list of bot commands.
|
/// This will return the current list of bot commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -186,7 +187,41 @@ public class MessageClient
|
|||||||
|
|
||||||
public async Task OnMessageLoop(UpdateResult update)
|
public async Task OnMessageLoop(UpdateResult update)
|
||||||
{
|
{
|
||||||
await (Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
var eventHandlers = (Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
||||||
|
|
||||||
|
if (eventHandlers != null)
|
||||||
|
{
|
||||||
|
await eventHandlers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public event Async.AsyncEventHandler<ErrorResult> ReceiveError
|
||||||
|
{
|
||||||
|
add => Events.AddHandler(EvOnReceiveError, value);
|
||||||
|
remove => Events.RemoveHandler(EvOnReceiveError, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnReceiveError(ErrorResult update)
|
||||||
|
{
|
||||||
|
var eventHandlers = (Events[EvOnReceiveError] as Async.AsyncEventHandler<ErrorResult>)?.Invoke(this, update);
|
||||||
|
|
||||||
|
if (eventHandlers != null)
|
||||||
|
{
|
||||||
|
await eventHandlers;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fallback when no event handler is used.
|
||||||
|
if (update.Exception is ApiRequestException exApi)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Telegram API Error:\n[{exApi.ErrorCode}]\n{exApi.Message}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine(update.Exception.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class UpdateResult : ResultBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override long DeviceId =>
|
public override long DeviceId =>
|
||||||
RawData?.Message?.Chat?.Id
|
RawData?.Message?.Chat?.Id
|
||||||
|
?? RawData?.EditedMessage?.Chat?.Id
|
||||||
?? RawData?.CallbackQuery?.Message?.Chat?.Id
|
?? RawData?.CallbackQuery?.Message?.Chat?.Id
|
||||||
?? Device?.DeviceId
|
?? Device?.DeviceId
|
||||||
?? 0;
|
?? 0;
|
||||||
|
|||||||
@@ -115,12 +115,13 @@ public sealed class BotBase
|
|||||||
if (ds == null)
|
if (ds == null)
|
||||||
{
|
{
|
||||||
ds = await Sessions.StartSession(e.DeviceId);
|
ds = await Sessions.StartSession(e.DeviceId);
|
||||||
e.Device = ds;
|
|
||||||
ds.LastMessage = e.RawData.Message;
|
ds.LastMessage = e.RawData.Message;
|
||||||
|
|
||||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.Device = ds;
|
||||||
|
|
||||||
var mr = new MessageResult(e.RawData);
|
var mr = new MessageResult(e.RawData);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; } = new();
|
private Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a full BotBase instance with all parameters previously set.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public BotBase Build()
|
public BotBase Build()
|
||||||
{
|
{
|
||||||
var bot = new BotBase(_apiKey, _client)
|
var bot = new BotBase(_apiKey, _client)
|
||||||
@@ -204,7 +207,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
#region "Step 4 (Network Settings)"
|
#region "Step 4 (Network Settings)"
|
||||||
|
|
||||||
public IBotCommandsStage WithProxy(string proxyAddress)
|
public IBotCommandsStage WithProxy(string proxyAddress, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
var url = new Uri(proxyAddress);
|
var url = new Uri(proxyAddress);
|
||||||
_client = new MessageClient(_apiKey, url)
|
_client = new MessageClient(_apiKey, url)
|
||||||
@@ -214,11 +217,12 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = new TimeSpan(0, 1, 0)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage NoProxy()
|
public IBotCommandsStage NoProxy(bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey)
|
_client = new MessageClient(_apiKey)
|
||||||
{
|
{
|
||||||
@@ -227,11 +231,12 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage WithBotClient(TelegramBotClient tgclient)
|
public IBotCommandsStage WithBotClient(TelegramBotClient tgclient, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, tgclient)
|
_client = new MessageClient(_apiKey, tgclient)
|
||||||
{
|
{
|
||||||
@@ -240,11 +245,12 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort)
|
public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, proxyHost, proxyPort)
|
_client = new MessageClient(_apiKey, proxyHost, proxyPort)
|
||||||
{
|
{
|
||||||
@@ -253,10 +259,11 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBotCommandsStage WithHttpClient(HttpClient tgclient)
|
public IBotCommandsStage WithHttpClient(HttpClient tgclient, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, tgclient)
|
_client = new MessageClient(_apiKey, tgclient)
|
||||||
{
|
{
|
||||||
@@ -265,6 +272,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,23 +391,41 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
#region "Step 7 (Language)"
|
#region "Step 7 (Language)"
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.DefaultLanguage"/>
|
||||||
public IBuildingStage DefaultLanguage()
|
public IBuildingStage DefaultLanguage()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.UseEnglish"/>
|
||||||
public IBuildingStage UseEnglish()
|
public IBuildingStage UseEnglish()
|
||||||
{
|
{
|
||||||
Default.Language = new English();
|
Default.Language = new English();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.UseGerman"/>
|
||||||
public IBuildingStage UseGerman()
|
public IBuildingStage UseGerman()
|
||||||
{
|
{
|
||||||
Default.Language = new German();
|
Default.Language = new German();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.UsePersian"/>
|
||||||
|
public IBuildingStage UsePersian()
|
||||||
|
{
|
||||||
|
Default.Language = new Persian();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.UseRussian"/>
|
||||||
|
public IBuildingStage UseRussian()
|
||||||
|
{
|
||||||
|
Default.Language = new Russian();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="ILanguageSelectionStage.Custom"/>
|
||||||
public IBuildingStage Custom(Localization language)
|
public IBuildingStage Custom(Localization language)
|
||||||
{
|
{
|
||||||
Default.Language = language;
|
Default.Language = language;
|
||||||
|
|||||||
@@ -2,5 +2,9 @@
|
|||||||
|
|
||||||
public interface IBuildingStage
|
public interface IBuildingStage
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a full BotBase instance with all parameters previously set.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
BotBase Build();
|
BotBase Build();
|
||||||
}
|
}
|
||||||
@@ -2,29 +2,44 @@
|
|||||||
|
|
||||||
namespace TelegramBotBase.Builder.Interfaces;
|
namespace TelegramBotBase.Builder.Interfaces;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the language selection stage in the localization process.
|
||||||
|
/// </summary>
|
||||||
public interface ILanguageSelectionStage
|
public interface ILanguageSelectionStage
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects the default language for control usage. (English)
|
/// Selects the default language for control usage. (English)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage DefaultLanguage();
|
IBuildingStage DefaultLanguage();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects english as the default language for control labels.
|
/// Selects english as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UseEnglish();
|
IBuildingStage UseEnglish();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects german as the default language for control labels.
|
/// Selects german as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UseGerman();
|
IBuildingStage UseGerman();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Selects persian as the default language for control labels.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The next stage in the building process.</returns>
|
||||||
|
IBuildingStage UsePersian();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Selects russian as the default language for control labels.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The next stage in the building process.</returns>
|
||||||
|
IBuildingStage UseRussian();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects a custom language as the default language for control labels.
|
/// Selects a custom language as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage Custom(Localization language);
|
IBuildingStage Custom(Localization language);
|
||||||
}
|
}
|
||||||
@@ -9,22 +9,25 @@ public interface INetworkingSelectionStage
|
|||||||
/// Chooses a proxy as network configuration.
|
/// Chooses a proxy as network configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="proxyAddress"></param>
|
/// <param name="proxyAddress"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBotCommandsStage WithProxy(string proxyAddress);
|
IBotCommandsStage WithProxy(string proxyAddress, bool throwPendingUpdates = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do not choose a proxy as network configuration.
|
/// Do not choose a proxy as network configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBotCommandsStage NoProxy();
|
IBotCommandsStage NoProxy(bool throwPendingUpdates = false);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Chooses a custom instance of TelegramBotClient.
|
/// Chooses a custom instance of TelegramBotClient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBotCommandsStage WithBotClient(TelegramBotClient client);
|
IBotCommandsStage WithBotClient(TelegramBotClient client, bool throwPendingUpdates = false);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,13 +35,15 @@ public interface INetworkingSelectionStage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="proxyHost"></param>
|
/// <param name="proxyHost"></param>
|
||||||
/// <param name="Port"></param>
|
/// <param name="Port"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBotCommandsStage WithHostAndPort(string proxyHost, int Port);
|
IBotCommandsStage WithHostAndPort(string proxyHost, int Port, bool throwPendingUpdates = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uses a custom http client.
|
/// Uses a custom http client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBotCommandsStage WithHttpClient(HttpClient client);
|
IBotCommandsStage WithHttpClient(HttpClient client, bool throwPendingUpdates = false);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.DependencyInjection
|
||||||
|
{
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
internal static FieldInfo _ServiceProviderField = typeof(FormBase).GetField("_serviceProvider", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use Dependency Injection to create new form and inject parameters. (Main variant)
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="NewForm"></typeparam>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<NewForm> NavigateTo<NewForm>(this FormBase current_form, params object[] args)
|
||||||
|
where NewForm : FormBase
|
||||||
|
{
|
||||||
|
var _serviceProvider = current_form.GetServiceProvider();
|
||||||
|
|
||||||
|
var instance = ActivatorUtilities.CreateInstance(_serviceProvider, typeof(NewForm)) as NewForm;
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
return null; //throw new Exception("Could not instantiate new form via DI.");
|
||||||
|
|
||||||
|
instance.SetServiceProvider(_serviceProvider);
|
||||||
|
|
||||||
|
await current_form.NavigateTo(instance, args);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use Dependency Injection to create new form and inject parameters. (Alternative variant)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="current_form"></param>
|
||||||
|
/// <param name="formBaseType"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
public static async Task<FormBase> NavigateTo(this FormBase current_form, Type formBaseType, params object[] args)
|
||||||
|
{
|
||||||
|
if (!typeof(FormBase).IsAssignableFrom(formBaseType))
|
||||||
|
throw new ArgumentException($"{nameof(formBaseType)} argument must be a {nameof(FormBase)} type");
|
||||||
|
|
||||||
|
var _serviceProvider = current_form.GetServiceProvider();
|
||||||
|
|
||||||
|
var instance = ActivatorUtilities.CreateInstance(_serviceProvider, formBaseType) as FormBase;
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
return null; //throw new Exception("Could not instantiate new form via DI.");
|
||||||
|
|
||||||
|
instance.SetServiceProvider(_serviceProvider);
|
||||||
|
|
||||||
|
await current_form.NavigateTo(instance, args);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the internal service provider field.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="form"></param>
|
||||||
|
/// <param name="serviceProvider"></param>
|
||||||
|
public static void SetServiceProvider(this FormBase form, IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
_ServiceProviderField?.SetValue(form, serviceProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the internal service provider field value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="form"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IServiceProvider GetServiceProvider(this FormBase form)
|
||||||
|
{
|
||||||
|
var sp = _ServiceProviderField?.GetValue(form) as IServiceProvider;
|
||||||
|
return sp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ public class DefaultStartFormFactory : IStartFormFactory
|
|||||||
{
|
{
|
||||||
if (!typeof(FormBase).IsAssignableFrom(startFormClass))
|
if (!typeof(FormBase).IsAssignableFrom(startFormClass))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("startFormClass argument must be a FormBase type");
|
throw new ArgumentException($"{nameof(startFormClass)} argument must be a {nameof(FormBase)} type");
|
||||||
}
|
}
|
||||||
|
|
||||||
_startFormClass = startFormClass;
|
_startFormClass = startFormClass;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using TelegramBotBase.DependencyInjection;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
|||||||
{
|
{
|
||||||
if (!typeof(FormBase).IsAssignableFrom(startFormClass))
|
if (!typeof(FormBase).IsAssignableFrom(startFormClass))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("startFormClass argument must be a FormBase type");
|
throw new ArgumentException($"{nameof(startFormClass)} argument must be a {nameof(FormBase)} type");
|
||||||
}
|
}
|
||||||
|
|
||||||
_startFormClass = startFormClass;
|
_startFormClass = startFormClass;
|
||||||
@@ -23,7 +24,12 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
|||||||
|
|
||||||
public FormBase CreateForm()
|
public FormBase CreateForm()
|
||||||
{
|
{
|
||||||
return (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
||||||
|
|
||||||
|
//Sets an internal field for future ServiceProvider navigation
|
||||||
|
fb.SetServiceProvider(_serviceProvider);
|
||||||
|
|
||||||
|
return fb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace TelegramBotBase.Localizations;
|
namespace TelegramBotBase.Localizations;
|
||||||
|
|
||||||
public class English : Localization
|
public sealed class English : Localization
|
||||||
{
|
{
|
||||||
public English()
|
public English()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace TelegramBotBase.Localizations;
|
namespace TelegramBotBase.Localizations;
|
||||||
|
|
||||||
public class German : Localization
|
public sealed class German : Localization
|
||||||
{
|
{
|
||||||
public German()
|
public German()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
namespace TelegramBotBase.Localizations
|
||||||
|
{
|
||||||
|
public sealed class Persian : Localization
|
||||||
|
{
|
||||||
|
public Persian()
|
||||||
|
{
|
||||||
|
Values["Language"] = "فارسی";
|
||||||
|
Values["ButtonGrid_Title"] = "منو";
|
||||||
|
Values["ButtonGrid_NoItems"] = "هیچ آیتمی وجود ندارد.";
|
||||||
|
Values["ButtonGrid_PreviousPage"] = "◀️";
|
||||||
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
|
Values["ButtonGrid_CurrentPage"] = "صفحه ی {0} از {1}";
|
||||||
|
Values["ButtonGrid_SearchFeature"] = "💡 برای فیلتر کردن لیست پیام ارسال کنید. برای بازنشانی فیلتر روی 🔍 کلیک کنید.";
|
||||||
|
Values["ButtonGrid_Back"] = "بازگشت";
|
||||||
|
Values["ButtonGrid_CheckAll"] = "بررسی کردن همه";
|
||||||
|
Values["ButtonGrid_UncheckAll"] = "بررسی نکردن همه";
|
||||||
|
Values["CalendarPicker_Title"] = "تاریخ را انتخاب کنید";
|
||||||
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
|
Values["TreeView_Title"] = "گره را انتخاب کنید";
|
||||||
|
Values["TreeView_LevelUp"] = "🔼 سطح بالا";
|
||||||
|
Values["ToggleButton_On"] = "روشن";
|
||||||
|
Values["ToggleButton_Off"] = "خاموش";
|
||||||
|
Values["ToggleButton_OnIcon"] = "⚫";
|
||||||
|
Values["ToggleButton_OffIcon"] = "⚪";
|
||||||
|
Values["ToggleButton_Title"] = "تغییر وضعیت";
|
||||||
|
Values["ToggleButton_Changed"] = "انتخاب شده";
|
||||||
|
Values["MultiToggleButton_SelectedIcon"] = "✅";
|
||||||
|
Values["MultiToggleButton_Title"] = "چند تعویض";
|
||||||
|
Values["MultiToggleButton_Changed"] = "انتخاب شده";
|
||||||
|
Values["PromptDialog_Back"] = "بازگشت";
|
||||||
|
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
||||||
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
|
Values["ButtonGrid_TagIcon"] = "📁";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
namespace TelegramBotBase.Localizations;
|
||||||
|
|
||||||
|
public sealed class Russian : Localization
|
||||||
|
{
|
||||||
|
public Russian()
|
||||||
|
{
|
||||||
|
Values["Language"] = "Русский (Russian)";
|
||||||
|
Values["ButtonGrid_Title"] = "Меню";
|
||||||
|
Values["ButtonGrid_NoItems"] = "Нет доступных элементов.";
|
||||||
|
Values["ButtonGrid_PreviousPage"] = "◀️";
|
||||||
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
|
Values["ButtonGrid_CurrentPage"] = "Страница {0} из {1}";
|
||||||
|
Values["ButtonGrid_SearchFeature"] = "💡 Отправьте сообщение, чтобы отфильтровать список. Нажмите на 🔍, чтобы сбросить фильтр.";
|
||||||
|
Values["ButtonGrid_Back"] = "Назада";
|
||||||
|
Values["ButtonGrid_CheckAll"] = "Выделить все";
|
||||||
|
Values["ButtonGrid_UncheckAll"] = "Отменить выбор";
|
||||||
|
Values["CalendarPicker_Title"] = "Календарь / Выберите дату";
|
||||||
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
|
Values["TreeView_Title"] = "Выберите пункт";
|
||||||
|
Values["TreeView_LevelUp"] = "🔼 Обратно";
|
||||||
|
Values["ToggleButton_On"] = "Вкл";
|
||||||
|
Values["ToggleButton_Off"] = "Выкл";
|
||||||
|
Values["ToggleButton_OnIcon"] = "⚫";
|
||||||
|
Values["ToggleButton_OffIcon"] = "⚪";
|
||||||
|
Values["ToggleButton_Title"] = "Переключить";
|
||||||
|
Values["ToggleButton_Changed"] = "Выбрано";
|
||||||
|
Values["MultiToggleButton_SelectedIcon"] = "✅";
|
||||||
|
Values["MultiToggleButton_Title"] = "Множественный выбор";
|
||||||
|
Values["MultiToggleButton_Changed"] = "Выбрано";
|
||||||
|
Values["PromptDialog_Back"] = "Назад";
|
||||||
|
Values["ToggleButton_Changed"] = "Настройки изменены";
|
||||||
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
|
Values["ButtonGrid_TagIcon"] = "📁";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,6 +72,12 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Message edited ?
|
||||||
|
if(update.Type == UpdateType.EditedMessage)
|
||||||
|
{
|
||||||
|
await activeForm.Edited(mr);
|
||||||
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction)
|
if (!session.FormSwitched && mr.IsAction)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ public class FullMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Message edited ?
|
||||||
|
if (update.Type == UpdateType.EditedMessage)
|
||||||
|
{
|
||||||
|
await activeForm.Edited(mr);
|
||||||
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction)
|
if (!session.FormSwitched && mr.IsAction)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class JsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException($"{nameof(FallbackStateForm)} is not a subclass of {nameof(FormBase)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class SimpleJsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException($"{nameof(FallbackStateForm)} is not a subclass of {nameof(FormBase)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class XmlStateMachine : IStateMachine
|
|||||||
|
|
||||||
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException($"{nameof(FallbackStateForm)} is not a subclass of {nameof(FormBase)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
FilePath = file ?? throw new ArgumentNullException(nameof(file));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6;net7</TargetFrameworks>
|
||||||
<LangVersion>10</LangVersion>
|
<LangVersion>10</LangVersion>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||||
|
|||||||
@@ -14,12 +14,10 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<group targetFramework=".NETFramework4.6.1">
|
<group targetFramework=".NETFramework4.6.1">
|
||||||
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
||||||
<dependency id="System.Drawing.Common" version="4.6.0" exclude="Build,Analyzers" />
|
|
||||||
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
||||||
</group>
|
</group>
|
||||||
<group targetFramework=".NETStandard2.0">
|
<group targetFramework=".NETStandard2.0">
|
||||||
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
|
||||||
<dependency id="System.Drawing.Common" version="4.6.0" exclude="Build,Analyzers" />
|
|
||||||
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
||||||
</group>
|
</group>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCoreBot", "Examples\EFCor
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotAndWebApplication", "Examples\BotAndWebApplication\BotAndWebApplication.csproj", "{52EA3201-02E8-46F5-87C4-B4752C8A815C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotAndWebApplication", "Examples\BotAndWebApplication\BotAndWebApplication.csproj", "{52EA3201-02E8-46F5-87C4-B4752C8A815C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InlineAndReplyCombination", "Examples\InlineAndReplyCombination\InlineAndReplyCombination.csproj", "{067E8EBE-F90A-4AFF-A0FF-20578216486E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InlineAndReplyCombination", "Examples\InlineAndReplyCombination\InlineAndReplyCombination.csproj", "{067E8EBE-F90A-4AFF-A0FF-20578216486E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyInjection", "Examples\DependencyInjection\DependencyInjection.csproj", "{689B16BC-200E-4C68-BB2E-8B209070849B}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -78,6 +80,10 @@ Global
|
|||||||
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{067E8EBE-F90A-4AFF-A0FF-20578216486E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{689B16BC-200E-4C68-BB2E-8B209070849B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{689B16BC-200E-4C68-BB2E-8B209070849B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -91,6 +97,7 @@ Global
|
|||||||
{261BED47-0404-4A9A-86FC-047DE42A7D25} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
{261BED47-0404-4A9A-86FC-047DE42A7D25} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||||
{52EA3201-02E8-46F5-87C4-B4752C8A815C} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
{52EA3201-02E8-46F5-87C4-B4752C8A815C} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||||
{067E8EBE-F90A-4AFF-A0FF-20578216486E} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
{067E8EBE-F90A-4AFF-A0FF-20578216486E} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||||
|
{689B16BC-200E-4C68-BB2E-8B209070849B} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}
|
SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}
|
||||||
|
|||||||
Reference in New Issue
Block a user