Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07ac1502b4 | ||
|
|
07cbb8bfa4 | ||
|
|
139ccbb136 | ||
|
|
f4bc2ca9b0 | ||
|
|
880878190d | ||
|
|
3f0fc962a4 | ||
|
|
6a80ec66ad | ||
|
|
0931147f5a | ||
|
|
a81d299010 | ||
|
|
956fbd47f0 | ||
|
|
4210ecbb4f | ||
|
|
9dc7490015 | ||
|
|
877d2daa30 | ||
|
|
55027b92aa | ||
|
|
ec4bb85d40 | ||
|
|
db0afd4668 | ||
|
|
3ab24dcd37 | ||
|
|
4b42644593 | ||
|
|
3b792ee676 | ||
|
|
367de14a1a | ||
|
|
82e6d79ec4 | ||
|
|
5d2f3e7fe9 | ||
|
|
7aa40b3e2d | ||
|
|
eb8fad444b | ||
|
|
5cda9e1fdc | ||
|
|
41bdf52afe | ||
|
|
9023875922 | ||
|
|
05bfeb8d09 | ||
|
|
1f1aa1f0ee | ||
|
|
3d97da75f1 | ||
|
|
261fdafd96 | ||
|
|
39e68a2089 | ||
|
|
312690c002 | ||
|
|
99b888a7a2 | ||
|
|
6adcc52ea2 | ||
|
|
834038ff44 | ||
|
|
e3d1652a02 | ||
|
|
a7411176e6 | ||
|
|
801c0b77f8 | ||
|
|
7a86ecdf32 | ||
|
|
175927fbab | ||
|
|
34e4429b38 | ||
|
|
dc28bde382 | ||
|
|
87d57c471a | ||
|
|
5ce2360cc7 | ||
|
|
e345fc2948 | ||
|
|
652526ec59 | ||
|
|
b829f43c5d | ||
|
|
6e7acdbdba | ||
|
|
396a524d94 | ||
|
|
7d679649e4 | ||
|
|
2db8e2cf63 | ||
|
|
6b7f2ca273 | ||
|
|
31d0d9890d | ||
|
|
b252829296 | ||
|
|
a483bc7c0b | ||
|
|
4635a96fc7 | ||
|
|
727375f7aa | ||
|
|
86792af214 | ||
|
|
b3edb95b55 | ||
|
|
946420f9c6 | ||
|
|
c8c56a42c0 | ||
|
|
6f930eee8c | ||
|
|
c4a589d476 | ||
|
|
1b14b7b3cf | ||
|
|
cb5fa35269 | ||
|
|
f60e1000c3 | ||
|
|
00dafd59a3 | ||
|
|
848b5d29cf | ||
|
|
9cac57b8e7 | ||
|
|
52517534f8 | ||
|
|
5e166db243 | ||
|
|
71aa0c3d91 | ||
|
|
e34c71b42b | ||
|
|
9927a034b0 | ||
|
|
2e454d7f5c | ||
|
|
339319ef2a | ||
|
|
c8b12e9168 | ||
|
|
cbc31b8ff5 | ||
|
|
c514ede03f | ||
|
|
c91fbaa16c | ||
|
|
b8125e9aed | ||
|
|
d4af8797fb | ||
|
|
b14913362e | ||
|
|
a632440efd | ||
|
|
194d8ba317 | ||
|
|
b20b3b2826 | ||
|
|
c1d1d5f543 | ||
|
|
078bdfb163 | ||
|
|
94c680e036 | ||
|
|
dbdc40582a | ||
|
|
2d3393aa05 | ||
|
|
fdd814c88e | ||
|
|
2b06fba8ff | ||
|
|
8e4bc7a222 | ||
|
|
deef8dd086 | ||
|
|
3aff0aa94b | ||
|
|
75064fd64c | ||
|
|
0cafca9aee | ||
|
|
ad40675b87 | ||
|
|
26152ee348 | ||
|
|
d5ffa914f0 | ||
|
|
7fcaa407ad |
48
.gitea/workflows/TelegramBotFramework.nuget.yaml
Normal file
48
.gitea/workflows/TelegramBotFramework.nuget.yaml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
name: build nuget workflow for TelegramBotBase project
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build-TelegramBotBase:
|
||||||
|
env:
|
||||||
|
APP_PROJECT_NAME: TelegramBotBase
|
||||||
|
PACKAGE_VERSION: "123.1.6"
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
# - win
|
||||||
|
arch:
|
||||||
|
- x64
|
||||||
|
#- x32
|
||||||
|
#- arch64
|
||||||
|
runs-on: [ "${{ matrix.os }}" ]
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup dotnet
|
||||||
|
uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: '8.0.x'
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore $APP_PROJECT_NAME /p:Version=$PACKAGE_VERSION
|
||||||
|
|
||||||
|
- name: Build app
|
||||||
|
run: dotnet build -c Release --version-suffix $PACKAGE_VERSION --no-restore $APP_PROJECT_NAME /p:Version=$PACKAGE_VERSION
|
||||||
|
|
||||||
|
- name: Pack app
|
||||||
|
run: dotnet pack --no-build $APP_PROJECT_NAME /p:Version=$PACKAGE_VERSION
|
||||||
|
|
||||||
|
- name: disconnect old source
|
||||||
|
run: dotnet nuget remove source gitea
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Connect source
|
||||||
|
run: dotnet nuget add source --name gitea https://git.kosyakmakc.ru/api/packages/kosyakmakc/nuget/index.json
|
||||||
|
|
||||||
|
- name: Upload nuget package
|
||||||
|
run: dotnet nuget push --source gitea --api-key ${{ secrets.kosyakmakc_nuget_publish }} ${{ gitea.workspace }}/${{ env.APP_PROJECT_NAME }}/bin/Release/$APP_PROJECT_NAME.$PACKAGE_VERSION.nupkg
|
||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="5.3.0" />
|
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace BotAndWebApplication.BotStuff.Tasks
|
|||||||
.DefaultCommands()
|
.DefaultCommands()
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseThreadPool()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ namespace DependencyInjection
|
|||||||
.NoCommands()
|
.NoCommands()
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.DefaultLanguage()
|
.DefaultLanguage()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9"/>
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9"/>
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -18,6 +18,7 @@ var bot = BotBaseBuilder.Create()
|
|||||||
.NoCommands()
|
.NoCommands()
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.DefaultLanguage()
|
.DefaultLanguage()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -21,6 +21,7 @@ namespace InlineAndReplyCombination
|
|||||||
.DefaultCommands()
|
.DefaultCommands()
|
||||||
.UseJSON(Path.Combine(Directory.GetCurrentDirectory(), "states.json"))
|
.UseJSON(Path.Combine(Directory.GetCurrentDirectory(), "states.json"))
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
<PackageReference Include="TelegramBotBase" Version="6.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
120
README.md
120
README.md
@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
**Releases: [GitHub](https://github.com/MajMcCloud/TelegramBotFramework/releases)**
|
||||||
|
|
||||||
|
**Need your own bot? Get in touch https://t.me/botbasebuilder**
|
||||||
|
|
||||||
|
**on X: @florian_zevedei**
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
|
||||||
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
Paypal: [https://paypal.me/majmccloud](https://paypal.me/majmccloud)
|
||||||
@ -102,6 +106,7 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Upload bot commands to BotFather
|
// Upload bot commands to BotFather
|
||||||
@ -122,8 +127,32 @@ like ChatId and other stuff your carrying.
|
|||||||
From there you build up your bots:
|
From there you build up your bots:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class StartForm : FormBase
|
public class Start : FormBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public Start()
|
||||||
|
{
|
||||||
|
//Additional event handlers
|
||||||
|
Init += Start_Init;
|
||||||
|
Opened += Start_Opened;
|
||||||
|
Closed += Start_Closed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets invoked on initialization, before navigation
|
||||||
|
private async Task Start_Init(object sender, Args.InitEventArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets invoked after opened
|
||||||
|
private async Task Start_Opened(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets invoked after form has been closed
|
||||||
|
private async Task Start_Closed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Gets invoked during Navigation to this form
|
// Gets invoked during Navigation to this form
|
||||||
public override async Task PreLoad(MessageResult message)
|
public override async Task PreLoad(MessageResult message)
|
||||||
{
|
{
|
||||||
@ -220,6 +249,7 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.BotCommand += async (s, en) =>
|
bot.BotCommand += async (s, en) =>
|
||||||
@ -260,15 +290,15 @@ public class SimpleForm : AutoCleanForm
|
|||||||
{
|
{
|
||||||
public SimpleForm()
|
public SimpleForm()
|
||||||
{
|
{
|
||||||
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
|
DeleteSide = EDeleteSide.Both;
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Opened += SimpleForm_Opened;
|
Opened += SimpleForm_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
await Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
public override async Task Load(MessageResult message)
|
||||||
@ -306,7 +336,13 @@ public class SimpleForm : AutoCleanForm
|
|||||||
```csharp
|
```csharp
|
||||||
public class ButtonTestForm : AutoCleanForm
|
public class ButtonTestForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
public override async Task Opened()
|
public ButtonTestForm()
|
||||||
|
{
|
||||||
|
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
||||||
|
Opened += ButtonTestForm_Opened;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ButtonTestForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
||||||
}
|
}
|
||||||
@ -376,9 +412,10 @@ public class ProgressTest : AutoCleanForm
|
|||||||
public ProgressTest()
|
public ProgressTest()
|
||||||
{
|
{
|
||||||
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
this.DeleteMode = eDeleteMode.OnLeavingForm;
|
||||||
|
Opened += ProgressTest_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Opened()
|
private async Task ProgressTest_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Welcome to ProgressTest");
|
await this.Device.Send("Welcome to ProgressTest");
|
||||||
}
|
}
|
||||||
@ -723,6 +760,7 @@ The current available languages for controls are:
|
|||||||
- English
|
- English
|
||||||
- German
|
- German
|
||||||
- Persian
|
- Persian
|
||||||
|
- Russian
|
||||||
|
|
||||||
You can add other languages easily by creating a subclass of the [TelegramBotBase/Localizations/Localization.cs](TelegramBotBase/Localizations/Localization.cs) class.
|
You can add other languages easily by creating a subclass of the [TelegramBotBase/Localizations/Localization.cs](TelegramBotBase/Localizations/Localization.cs) class.
|
||||||
|
|
||||||
@ -857,6 +895,7 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json")
|
.UseSimpleJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -880,6 +919,7 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseJSON(AppContext.BaseDirectory + "config\\states.json")
|
.UseJSON(AppContext.BaseDirectory + "config\\states.json")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -902,6 +942,7 @@ var bot = BotBaseBuilder
|
|||||||
})
|
})
|
||||||
.UseXML(AppContext.BaseDirectory + "config\\states.xml")
|
.UseXML(AppContext.BaseDirectory + "config\\states.xml")
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseSingleThread()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await bot.Start();
|
await bot.Start();
|
||||||
@ -915,7 +956,7 @@ datatype and one for implementing into a form which should be invoked with event
|
|||||||
#### IStateMachine
|
#### IStateMachine
|
||||||
|
|
||||||
Is the basic StateMachine interface, it has two methods `SaveFormStates(SaveStatesEventArgs e)`
|
Is the basic StateMachine interface, it has two methods `SaveFormStates(SaveStatesEventArgs e)`
|
||||||
and `StateContainerLoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
and `LoadFormStates()`, nothing fancy, just simple calls. Implement both methods with your own
|
||||||
serialization process.
|
serialization process.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
@ -1039,6 +1080,8 @@ again at 1 (due to `PopAsync` or `PopToRootAsync` calls) it will replace the con
|
|||||||
you
|
you
|
||||||
have given to the constructor at the beginning.*
|
have given to the constructor at the beginning.*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Extensions
|
## Extensions
|
||||||
|
|
||||||
### TelegramBotBase.Extensions.Images
|
### TelegramBotBase.Extensions.Images
|
||||||
@ -1048,7 +1091,43 @@ Extends the base package with some additional image methods like SendPhoto (usin
|
|||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images)
|
||||||
|
|
||||||
[https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
Source code: [TelegramBotBase.Extensions.Images/](/TelegramBotBase.Extensions.Images/)
|
||||||
|
|
||||||
|
Nuget package: [https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### TelegramBotBase.Extensions.Images.IronSoftware
|
||||||
|
|
||||||
|
Extends the base package with some additional image methods like SendPhoto (using Bitmap)
|
||||||
|
|
||||||
|
Important: This extension uses the IronSoftware drawing library.
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware)
|
||||||
|
|
||||||
|
[https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
|
||||||
|
Source code: [TelegramBotBase.Extensions.Images.IronSoftware/](TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
|
||||||
|
Nuget package: [https://www.nuget.org/packages/TelegramBotBase.Extensions.IronSoftware/](https://www.nuget.org/packages/TelegramBotBase.Extensions.IronSoftware/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Project: [open source](TelegramBotBase.Extensions.Images/)
|
||||||
|
|
||||||
|
### TelegramBotBase.Extensions.Images.IronSoftware
|
||||||
|
|
||||||
|
Extends the base package with some additional image methods like SendPhoto (using Bitmap)
|
||||||
|
|
||||||
|
Important: This extension uses the IronSoftware drawing library.
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware)
|
||||||
|
|
||||||
|
[https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
|
||||||
|
Project: [open source](TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
|
||||||
### TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
### TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||||
|
|
||||||
@ -1057,7 +1136,28 @@ A session serializer for Microsoft SQL Server.
|
|||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL)
|
||||||
|
|
||||||
[https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
Source code: [TelegramBotBase.Extensions.Serializer.Database.MSSQL/](/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||||
|
|
||||||
|
Nuget package: [https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### TelegramBotBase.Extensions.Serializer.Database.PostgreSql
|
||||||
|
|
||||||
|
A session serializer for PostgreSql Server.
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSql/)
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSql)
|
||||||
|
|
||||||
|
Source code: [TelegramBotBase.Extensions.Serializer.Database.PostgreSql/](/TelegramBotBase.Extensions.Serializer.Database.PostgreSql/)
|
||||||
|
|
||||||
|
Nuget package: [https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSql/](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSql/)
|
||||||
|
|
||||||
|
Credits: [@Kataane](https://github.com/Kataane)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Project: [open source](TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||||
|
|
||||||
## Test Project
|
## Test Project
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
using IronSoftware.Drawing;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Sessions;
|
||||||
|
using static IronSoftware.Drawing.AnyBitmap;
|
||||||
|
using SKImage = SixLabors.ImageSharp.Image;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Extensions.Images.IronSoftware
|
||||||
|
{
|
||||||
|
public static class ImageExtensions
|
||||||
|
{
|
||||||
|
public static Stream ToStream(this AnyBitmap image, ImageFormat format)
|
||||||
|
{
|
||||||
|
var stream = new MemoryStream();
|
||||||
|
image.ExportStream(stream, format);
|
||||||
|
stream.Position = 0;
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Stream> ToStream(this SKImage image)
|
||||||
|
{
|
||||||
|
var stream = new MemoryStream();
|
||||||
|
await image.SaveAsPngAsync(stream);
|
||||||
|
stream.Position = 0;
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends an image
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="buttons"></param>
|
||||||
|
/// <param name="replyTo"></param>
|
||||||
|
/// <param name="disableNotification"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<Message> SendPhoto(this DeviceSession session, AnyBitmap image, string name,
|
||||||
|
string caption, ButtonForm buttons = null, int replyTo = 0,
|
||||||
|
bool disableNotification = false)
|
||||||
|
{
|
||||||
|
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||||
|
{
|
||||||
|
var fts = InputFile.FromStream(fileStream, name);
|
||||||
|
|
||||||
|
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends an image
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <param name="buttons"></param>
|
||||||
|
/// <param name="replyTo"></param>
|
||||||
|
/// <param name="disableNotification"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<Message> SendPhoto(this DeviceSession session, SKImage image, string name,
|
||||||
|
string caption, ButtonForm buttons = null, int replyTo = 0,
|
||||||
|
bool disableNotification = false)
|
||||||
|
{
|
||||||
|
using (var fileStream = await ToStream(image))
|
||||||
|
{
|
||||||
|
var fts = InputFile.FromStream(fileStream, name);
|
||||||
|
|
||||||
|
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
TelegramBotBase.Extensions.Images.IronSoftware/README.md
Normal file
12
TelegramBotBase.Extensions.Images.IronSoftware/README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# TelegramBotBase.Extensions.Images.IronSoftware
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware/)
|
||||||
|
[](https://www.t.me/tgbotbase)
|
||||||
|
|
||||||
|
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images.IronSoftware)
|
||||||
|
|
||||||
|
|
||||||
|
This extension uses the [IronSoftware](https://ironsoftware.com/open-source/csharp/drawing/docs/) drawing library.
|
||||||
|
|
||||||
|
Check [https://ironsoftware.com/open-source/csharp/drawing/docs/](https://ironsoftware.com/open-source/csharp/drawing/docs/) for more details on this library.
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
||||||
|
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework/tree/development/TelegramBotBase.Extensions.Images.IronSoftware</RepositoryUrl>
|
||||||
|
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework/tree/development/TelegramBotBase.Extensions.Images.IronSoftware</PackageProjectUrl>
|
||||||
|
<Copyright>MIT</Copyright>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
<AssemblyVersion>1.0.1</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.1</FileVersion>
|
||||||
|
<Description>This is an extension for sending Bitmap/Images platform independent by using IronSoftware's drawing library via TelegramBotBase.</Description>
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.5.1" />
|
||||||
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
||||||
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework/tree/development/TelegramBotBase.Extensions.Images</RepositoryUrl>
|
||||||
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework/tree/development/TelegramBotBase.Extensions.Images</PackageProjectUrl>
|
||||||
<Copyright>MIT</Copyright>
|
<Copyright>MIT</Copyright>
|
||||||
<IncludeSymbols>true</IncludeSymbols>
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||||
|
<Authors>$(AssemblyName)</Authors>
|
||||||
|
<Description>This is an extension for sending Bitmap/Images via TelegramBotBase.</Description>
|
||||||
|
<FileVersion>1.1.1</FileVersion>
|
||||||
|
<AssemblyVersion>1.1.1</AssemblyVersion>
|
||||||
|
<Version>1.1.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -15,14 +21,11 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||||
|
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
|
||||||
<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>
|
||||||
|
|||||||
@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using TelegramBotBase.Builder;
|
||||||
|
using TelegramBotBase.Builder.Interfaces;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Extensions.Serializer.Database.PostgreSql
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides extension methods for configuring the use of PostgreSQL Server Database for session serialization.
|
||||||
|
/// </summary>
|
||||||
|
public static class BotBaseBuilderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Uses an PostgreSQL Server Database to save and restore sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The session serialization stage builder.</param>
|
||||||
|
/// <param name="connectionString">The connection string to the PostgreSQL database.</param>
|
||||||
|
/// <param name="fallbackForm">The fallback form type.</param>
|
||||||
|
/// <param name="tablePrefix">The prefix for database table names (default is "tgb_").</param>
|
||||||
|
/// <returns>The language selection stage builder.</returns>
|
||||||
|
public static ILanguageSelectionStage UsePostgreSqlDatabase(
|
||||||
|
this ISessionSerializationStage builder,
|
||||||
|
string connectionString, Type fallbackForm = null,
|
||||||
|
string tablePrefix = "tgb_")
|
||||||
|
{
|
||||||
|
var serializer = new PostgreSqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
|
return builder as BotBaseBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uses an PostgreSQL Server Database to save and restore sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The session serialization stage builder.</param>
|
||||||
|
/// <param name="hostOrIp">The host or IP address of the PostgreSQL server.</param>
|
||||||
|
/// <param name="port">The port number for the PostgreSQL server.</param>
|
||||||
|
/// <param name="databaseName">The name of the PostgreSQL database.</param>
|
||||||
|
/// <param name="userId">The user ID for connecting to the PostgreSQL server.</param>
|
||||||
|
/// <param name="password">The password for connecting to the PostgreSQL server.</param>
|
||||||
|
/// <param name="fallbackForm">The fallback form type.</param>
|
||||||
|
/// <param name="tablePrefix">The prefix for database table names (default is "tgb_").</param>
|
||||||
|
/// <returns>The language selection stage builder.</returns>
|
||||||
|
public static ILanguageSelectionStage UsePostgreSqlDatabase(
|
||||||
|
this ISessionSerializationStage builder,
|
||||||
|
string hostOrIp, int port,
|
||||||
|
string databaseName, string userId,
|
||||||
|
string password, Type fallbackForm = null,
|
||||||
|
string tablePrefix = "tgb_")
|
||||||
|
{
|
||||||
|
var connectionString = $"Host={hostOrIp};Port={port};Database={databaseName};Username={userId};Password={password}";
|
||||||
|
|
||||||
|
var serializer = new PostgreSqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
|
return builder as BotBaseBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uses an PostgreSQL Server Database with Windows Authentication to save and restore sessions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The session serialization stage builder.</param>
|
||||||
|
/// <param name="hostOrIp">The host or IP address of the PostgreSQL server.</param>
|
||||||
|
/// <param name="port">The port number for the PostgreSQL server.</param>
|
||||||
|
/// <param name="databaseName">The name of the PostgreSQL database.</param>
|
||||||
|
/// <param name="integratedSecurity">A flag indicating whether to use Windows Authentication (true) or not (false).</param>
|
||||||
|
/// <param name="fallbackForm">The fallback form type.</param>
|
||||||
|
/// <param name="tablePrefix">The prefix for database table names (default is "tgb_").</param>
|
||||||
|
/// <returns>The language selection stage builder.</returns>
|
||||||
|
public static ILanguageSelectionStage UsePostgreSqlDatabase(
|
||||||
|
this ISessionSerializationStage builder,
|
||||||
|
string hostOrIp, int port,
|
||||||
|
string databaseName, bool integratedSecurity = true,
|
||||||
|
Type fallbackForm = null, string tablePrefix = "tgb_")
|
||||||
|
{
|
||||||
|
if (!integratedSecurity)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
var connectionString = $"Host={hostOrIp};Port={port};Database={databaseName};Integrated Security=true;";
|
||||||
|
|
||||||
|
var serializer = new PostgreSqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
|
return builder as BotBaseBuilder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,252 @@
|
|||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using NpgsqlTypes;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Extensions.Serializer.Database.PostgreSql
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a PostgreSQL implementation of the <see cref="IStateMachine"/> for saving and loading form states.
|
||||||
|
/// </summary>
|
||||||
|
public class PostgreSqlSerializer : IStateMachine
|
||||||
|
{
|
||||||
|
private readonly string insertIntoSessionSql;
|
||||||
|
private readonly string insertIntoSessionsDataSql;
|
||||||
|
private readonly string selectAllDevicesSessionsSql;
|
||||||
|
private readonly string selectAllDevicesSessionsDataSql;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="PostgreSqlSerializer"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionString">The connection string to the PostgreSQL database.</param>
|
||||||
|
/// <param name="tablePrefix">The prefix for database table names (default is "tgb_").</param>
|
||||||
|
/// <param name="fallbackStateForm">The fallback state form type.</param>
|
||||||
|
/// <exception cref="ArgumentNullException">Thrown when <paramref name="connectionString"/> is null.</exception>
|
||||||
|
/// <exception cref="ArgumentException">Thrown when <paramref name="fallbackStateForm"/> is not a subclass of <see cref="FormBase"/>.</exception>
|
||||||
|
public PostgreSqlSerializer(string connectionString, string tablePrefix = "tgb_", Type fallbackStateForm = null)
|
||||||
|
{
|
||||||
|
ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||||
|
|
||||||
|
TablePrefix = tablePrefix;
|
||||||
|
|
||||||
|
FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"{nameof(FallbackStateForm)} is not a subclass of {nameof(FormBase)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
insertIntoSessionSql = "INSERT INTO " + TablePrefix +
|
||||||
|
"devices_sessions (deviceId, deviceTitle, \"FormUri\", \"QualifiedName\") VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
||||||
|
insertIntoSessionsDataSql = "INSERT INTO " + TablePrefix + "devices_sessions_data (deviceId, key, value, type) VALUES (@deviceId, @key, @value, @type)";
|
||||||
|
|
||||||
|
selectAllDevicesSessionsSql = "SELECT * FROM " + TablePrefix + "devices_sessions";
|
||||||
|
selectAllDevicesSessionsDataSql = "SELECT * FROM " + TablePrefix + "devices_sessions_data WHERE deviceId = @deviceId";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the connection string to the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
public string ConnectionString { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the table name prefix for database tables.
|
||||||
|
/// </summary>
|
||||||
|
public string TablePrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the fallback state form type.
|
||||||
|
/// </summary>
|
||||||
|
public Type FallbackStateForm { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
/// <summary>
|
||||||
|
/// Saves form states to the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">The <see cref="SaveStatesEventArgs"/> containing the states to be saved.</param>
|
||||||
|
public void SaveFormStates(SaveStatesEventArgs e)
|
||||||
|
{
|
||||||
|
var container = e.States;
|
||||||
|
|
||||||
|
//Cleanup old Session data
|
||||||
|
Cleanup();
|
||||||
|
|
||||||
|
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
//Store session data in database
|
||||||
|
foreach (var state in container.States)
|
||||||
|
{
|
||||||
|
using (var sessionCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
sessionCommand.CommandText = insertIntoSessionSql;
|
||||||
|
|
||||||
|
sessionCommand.Parameters.Add(new NpgsqlParameter("@deviceId", NpgsqlDbType.Bigint){Value = state.DeviceId });
|
||||||
|
sessionCommand.Parameters.Add(new NpgsqlParameter("@deviceTitle", DbType.StringFixedLength){Value = state.ChatTitle ?? string.Empty});
|
||||||
|
sessionCommand.Parameters.Add(new NpgsqlParameter("@FormUri", DbType.StringFixedLength) {Value = state.FormUri});
|
||||||
|
sessionCommand.Parameters.Add(new NpgsqlParameter("@QualifiedName", DbType.StringFixedLength){Value = state.QualifiedName });
|
||||||
|
|
||||||
|
sessionCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
foreach (var state in container.States)
|
||||||
|
{
|
||||||
|
SaveSessionsData(state, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
/// <summary>
|
||||||
|
/// Loads form states from the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A <see cref="StateContainer"/> containing the loaded form states.</returns>
|
||||||
|
public StateContainer LoadFormStates()
|
||||||
|
{
|
||||||
|
var stateContainer = new StateContainer();
|
||||||
|
|
||||||
|
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using (var sessionCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
sessionCommand.CommandText = selectAllDevicesSessionsSql;
|
||||||
|
|
||||||
|
var sessionTable = new DataTable();
|
||||||
|
using (var dataAdapter = new NpgsqlDataAdapter(sessionCommand))
|
||||||
|
{
|
||||||
|
dataAdapter.Fill(sessionTable);
|
||||||
|
|
||||||
|
foreach (DataRow row in sessionTable.Rows)
|
||||||
|
{
|
||||||
|
var stateEntry = new StateEntry
|
||||||
|
{
|
||||||
|
DeviceId = (long)row["deviceId"],
|
||||||
|
ChatTitle = row["deviceTitle"].ToString(),
|
||||||
|
FormUri = row["FormUri"].ToString(),
|
||||||
|
QualifiedName = row["QualifiedName"].ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
stateContainer.States.Add(stateEntry);
|
||||||
|
|
||||||
|
if (stateEntry.DeviceId > 0)
|
||||||
|
{
|
||||||
|
stateContainer.ChatIds.Add(stateEntry.DeviceId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stateContainer.GroupIds.Add(stateEntry.DeviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadDataTable(connection, row, stateEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleans up old session data in the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
private void Cleanup()
|
||||||
|
{
|
||||||
|
using (var connection = new NpgsqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using (var clearCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
clearCommand.CommandText = $"DELETE FROM {TablePrefix}devices_sessions_data";
|
||||||
|
clearCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var clearCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
clearCommand.CommandText = $"DELETE FROM {TablePrefix}devices_sessions";
|
||||||
|
clearCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves session data to the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The state entry containing session data to be saved.</param>
|
||||||
|
/// <param name="connection">The NpgsqlConnection used for the database interaction.</param>
|
||||||
|
private void SaveSessionsData(StateEntry state, NpgsqlConnection connection)
|
||||||
|
{
|
||||||
|
foreach (var data in state.Values)
|
||||||
|
{
|
||||||
|
using (var dataCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
dataCommand.CommandText = insertIntoSessionsDataSql;
|
||||||
|
|
||||||
|
dataCommand.Parameters.Add(new NpgsqlParameter("@deviceId", NpgsqlDbType.Bigint) { Value = state.DeviceId });
|
||||||
|
dataCommand.Parameters.Add(new NpgsqlParameter("@key", DbType.StringFixedLength) { Value = data.Key });
|
||||||
|
|
||||||
|
var type = data.Value.GetType();
|
||||||
|
|
||||||
|
if (type.IsPrimitive || type == typeof(string))
|
||||||
|
{
|
||||||
|
dataCommand.Parameters.Add(new NpgsqlParameter("@value", NpgsqlDbType.Text) { Value = data.Value });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var json = System.Text.Json.JsonSerializer.Serialize(data.Value);
|
||||||
|
dataCommand.Parameters.Add(new NpgsqlParameter("@value", NpgsqlDbType.Text) { Value = json });
|
||||||
|
}
|
||||||
|
|
||||||
|
dataCommand.Parameters.Add(new NpgsqlParameter("@type", DbType.StringFixedLength) { Value = type.AssemblyQualifiedName });
|
||||||
|
|
||||||
|
dataCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads session data from the PostgreSQL database.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection">The NpgsqlConnection used for the database interaction.</param>
|
||||||
|
/// <param name="row">The DataRow representing a session entry in the main sessions table.</param>
|
||||||
|
/// <param name="stateEntry">The StateEntry object to which session data will be loaded.</param>
|
||||||
|
private void LoadDataTable(NpgsqlConnection connection, DataRow row, StateEntry stateEntry)
|
||||||
|
{
|
||||||
|
using (var sessionCommand = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
sessionCommand.CommandText = selectAllDevicesSessionsDataSql;
|
||||||
|
sessionCommand.Parameters.Add(new NpgsqlParameter("@deviceId", row["deviceId"]));
|
||||||
|
|
||||||
|
var dataCommandTable = new DataTable();
|
||||||
|
using (var npgSqlDataAdapter = new NpgsqlDataAdapter(sessionCommand))
|
||||||
|
{
|
||||||
|
npgSqlDataAdapter.Fill(dataCommandTable);
|
||||||
|
|
||||||
|
foreach (DataRow dataRow in dataCommandTable.Rows)
|
||||||
|
{
|
||||||
|
var key = dataRow["key"].ToString();
|
||||||
|
var type = Type.GetType(dataRow["type"].ToString());
|
||||||
|
|
||||||
|
var value = System.Text.Json.JsonSerializer.Deserialize(dataRow["value"].ToString(), type);
|
||||||
|
|
||||||
|
stateEntry.Values.Add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
# TelegramBotBase.Extensions.Serializer.Database.PostgreSQL
|
||||||
|
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSQL/)
|
||||||
|
[](https://www.t.me/tgbotbase)
|
||||||
|
|
||||||
|
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||||
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.PostgreSQL)
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using TelegramBotBase.Extensions.Serializer.Database.PostgreSQL;
|
||||||
|
|
||||||
|
|
||||||
|
var bot = BotBaseBuilder
|
||||||
|
.Create()
|
||||||
|
.WithAPIKey(APIKey)
|
||||||
|
.DefaultMessageLoop()
|
||||||
|
.WithStartForm<Start>()
|
||||||
|
.NoProxy()
|
||||||
|
.OnlyStart()
|
||||||
|
.UsePostgreSqlDatabase("localhost", "8181", "telegram_bot")
|
||||||
|
.UseEnglish()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
bot.Start();
|
||||||
|
```
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6</TargetFrameworks>
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
||||||
|
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
||||||
|
<Copyright>MIT</Copyright>
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||||
|
<AssemblyVersion>1.0.1</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.1</FileVersion>
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
<Description>
|
||||||
|
A session serializer for PostgreSQL Server.
|
||||||
|
</Description>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="TelegramBotBase" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Npgsql" Version="8.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
-- Enable uuid-ossp extension
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
-- Create table tgb_devices_sessions
|
||||||
|
CREATE TABLE tgb_devices_sessions (
|
||||||
|
deviceId bigint NOT NULL,
|
||||||
|
deviceTitle character varying(512) NOT NULL,
|
||||||
|
"FormUri" character varying(512) NOT NULL,
|
||||||
|
"QualifiedName" character varying(512) NOT NULL,
|
||||||
|
CONSTRAINT PK_tgb_devices_sessions_1 PRIMARY KEY (deviceId)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create table tgb_devices_sessions_data
|
||||||
|
CREATE TABLE tgb_devices_sessions_data (
|
||||||
|
Id uuid DEFAULT uuid_generate_v4() NOT NULL,
|
||||||
|
deviceId bigint NOT NULL,
|
||||||
|
key character varying(512) NOT NULL,
|
||||||
|
"value" text NOT NULL,
|
||||||
|
"type" character varying(512) NOT NULL,
|
||||||
|
CONSTRAINT PK_tgb_devices_session_data PRIMARY KEY (Id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add default constraint for Id column in tgb_devices_sessions_data
|
||||||
|
ALTER TABLE tgb_devices_sessions_data
|
||||||
|
ALTER COLUMN Id SET DEFAULT uuid_generate_v4();
|
||||||
@ -32,6 +32,7 @@ internal class Program
|
|||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
|
.UseThreadPool()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj" />
|
<PackageReference Include="TelegramBotBase.Extensions.Images" Version="1.1.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Document.FileSize.Value);
|
encryptedContent.SetLength(Document.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId,
|
||||||
encryptedContent);
|
encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, Document.FileName);
|
return InputFile.FromStream(encryptedContent, Document.FileName);
|
||||||
@ -69,9 +69,9 @@ public class DataResult : ResultBase
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task DownloadDocument(string path)
|
public async Task DownloadDocument(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(Document.FileId);
|
var file = await Device.Client.TelegramClient.GetFile(Document.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ public class DataResult : ResultBase
|
|||||||
public async Task<byte[]> DownloadRawDocument()
|
public async Task<byte[]> DownloadRawDocument()
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ public class DataResult : ResultBase
|
|||||||
public async Task<string> DownloadRawTextDocument(Encoding encoding)
|
public async Task<string> DownloadRawTextDocument(Encoding encoding)
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFile(Document.FileId, ms);
|
||||||
|
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
@ -116,16 +116,16 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Video.FileSize.Value);
|
encryptedContent.SetLength(Video.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Video.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Video.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadVideo(string path)
|
public async Task DownloadVideo(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(Video.FileId);
|
var file = await Device.Client.TelegramClient.GetFile(Video.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -134,16 +134,16 @@ public class DataResult : ResultBase
|
|||||||
{
|
{
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(Audio.FileSize.Value);
|
encryptedContent.SetLength(Audio.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Audio.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(Audio.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadAudio(string path)
|
public async Task DownloadAudio(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(Audio.FileId);
|
var file = await Device.Client.TelegramClient.GetFile(Audio.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ public class DataResult : ResultBase
|
|||||||
var photo = Photos[index];
|
var photo = Photos[index];
|
||||||
var encryptedContent = new MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(photo.FileSize.Value);
|
encryptedContent.SetLength(photo.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFile(photo.FileId, encryptedContent);
|
||||||
|
|
||||||
return InputFile.FromStream(encryptedContent, "");
|
return InputFile.FromStream(encryptedContent, "");
|
||||||
}
|
}
|
||||||
@ -161,9 +161,9 @@ public class DataResult : ResultBase
|
|||||||
public async Task DownloadPhoto(int index, string path)
|
public async Task DownloadPhoto(int index, string path)
|
||||||
{
|
{
|
||||||
var photo = Photos[index];
|
var photo = Photos[index];
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
var file = await Device.Client.TelegramClient.GetFile(photo.FileId);
|
||||||
var fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFile(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -446,8 +446,8 @@ public class FormBase : IDisposable
|
|||||||
{
|
{
|
||||||
c.Cleanup().Wait();
|
c.Cleanup().Wait();
|
||||||
|
|
||||||
Controls.Remove(c);
|
|
||||||
}
|
}
|
||||||
|
Controls.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
@ -10,6 +11,7 @@ using Telegram.Bot.Exceptions;
|
|||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Base;
|
namespace TelegramBotBase.Base;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -17,16 +19,18 @@ namespace TelegramBotBase.Base;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MessageClient
|
public class MessageClient
|
||||||
{
|
{
|
||||||
|
private EventHandlerList Events { get; } = new();
|
||||||
|
|
||||||
private static readonly object EvOnMessageLoop = new();
|
private static readonly object EvOnMessageLoop = new();
|
||||||
private static readonly object EvOnReceiveError = new();
|
private static readonly object EvOnReceiveError = new();
|
||||||
|
|
||||||
private static object __evOnMessage = new();
|
protected CancellationTokenSource _cancellationTokenSource;
|
||||||
|
|
||||||
private static object __evOnMessageEdit = new();
|
public string ApiKey { get; }
|
||||||
|
|
||||||
|
public ITelegramBotClient TelegramClient { get; set; }
|
||||||
|
|
||||||
private static object __evCallbackQuery = new();
|
|
||||||
|
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before
|
/// Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before
|
||||||
@ -41,16 +45,12 @@ public class MessageClient
|
|||||||
{
|
{
|
||||||
ApiKey = apiKey;
|
ApiKey = apiKey;
|
||||||
TelegramClient = new TelegramBotClient(apiKey);
|
TelegramClient = new TelegramBotClient(apiKey);
|
||||||
|
|
||||||
Prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageClient(string apiKey, HttpClient proxy)
|
public MessageClient(string apiKey, HttpClient proxy)
|
||||||
{
|
{
|
||||||
ApiKey = apiKey;
|
ApiKey = apiKey;
|
||||||
TelegramClient = new TelegramBotClient(apiKey, proxy);
|
TelegramClient = new TelegramBotClient(apiKey, proxy);
|
||||||
|
|
||||||
Prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,8 +68,6 @@ public class MessageClient
|
|||||||
);
|
);
|
||||||
|
|
||||||
TelegramClient = new TelegramBotClient(apiKey, httpClient);
|
TelegramClient = new TelegramBotClient(apiKey, httpClient);
|
||||||
|
|
||||||
Prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -89,8 +87,6 @@ public class MessageClient
|
|||||||
);
|
);
|
||||||
|
|
||||||
TelegramClient = new TelegramBotClient(apiKey, httpClient);
|
TelegramClient = new TelegramBotClient(apiKey, httpClient);
|
||||||
|
|
||||||
Prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,53 +94,41 @@ public class MessageClient
|
|||||||
{
|
{
|
||||||
ApiKey = apiKey;
|
ApiKey = apiKey;
|
||||||
TelegramClient = client;
|
TelegramClient = client;
|
||||||
|
|
||||||
Prepare();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string ApiKey { get; }
|
public virtual void StartReceiving()
|
||||||
|
|
||||||
public ITelegramBotClient TelegramClient { get; set; }
|
|
||||||
|
|
||||||
private EventHandlerList Events { get; } = new();
|
|
||||||
|
|
||||||
|
|
||||||
public void Prepare()
|
|
||||||
{
|
|
||||||
TelegramClient.Timeout = new TimeSpan(0, 0, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void StartReceiving()
|
|
||||||
{
|
{
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
var receiverOptions = new ReceiverOptions();
|
var receiverOptions = new ReceiverOptions();
|
||||||
|
|
||||||
receiverOptions.ThrowPendingUpdates = ThrowPendingUpdates;
|
receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
|
||||||
|
|
||||||
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions,
|
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _cancellationTokenSource.Token);
|
||||||
_cancellationTokenSource.Token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopReceiving()
|
|
||||||
|
public virtual void StopReceiving()
|
||||||
{
|
{
|
||||||
_cancellationTokenSource.Cancel();
|
_cancellationTokenSource.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
private async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await OnMessageLoop(new UpdateResult(update, null));
|
await OnMessageLoop(new UpdateResult(update, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
|
||||||
|
private async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await OnReceiveError(new ErrorResult(exception));
|
await OnReceiveError(new ErrorResult(exception));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region "BotCommands"
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will return the current list of bot commands.
|
/// This will return the current list of bot commands.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -176,6 +160,8 @@ public class MessageClient
|
|||||||
await TelegramClient.DeleteMyCommandsAsync(scope, languageCode);
|
await TelegramClient.DeleteMyCommandsAsync(scope, languageCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region "Events"
|
#region "Events"
|
||||||
|
|
||||||
@ -185,6 +171,7 @@ public class MessageClient
|
|||||||
remove => Events.RemoveHandler(EvOnMessageLoop, value);
|
remove => Events.RemoveHandler(EvOnMessageLoop, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task OnMessageLoop(UpdateResult update)
|
public async Task OnMessageLoop(UpdateResult update)
|
||||||
{
|
{
|
||||||
var eventHandlers = (Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
var eventHandlers = (Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
||||||
@ -202,6 +189,7 @@ public class MessageClient
|
|||||||
remove => Events.RemoveHandler(EvOnReceiveError, value);
|
remove => Events.RemoveHandler(EvOnReceiveError, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task OnReceiveError(ErrorResult update)
|
public async Task OnReceiveError(ErrorResult update)
|
||||||
{
|
{
|
||||||
var eventHandlers = (Events[EvOnReceiveError] as Async.AsyncEventHandler<ErrorResult>)?.Invoke(this, update);
|
var eventHandlers = (Events[EvOnReceiveError] as Async.AsyncEventHandler<ErrorResult>)?.Invoke(this, update);
|
||||||
@ -225,4 +213,5 @@ public class MessageClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
@ -9,16 +10,36 @@ namespace TelegramBotBase.Base;
|
|||||||
|
|
||||||
public class MessageResult : ResultBase
|
public class MessageResult : ResultBase
|
||||||
{
|
{
|
||||||
internal MessageResult()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageResult(Update update)
|
public MessageResult(Update update)
|
||||||
{
|
{
|
||||||
UpdateData = update;
|
UpdateData = update;
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Update UpdateData { get; set; }
|
void init()
|
||||||
|
{
|
||||||
|
IsAction = UpdateData.CallbackQuery != null;
|
||||||
|
|
||||||
|
if (Message == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IsBotCommand = Message.Entities?.Any(a => a.Type == MessageEntityType.BotCommand) ?? false;
|
||||||
|
|
||||||
|
if (!IsBotCommand)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BotCommand = MessageText.Split(' ')[0];
|
||||||
|
|
||||||
|
IsBotGroupCommand = BotCommand.Contains("@");
|
||||||
|
|
||||||
|
if (IsBotGroupCommand)
|
||||||
|
{
|
||||||
|
BotCommand = BotCommand.Substring(0, BotCommand.LastIndexOf('@'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Update UpdateData { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Device/ChatId
|
/// Returns the Device/ChatId
|
||||||
@ -55,12 +76,17 @@ public class MessageResult : ResultBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this an action ? (i.e. button click)
|
/// Is this an action ? (i.e. button click)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsAction => UpdateData.CallbackQuery != null;
|
public bool IsAction { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this a command ? Starts with a slash '/' and a command
|
/// Is this a command ? Starts with a slash '/' and a command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsBotCommand => MessageText.StartsWith("/");
|
public bool IsBotCommand { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this a bot command sent from a group via @BotId ?
|
||||||
|
/// </summary>
|
||||||
|
public bool IsBotGroupCommand { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
||||||
@ -83,18 +109,7 @@ public class MessageResult : ResultBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
/// Returns just the command (i.e. /start 1 2 3 => /start)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BotCommand
|
public string BotCommand { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (!IsBotCommand)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MessageText.Split(' ')[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns if this message will be used on the first form or not.
|
/// Returns if this message will be used on the first form or not.
|
||||||
@ -111,7 +126,7 @@ public class MessageResult : ResultBase
|
|||||||
T cd = null;
|
T cd = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cd = JsonConvert.DeserializeObject<T>(RawData);
|
cd = JsonSerializer.Deserialize<T>(RawData);
|
||||||
|
|
||||||
return cd;
|
return cd;
|
||||||
}
|
}
|
||||||
|
|||||||
109
TelegramBotBase/Base/ThreadPoolMessageClient.cs
Normal file
109
TelegramBotBase/Base/ThreadPoolMessageClient.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
|
using Telegram.Bot.Polling;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Base;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for message handling
|
||||||
|
/// </summary>
|
||||||
|
public class ThreadPoolMessageClient : MessageClient
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <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 int ThreadPool_WorkerThreads { get; set; } = 1;
|
||||||
|
|
||||||
|
public int ThreadPool_IOThreads { get; set; } = 1;
|
||||||
|
|
||||||
|
|
||||||
|
public ThreadPoolMessageClient(string apiKey) : base(apiKey)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThreadPoolMessageClient(string apiKey, HttpClient proxy) : base(apiKey, proxy)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ThreadPoolMessageClient(string apiKey, Uri proxyUrl, NetworkCredential credential = null) : base(apiKey, proxyUrl, credential)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the client with a proxy
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKey"></param>
|
||||||
|
/// <param name="proxyHost">i.e. 127.0.0.1</param>
|
||||||
|
/// <param name="proxyPort">i.e. 10000</param>
|
||||||
|
public ThreadPoolMessageClient(string apiKey, string proxyHost, int proxyPort) : base(apiKey, proxyHost, proxyPort)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ThreadPoolMessageClient(string apiKey, TelegramBotClient client) : base(apiKey, client)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public override void StartReceiving()
|
||||||
|
{
|
||||||
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
var receiverOptions = new ReceiverOptions();
|
||||||
|
|
||||||
|
receiverOptions.DropPendingUpdates = ThrowPendingUpdates;
|
||||||
|
|
||||||
|
ThreadPool.SetMaxThreads(ThreadPool_WorkerThreads, ThreadPool_IOThreads);
|
||||||
|
|
||||||
|
TelegramClient.StartReceiving(HandleUpdateAsyncThreadPool, HandleErrorAsyncThreadPool, receiverOptions, _cancellationTokenSource.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void StopReceiving()
|
||||||
|
{
|
||||||
|
_cancellationTokenSource.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Task HandleUpdateAsyncThreadPool(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
ThreadPool.QueueUserWorkItem(async a =>
|
||||||
|
{
|
||||||
|
await OnMessageLoop(new UpdateResult(update, null));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task HandleErrorAsyncThreadPool(ITelegramBotClient botClient, Exception exception,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
ThreadPool.QueueUserWorkItem(async a =>
|
||||||
|
{
|
||||||
|
await OnReceiveError(new ErrorResult(exception));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ using Telegram.Bot.Types;
|
|||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Enums;
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Exceptions;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
using Console = TelegramBotBase.Tools.Console;
|
using Console = TelegramBotBase.Tools.Console;
|
||||||
@ -115,7 +116,7 @@ public sealed class BotBase
|
|||||||
if (ds == null)
|
if (ds == null)
|
||||||
{
|
{
|
||||||
ds = await Sessions.StartSession(e.DeviceId);
|
ds = await Sessions.StartSession(e.DeviceId);
|
||||||
ds.LastMessage = e.RawData.Message;
|
ds.LastMessage = e.Message;
|
||||||
|
|
||||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||||
}
|
}
|
||||||
@ -139,6 +140,13 @@ public sealed class BotBase
|
|||||||
mr.IsFirstHandler = false;
|
mr.IsFirstHandler = false;
|
||||||
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
||||||
}
|
}
|
||||||
|
catch (InvalidServiceProviderConfiguration ex)
|
||||||
|
{
|
||||||
|
var ds = Sessions.GetSession(e.DeviceId);
|
||||||
|
OnException(new SystemExceptionEventArgs(e.Message.Text, e.DeviceId, ds, ex));
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var ds = Sessions.GetSession(e.DeviceId);
|
var ds = Sessions.GetSession(e.DeviceId);
|
||||||
@ -189,13 +197,10 @@ public sealed class BotBase
|
|||||||
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
||||||
public async Task InvokeMessageLoop(long deviceId)
|
public async Task InvokeMessageLoop(long deviceId)
|
||||||
{
|
{
|
||||||
var mr = new MessageResult
|
var mr = new MessageResult(new Update
|
||||||
{
|
|
||||||
UpdateData = new Update
|
|
||||||
{
|
{
|
||||||
Message = new Message()
|
Message = new Message()
|
||||||
}
|
});
|
||||||
};
|
|
||||||
|
|
||||||
await InvokeMessageLoop(deviceId, mr);
|
await InvokeMessageLoop(deviceId, mr);
|
||||||
}
|
}
|
||||||
@ -260,7 +265,7 @@ public sealed class BotBase
|
|||||||
{
|
{
|
||||||
foreach (var scope in BotCommandScopes)
|
foreach (var scope in BotCommandScopes)
|
||||||
{
|
{
|
||||||
if (scope.Value.Any(a => "/" + a.Command == command))
|
if (scope.Value.Any(a => Constants.Telegram.BotCommandIndicator + a.Command == command))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace TelegramBotBase.Builder;
|
|||||||
|
|
||||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage,
|
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage,
|
||||||
IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage,
|
IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage,
|
||||||
ILanguageSelectionStage
|
ILanguageSelectionStage, IThreadingStage
|
||||||
{
|
{
|
||||||
private string _apiKey;
|
private string _apiKey;
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
private BotBaseBuilder()
|
private BotBaseBuilder()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -72,14 +73,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBuildingStage QuickStart(string apiKey, Type startForm)
|
public IBuildingStage QuickStart(string apiKey, Type startForm, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
_factory = new DefaultStartFormFactory(startForm);
|
_factory = new DefaultStartFormFactory(startForm);
|
||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy();
|
NoProxy(throwPendingUpdates);
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
@ -87,11 +88,13 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
DefaultLanguage();
|
DefaultLanguage();
|
||||||
|
|
||||||
|
UseSingleThread();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBuildingStage QuickStart<T>(string apiKey)
|
public IBuildingStage QuickStart<T>(string apiKey, bool throwPendingUpdates = false)
|
||||||
where T : FormBase
|
where T : FormBase
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
@ -99,7 +102,7 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy();
|
NoProxy(throwPendingUpdates);
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
@ -107,17 +110,19 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
DefaultLanguage();
|
DefaultLanguage();
|
||||||
|
|
||||||
|
UseSingleThread();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory)
|
public IBuildingStage QuickStart(string apiKey, IStartFormFactory startFormFactory, bool throwPendingUpdates = false)
|
||||||
{
|
{
|
||||||
_apiKey = apiKey;
|
_apiKey = apiKey;
|
||||||
_factory = startFormFactory;
|
_factory = startFormFactory;
|
||||||
|
|
||||||
DefaultMessageLoop();
|
DefaultMessageLoop();
|
||||||
|
|
||||||
NoProxy();
|
NoProxy(throwPendingUpdates);
|
||||||
|
|
||||||
OnlyStart();
|
OnlyStart();
|
||||||
|
|
||||||
@ -125,6 +130,8 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
DefaultLanguage();
|
DefaultLanguage();
|
||||||
|
|
||||||
|
UseSingleThread();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,14 +214,14 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
|
|
||||||
#region "Step 4 (Network Settings)"
|
#region "Step 4 (Network Settings)"
|
||||||
|
|
||||||
public IBotCommandsStage WithProxy(string proxyAddress, bool throwPendingUpdates = false)
|
public IBotCommandsStage WithProxy(string proxyAddress, bool throwPendingUpdates = false, int timeoutInSeconds = 60)
|
||||||
{
|
{
|
||||||
var url = new Uri(proxyAddress);
|
var url = new Uri(proxyAddress);
|
||||||
_client = new MessageClient(_apiKey, url)
|
_client = new MessageClient(_apiKey, url)
|
||||||
{
|
{
|
||||||
TelegramClient =
|
TelegramClient =
|
||||||
{
|
{
|
||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = TimeSpan.FromSeconds(timeoutInSeconds)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
_client.ThrowPendingUpdates = throwPendingUpdates;
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
@ -222,13 +229,13 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage NoProxy(bool throwPendingUpdates = false)
|
public IBotCommandsStage NoProxy(bool throwPendingUpdates = false, int timeoutInSeconds = 60)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey)
|
_client = new MessageClient(_apiKey)
|
||||||
{
|
{
|
||||||
TelegramClient =
|
TelegramClient =
|
||||||
{
|
{
|
||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = TimeSpan.FromSeconds(timeoutInSeconds)// new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_client.ThrowPendingUpdates = throwPendingUpdates;
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
@ -236,13 +243,13 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage WithBotClient(TelegramBotClient tgclient, bool throwPendingUpdates = false)
|
public IBotCommandsStage WithBotClient(TelegramBotClient tgclient, bool throwPendingUpdates = false, int timeoutInSeconds = 60)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, tgclient)
|
_client = new MessageClient(_apiKey, tgclient)
|
||||||
{
|
{
|
||||||
TelegramClient =
|
TelegramClient =
|
||||||
{
|
{
|
||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = TimeSpan.FromSeconds(timeoutInSeconds)// new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_client.ThrowPendingUpdates = throwPendingUpdates;
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
@ -250,26 +257,26 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort, bool throwPendingUpdates = false)
|
public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort, bool throwPendingUpdates = false, int timeoutInSeconds = 60)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, proxyHost, proxyPort)
|
_client = new MessageClient(_apiKey, proxyHost, proxyPort)
|
||||||
{
|
{
|
||||||
TelegramClient =
|
TelegramClient =
|
||||||
{
|
{
|
||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = TimeSpan.FromSeconds(timeoutInSeconds)// new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_client.ThrowPendingUpdates = throwPendingUpdates;
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBotCommandsStage WithHttpClient(HttpClient tgclient, bool throwPendingUpdates = false)
|
public IBotCommandsStage WithHttpClient(HttpClient tgclient, bool throwPendingUpdates = false, int timeoutInSeconds = 60)
|
||||||
{
|
{
|
||||||
_client = new MessageClient(_apiKey, tgclient)
|
_client = new MessageClient(_apiKey, tgclient)
|
||||||
{
|
{
|
||||||
TelegramClient =
|
TelegramClient =
|
||||||
{
|
{
|
||||||
Timeout = new TimeSpan(0, 1, 0)
|
Timeout = TimeSpan.FromSeconds(timeoutInSeconds)// new TimeSpan(0, 1, 0)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_client.ThrowPendingUpdates = throwPendingUpdates;
|
_client.ThrowPendingUpdates = throwPendingUpdates;
|
||||||
@ -392,45 +399,70 @@ public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage,
|
|||||||
#region "Step 7 (Language)"
|
#region "Step 7 (Language)"
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.DefaultLanguage"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.DefaultLanguage"/>
|
||||||
public IBuildingStage DefaultLanguage()
|
public IThreadingStage DefaultLanguage()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.UseEnglish"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.UseEnglish"/>
|
||||||
public IBuildingStage UseEnglish()
|
public IThreadingStage UseEnglish()
|
||||||
{
|
{
|
||||||
Default.Language = new English();
|
Default.Language = new English();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.UseGerman"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.UseGerman"/>
|
||||||
public IBuildingStage UseGerman()
|
public IThreadingStage UseGerman()
|
||||||
{
|
{
|
||||||
Default.Language = new German();
|
Default.Language = new German();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.UsePersian"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.UsePersian"/>
|
||||||
public IBuildingStage UsePersian()
|
public IThreadingStage UsePersian()
|
||||||
{
|
{
|
||||||
Default.Language = new Persian();
|
Default.Language = new Persian();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.UseRussian"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.UseRussian"/>
|
||||||
public IBuildingStage UseRussian()
|
public IThreadingStage UseRussian()
|
||||||
{
|
{
|
||||||
Default.Language = new Russian();
|
Default.Language = new Russian();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="ILanguageSelectionStage.Custom"/>
|
/// <inheritdoc cref="ILanguageSelectionStage.Custom"/>
|
||||||
public IBuildingStage Custom(Localization language)
|
public IThreadingStage Custom(Localization language)
|
||||||
{
|
{
|
||||||
Default.Language = language;
|
Default.Language = language;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region "Step 8 (Threading)"
|
||||||
|
|
||||||
|
public IBuildingStage UseSingleThread()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBuildingStage UseThreadPool(int workerThreads = 2, int ioThreads = 1)
|
||||||
|
{
|
||||||
|
var c = new ThreadPoolMessageClient(_apiKey, (TelegramBotClient)_client.TelegramClient);
|
||||||
|
|
||||||
|
c.ThreadPool_WorkerThreads = workerThreads;
|
||||||
|
c.ThreadPool_IOThreads = ioThreads;
|
||||||
|
c.ThrowPendingUpdates = _client.ThrowPendingUpdates;
|
||||||
|
|
||||||
|
_client = c;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,16 +20,18 @@ public interface IAPIKeySelectionStage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="StartForm"></param>
|
/// <param name="StartForm"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart(string apiKey, Type StartForm);
|
IBuildingStage QuickStart(string apiKey, Type StartForm, bool throwPendingUpdates = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quick and easy way to create a BotBase instance.
|
/// Quick and easy way to create a BotBase instance.
|
||||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart<T>(string apiKey) where T : FormBase;
|
IBuildingStage QuickStart<T>(string apiKey , bool throwPendingUpdates = false) where T : FormBase;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Quick and easy way to create a BotBase instance.
|
/// Quick and easy way to create a BotBase instance.
|
||||||
@ -37,6 +39,7 @@ public interface IAPIKeySelectionStage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="apiKey"></param>
|
/// <param name="apiKey"></param>
|
||||||
/// <param name="StartFormFactory"></param>
|
/// <param name="StartFormFactory"></param>
|
||||||
|
/// <param name="throwPendingUpdates">Indicates if all pending Telegram.Bot.Types.Updates should be thrown out before start polling.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory);
|
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory, bool throwPendingUpdates = false);
|
||||||
}
|
}
|
||||||
@ -11,35 +11,35 @@ public interface ILanguageSelectionStage
|
|||||||
/// Selects the default language for control usage. (English)
|
/// Selects the default language for control usage. (English)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage DefaultLanguage();
|
IThreadingStage DefaultLanguage();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects english as the default language for control labels.
|
/// Selects english as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UseEnglish();
|
IThreadingStage UseEnglish();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects german as the default language for control labels.
|
/// Selects german as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UseGerman();
|
IThreadingStage UseGerman();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects persian as the default language for control labels.
|
/// Selects persian as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UsePersian();
|
IThreadingStage UsePersian();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects russian as the default language for control labels.
|
/// Selects russian as the default language for control labels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage UseRussian();
|
IThreadingStage 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>The next stage in the building process.</returns>
|
/// <returns>The next stage in the building process.</returns>
|
||||||
IBuildingStage Custom(Localization language);
|
IThreadingStage Custom(Localization language);
|
||||||
}
|
}
|
||||||
@ -11,14 +11,14 @@ public interface INetworkingSelectionStage
|
|||||||
/// <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>
|
/// <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, bool throwPendingUpdates = false);
|
IBotCommandsStage WithProxy(string proxyAddress, bool throwPendingUpdates = false, int timeoutInSeconds = 60);
|
||||||
|
|
||||||
/// <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>
|
/// <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(bool throwPendingUpdates = false);
|
IBotCommandsStage NoProxy(bool throwPendingUpdates = false, int timeoutInSeconds = 60);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +27,7 @@ public interface INetworkingSelectionStage
|
|||||||
/// <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>
|
/// <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, bool throwPendingUpdates = false);
|
IBotCommandsStage WithBotClient(TelegramBotClient client, bool throwPendingUpdates = false, int timeoutInSeconds = 60);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -37,7 +37,7 @@ public interface INetworkingSelectionStage
|
|||||||
/// <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>
|
/// <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, bool throwPendingUpdates = false);
|
IBotCommandsStage WithHostAndPort(string proxyHost, int Port, bool throwPendingUpdates = false, int timeoutInSeconds = 60);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uses a custom http client.
|
/// Uses a custom http client.
|
||||||
@ -45,5 +45,5 @@ public interface INetworkingSelectionStage
|
|||||||
/// <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>
|
/// <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, bool throwPendingUpdates = false);
|
IBotCommandsStage WithHttpClient(HttpClient client, bool throwPendingUpdates = false, int timeoutInSeconds = 60);
|
||||||
}
|
}
|
||||||
24
TelegramBotBase/Builder/Interfaces/IThreadingStage.cs
Normal file
24
TelegramBotBase/Builder/Interfaces/IThreadingStage.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Builder.Interfaces
|
||||||
|
{
|
||||||
|
public interface IThreadingStage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Uses one single thread for message loop. (Default)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IBuildingStage UseSingleThread();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Using the threadpool for managing requests.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="workerThreads">Number of concurrent working threads.</param>
|
||||||
|
/// <param name="ioThreads">Number of concurrent I/O threads.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IBuildingStage UseThreadPool(int workerThreads = 2, int ioThreads = 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
@ -20,6 +21,16 @@ public static class Extensions
|
|||||||
scope = BotCommandScope.Default();
|
scope = BotCommandScope.Default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(command))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(command), $"{nameof(command)} parameter can not be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(command.StartsWith(Constants.Telegram.BotCommandIndicator))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"{nameof(command)} parameter does not have to start with a slash, please remove.", $"{nameof(command)}");
|
||||||
|
}
|
||||||
|
|
||||||
var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type);
|
var item = cmds.FirstOrDefault(a => a.Key.Type == scope.Type);
|
||||||
|
|
||||||
if (item.Value != null)
|
if (item.Value != null)
|
||||||
|
|||||||
@ -16,4 +16,15 @@ public static class Telegram
|
|||||||
public const int MaxReplyKeyboardCols = 12;
|
public const int MaxReplyKeyboardCols = 12;
|
||||||
|
|
||||||
public const int MessageDeletionsPerSecond = 30;
|
public const int MessageDeletionsPerSecond = 30;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum length of callback data. Will raise an exception of it exceeds it.
|
||||||
|
/// </summary>
|
||||||
|
public const int MaxCallBackDataBytes = 64;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The slash constant which indicates a bot command.
|
||||||
|
/// </summary>
|
||||||
|
public const string BotCommandIndicator = "/";
|
||||||
}
|
}
|
||||||
@ -51,7 +51,24 @@ public class ButtonGrid : ControlBase
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_Title;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Title = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string ConfirmationText { get; set; } = "";
|
public string ConfirmationText { get; set; } = "";
|
||||||
|
|
||||||
@ -426,8 +443,6 @@ public class ButtonGrid : ControlBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await result.ConfirmAction(ConfirmationText ?? "");
|
|
||||||
|
|
||||||
ButtonRow match = null;
|
ButtonRow match = null;
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
|
||||||
@ -462,6 +477,8 @@ public class ButtonGrid : ControlBase
|
|||||||
check:
|
check:
|
||||||
if (match != null)
|
if (match != null)
|
||||||
{
|
{
|
||||||
|
await result.ConfirmAction(ConfirmationText ?? "");
|
||||||
|
|
||||||
await OnButtonClicked(new ButtonClickedEventArgs(match.GetButtonMatch(result.RawData, false), index,
|
await OnButtonClicked(new ButtonClickedEventArgs(match.GetButtonMatch(result.RawData, false), index,
|
||||||
match));
|
match));
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ using TelegramBotBase.Enums;
|
|||||||
using TelegramBotBase.Exceptions;
|
using TelegramBotBase.Exceptions;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Localizations;
|
using TelegramBotBase.Localizations;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using static TelegramBotBase.Base.Async;
|
using static TelegramBotBase.Base.Async;
|
||||||
|
|
||||||
namespace TelegramBotBase.Controls.Hybrid;
|
namespace TelegramBotBase.Controls.Hybrid;
|
||||||
@ -51,7 +52,24 @@ public class CheckedButtonList : ControlBase
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_Title;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Title = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string ConfirmationText { get; set; } = "";
|
public string ConfirmationText { get; set; } = "";
|
||||||
|
|
||||||
|
|||||||
@ -29,8 +29,6 @@ public class TaggedButtonGrid : MultiView
|
|||||||
|
|
||||||
public string BackLabel = Default.Language["ButtonGrid_Back"];
|
public string BackLabel = Default.Language["ButtonGrid_Back"];
|
||||||
|
|
||||||
public string CheckAllLabel = Default.Language["ButtonGrid_CheckAll"];
|
|
||||||
|
|
||||||
public string NextPageLabel = Default.Language["ButtonGrid_NextPage"];
|
public string NextPageLabel = Default.Language["ButtonGrid_NextPage"];
|
||||||
|
|
||||||
public string NoItemsLabel = Default.Language["ButtonGrid_NoItems"];
|
public string NoItemsLabel = Default.Language["ButtonGrid_NoItems"];
|
||||||
@ -39,11 +37,17 @@ public class TaggedButtonGrid : MultiView
|
|||||||
|
|
||||||
public string SearchLabel = Default.Language["ButtonGrid_SearchFeature"];
|
public string SearchLabel = Default.Language["ButtonGrid_SearchFeature"];
|
||||||
|
|
||||||
public string UncheckAllLabel = Default.Language["ButtonGrid_UncheckAll"];
|
public string TotalTagsLabel = Default.Language["TaggedButtonGrid_TotalTags"];
|
||||||
|
|
||||||
|
public string CheckedTagsLabel = Default.Language["TaggedButtonGrid_CheckedTags"];
|
||||||
|
|
||||||
|
public string CheckAllLabel = Default.Language["TaggedButtonGrid_CheckAll"];
|
||||||
|
|
||||||
|
public string UncheckAllLabel = Default.Language["TaggedButtonGrid_UncheckAll"];
|
||||||
|
|
||||||
public string SearchIcon = Default.Language["ButtonGrid_SearchIcon"];
|
public string SearchIcon = Default.Language["ButtonGrid_SearchIcon"];
|
||||||
|
|
||||||
public string TagIcon = Default.Language["ButtonGrid_TagIcon"];
|
public string TagIcon = Default.Language["TaggedButtonGrid_TagIcon"];
|
||||||
|
|
||||||
public TaggedButtonGrid()
|
public TaggedButtonGrid()
|
||||||
{
|
{
|
||||||
@ -63,7 +67,24 @@ public class TaggedButtonGrid : MultiView
|
|||||||
DataSource = new ButtonFormDataSource(form);
|
DataSource = new ButtonFormDataSource(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get; set; } = Default.Language["ButtonGrid_Title"];
|
string m_Title = Default.Language["ButtonGrid_Title"];
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_Title;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Title = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string ConfirmationText { get; set; }
|
public string ConfirmationText { get; set; }
|
||||||
|
|
||||||
@ -379,14 +400,6 @@ public class TaggedButtonGrid : MultiView
|
|||||||
index = br.Item2;
|
index = br.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var button = HeadLayoutButtonRow?. .FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
|
||||||
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
|
||||||
|
|
||||||
// bf.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText)
|
|
||||||
|
|
||||||
//var index = bf.FindRowByButton(button);
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
|
||||||
|
|
||||||
@ -490,10 +503,16 @@ public class TaggedButtonGrid : MultiView
|
|||||||
if (result.MessageText == CheckAllLabel)
|
if (result.MessageText == CheckAllLabel)
|
||||||
{
|
{
|
||||||
CheckAllTags();
|
CheckAllTags();
|
||||||
|
Updated();
|
||||||
|
result.Handled = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (result.MessageText == UncheckAllLabel)
|
else if (result.MessageText == UncheckAllLabel)
|
||||||
{
|
{
|
||||||
UncheckAllTags();
|
UncheckAllTags();
|
||||||
|
Updated();
|
||||||
|
result.Handled = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = result.MessageText.LastIndexOf(" ");
|
var i = result.MessageText.LastIndexOf(" ");
|
||||||
@ -569,15 +588,6 @@ public class TaggedButtonGrid : MultiView
|
|||||||
index = br.Item2;
|
index = br.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//var bf = DataSource.ButtonForm;
|
|
||||||
|
|
||||||
//var button = HeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
|
||||||
// ?? SubHeadLayoutButtonRow?.FirstOrDefault(a => a.Value == result.RawData)
|
|
||||||
// ?? bf.ToList().FirstOrDefault(a => a.Value == result.RawData);
|
|
||||||
|
|
||||||
//var index = bf.FindRowByButton(button);
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
if (match != null)
|
if (match != null)
|
||||||
{
|
{
|
||||||
@ -619,23 +629,48 @@ public class TaggedButtonGrid : MultiView
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
if (SelectedViewIndex != 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
switch (result.RawData)
|
||||||
|
{
|
||||||
case "$back$":
|
case "$back$":
|
||||||
|
|
||||||
SelectedViewIndex = 0;
|
SelectedViewIndex = 0;
|
||||||
Updated();
|
Updated();
|
||||||
|
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "$checkall$":
|
case "$checkall$":
|
||||||
|
|
||||||
CheckAllTags();
|
CheckAllTags();
|
||||||
|
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "$uncheckall$":
|
case "$uncheckall$":
|
||||||
|
|
||||||
UncheckAllTags();
|
UncheckAllTags();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SelectedTags.Contains(result.RawData))
|
||||||
|
{
|
||||||
|
SelectedTags.Remove(result.RawData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedTags.Add(result.RawData);
|
||||||
|
}
|
||||||
|
|
||||||
|
Updated();
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -723,8 +758,10 @@ public class TaggedButtonGrid : MultiView
|
|||||||
|
|
||||||
if (EnableCheckAllTools)
|
if (EnableCheckAllTools)
|
||||||
{
|
{
|
||||||
TagsSubHeadLayoutButtonRow = new ButtonRow(new ButtonBase(CheckAllLabel, "$checkall$"),
|
TagsSubHeadLayoutButtonRow = new ButtonRow(new ButtonBase(string.Format(TotalTagsLabel, Tags.Count), "$total$"),
|
||||||
new ButtonBase(UncheckAllLabel, "$uncheckall$"));
|
new ButtonBase(CheckAllLabel, "$checkall$"),
|
||||||
|
new ButtonBase(UncheckAllLabel, "$uncheckall$"),
|
||||||
|
new ButtonBase(string.Format(CheckedTagsLabel, SelectedTags.Count), "checked$"));
|
||||||
bf.AddButtonRow(TagsSubHeadLayoutButtonRow);
|
bf.AddButtonRow(TagsSubHeadLayoutButtonRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -756,10 +793,6 @@ public class TaggedButtonGrid : MultiView
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (bf.Count == 0)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
|
|
||||||
var rkm = (ReplyKeyboardMarkup)bf;
|
var rkm = (ReplyKeyboardMarkup)bf;
|
||||||
rkm.ResizeKeyboard = ResizeKeyboard;
|
rkm.ResizeKeyboard = ResizeKeyboard;
|
||||||
rkm.OneTimeKeyboard = OneTimeKeyboard;
|
rkm.OneTimeKeyboard = OneTimeKeyboard;
|
||||||
@ -881,21 +914,20 @@ public class TaggedButtonGrid : MultiView
|
|||||||
{
|
{
|
||||||
Message m = null;
|
Message m = null;
|
||||||
|
|
||||||
var form = DataSource.PickItems(CurrentPageIndex * ItemRowsPerPage, ItemRowsPerPage,
|
ButtonForm form = null;
|
||||||
EnableSearch ? SearchQuery : null);
|
|
||||||
|
|
||||||
//if (this.EnableSearch && this.SearchQuery != null && this.SearchQuery != "")
|
|
||||||
//{
|
|
||||||
// form = form.FilterDuplicate(this.SearchQuery, true);
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// form = form.Duplicate();
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (Tags != null && SelectedTags != null)
|
if (Tags != null && SelectedTags != null)
|
||||||
{
|
{
|
||||||
|
form = DataSource.PickAllItems(EnableSearch ? SearchQuery : null); //CurrentPageIndex * ItemRowsPerPage, ItemRowsPerPage,
|
||||||
|
|
||||||
form = form.TagDuplicate(SelectedTags);
|
form = form.TagDuplicate(SelectedTags);
|
||||||
|
|
||||||
|
form = new ButtonForm(form.ToRowList().Skip(CurrentPageIndex * ItemRowsPerPage).Take(ItemRowsPerPage));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
form = DataSource.PickItems(CurrentPageIndex * ItemRowsPerPage, ItemRowsPerPage,
|
||||||
|
EnableSearch ? SearchQuery : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EnablePaging)
|
if (EnablePaging)
|
||||||
|
|||||||
@ -14,9 +14,9 @@ namespace TelegramBotBase.Controls.Inline;
|
|||||||
[DebuggerDisplay("{Text}")]
|
[DebuggerDisplay("{Text}")]
|
||||||
public class Label : ControlBase
|
public class Label : ControlBase
|
||||||
{
|
{
|
||||||
private bool _renderNecessary = true;
|
protected bool _renderNecessary = true;
|
||||||
|
|
||||||
private string _text = string.Empty;
|
private string _text = Default.Language["Label_Text"];
|
||||||
|
|
||||||
public String Text
|
public String Text
|
||||||
{
|
{
|
||||||
@ -29,6 +29,10 @@ public class Label : ControlBase
|
|||||||
if (_text == value)
|
if (_text == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Text)}", $"{nameof(Text)} property must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
_text = value;
|
_text = value;
|
||||||
_renderNecessary = true;
|
_renderNecessary = true;
|
||||||
@ -36,6 +40,8 @@ public class Label : ControlBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ParseMode _parseMode = ParseMode.Markdown;
|
private ParseMode _parseMode = ParseMode.Markdown;
|
||||||
|
|
||||||
public ParseMode ParseMode
|
public ParseMode ParseMode
|
||||||
|
|||||||
@ -32,10 +32,32 @@ public class MultiToggleButton : ControlBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
|
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
|
||||||
|
|
||||||
|
private string _title = Default.Language["MultiToggleButton_Title"];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This holds the title of the control.
|
/// This holds the title of the control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Title { get; set; } = Default.Language["MultiToggleButton_Title"];
|
public String Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _title;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_title == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
_title = value;
|
||||||
|
_renderNecessary = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
public int? MessageId { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,31 @@ public class ToggleButton : ControlBase
|
|||||||
|
|
||||||
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
|
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
|
||||||
|
|
||||||
public string Title { get; set; } = Default.Language["ToggleButton_Title"];
|
private string _title = Default.Language["ToggleButton_Title"];
|
||||||
|
|
||||||
|
public String Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _title;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_title == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
_title = value;
|
||||||
|
_renderNecessary = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
public int? MessageId { get; set; }
|
||||||
|
|
||||||
|
|||||||
35
TelegramBotBase/Exceptions/CallbackDataTooLongException.cs
Normal file
35
TelegramBotBase/Exceptions/CallbackDataTooLongException.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Exceptions;
|
||||||
|
|
||||||
|
public sealed class CallbackDataTooLongException : Exception
|
||||||
|
{
|
||||||
|
static ApiRequestException _innerException = new Telegram.Bot.Exceptions.ApiRequestException("Bad Request: BUTTON_DATA_INVALID", 400);
|
||||||
|
|
||||||
|
static String _message = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
||||||
|
|
||||||
|
static String _message_with_bytes = $"You have exceeded the maximum {Constants.Telegram.MaxCallBackDataBytes} bytes of callback data with @current_callback_bytes@ bytes.\r\nThis is a pre-sending message from the TelegramBotBase framework.\r\nread more: https://core.telegram.org/bots/api#inlinekeyboardbutton";
|
||||||
|
|
||||||
|
public CallbackDataTooLongException() : base(_message, _innerException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="current_callback_bytes">The amount of callback bytes generated.</param>
|
||||||
|
public CallbackDataTooLongException(int current_callback_bytes) : base(getMessage(current_callback_bytes), _innerException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getMessage(int current_callback_bytes = -1)
|
||||||
|
{
|
||||||
|
if (current_callback_bytes == -1)
|
||||||
|
return _message;
|
||||||
|
|
||||||
|
return _message_with_bytes.Replace("@current_callback_bytes@", current_callback_bytes.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Exceptions
|
||||||
|
{
|
||||||
|
public sealed class InvalidServiceProviderConfiguration : Exception
|
||||||
|
{
|
||||||
|
public InvalidServiceProviderConfiguration(string message, Exception innerException) : base(message, innerException) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using TelegramBotBase.DependencyInjection;
|
using TelegramBotBase.DependencyInjection;
|
||||||
|
using TelegramBotBase.Exceptions;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
@ -22,9 +23,20 @@ public class ServiceProviderStartFormFactory : IStartFormFactory
|
|||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormBase CreateForm()
|
public FormBase CreateForm() => CreateForm(null);
|
||||||
|
|
||||||
|
public FormBase CreateForm(Type? specifiedStartFrom = null)
|
||||||
{
|
{
|
||||||
var fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, _startFormClass);
|
FormBase fb = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fb = (FormBase)ActivatorUtilities.CreateInstance(_serviceProvider, specifiedStartFrom ?? _startFormClass);
|
||||||
|
}
|
||||||
|
catch(InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
throw new InvalidServiceProviderConfiguration(ex.Message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
//Sets an internal field for future ServiceProvider navigation
|
//Sets an internal field for future ServiceProvider navigation
|
||||||
fb.SetServiceProvider(_serviceProvider);
|
fb.SetServiceProvider(_serviceProvider);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class AutoCleanForm : FormBase
|
|||||||
DeleteMode = EDeleteMode.OnEveryCall;
|
DeleteMode = EDeleteMode.OnEveryCall;
|
||||||
DeleteSide = EDeleteSide.BotOnly;
|
DeleteSide = EDeleteSide.BotOnly;
|
||||||
|
|
||||||
Init += AutoCleanForm_Init;
|
Opened += AutoCleanForm_Init;
|
||||||
|
|
||||||
Closed += AutoCleanForm_Closed;
|
Closed += AutoCleanForm_Closed;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ public class AutoCleanForm : FormBase
|
|||||||
|
|
||||||
[SaveState] public EDeleteSide DeleteSide { get; set; }
|
[SaveState] public EDeleteSide DeleteSide { get; set; }
|
||||||
|
|
||||||
private Task AutoCleanForm_Init(object sender, InitEventArgs e)
|
private Task AutoCleanForm_Init(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (Device == null)
|
if (Device == null)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,8 @@ public class AutoCleanForm : FormBase
|
|||||||
|
|
||||||
private Task Device_MessageSent(object sender, MessageSentEventArgs e)
|
private Task Device_MessageSent(object sender, MessageSentEventArgs e)
|
||||||
{
|
{
|
||||||
if (DeleteSide == EDeleteSide.UserOnly)
|
if (DeleteSide == EDeleteSide.UserOnly
|
||||||
|
|| Device.ActiveForm != this)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
@ -137,6 +138,12 @@ public class AutoCleanForm : FormBase
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Device.MessageSent -= Device_MessageSent;
|
||||||
|
|
||||||
|
Device.MessageReceived -= Device_MessageReceived;
|
||||||
|
|
||||||
|
Device.MessageDeleted -= Device_MessageDeleted;
|
||||||
|
|
||||||
MessageCleanup().Wait();
|
MessageCleanup().Wait();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,11 @@ public class ButtonForm
|
|||||||
DependencyControl = control;
|
DependencyControl = control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ButtonForm(IEnumerable<ButtonRow> rows)
|
||||||
|
{
|
||||||
|
_buttons = rows.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public IReplyMarkup Markup { get; set; }
|
public IReplyMarkup Markup { get; set; }
|
||||||
|
|
||||||
@ -149,6 +154,11 @@ public class ButtonForm
|
|||||||
.Aggregate((a, b) => a.Union(b).ToList());
|
.Aggregate((a, b) => a.Union(b).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ButtonRow> ToRowList()
|
||||||
|
{
|
||||||
|
return _buttons;
|
||||||
|
}
|
||||||
|
|
||||||
public InlineKeyboardButton[][] ToInlineButtonArray()
|
public InlineKeyboardButton[][] ToInlineButtonArray()
|
||||||
{
|
{
|
||||||
var ikb = _buttons.Select(a => a.ToArray().Select(b => b.ToInlineButton(this)).ToArray()).ToArray();
|
var ikb = _buttons.Select(a => a.ToArray().Select(b => b.ToInlineButton(this)).ToArray()).ToArray();
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using TelegramBotBase.Exceptions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Form;
|
namespace TelegramBotBase.Form;
|
||||||
|
|
||||||
@ -17,28 +20,30 @@ public class CallbackData
|
|||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("m")] public string Method { get; set; }
|
[JsonPropertyName("m")] public string Method { get; set; }
|
||||||
|
|
||||||
[JsonProperty("v")] public string Value { get; set; }
|
[JsonPropertyName("v")] public string Value { get; set; }
|
||||||
|
|
||||||
public static string Create(string method, string value)
|
public static string Create(string method, string value)
|
||||||
{
|
{
|
||||||
return new CallbackData(method, value).Serialize();
|
return new CallbackData(method, value).Serialize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes data to json string
|
/// Serializes data to json string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string Serialize()
|
public string Serialize(bool throwExceptionOnOverflow = false)
|
||||||
{
|
{
|
||||||
var s = "";
|
var s = string.Empty;
|
||||||
try
|
|
||||||
{
|
s = JsonSerializer.Serialize(this);
|
||||||
s = JsonConvert.SerializeObject(this);
|
|
||||||
}
|
//Is data over 64 bytes ?
|
||||||
catch
|
int byte_count = Encoding.UTF8.GetByteCount(s);
|
||||||
|
if (throwExceptionOnOverflow && byte_count > Constants.Telegram.MaxCallBackDataBytes)
|
||||||
{
|
{
|
||||||
|
throw new CallbackDataTooLongException(byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -51,19 +56,8 @@ public class CallbackData
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CallbackData Deserialize(string data)
|
public static CallbackData Deserialize(string data)
|
||||||
{
|
{
|
||||||
CallbackData cd = null;
|
return JsonSerializer.Deserialize<CallbackData>(data);
|
||||||
try
|
|
||||||
{
|
|
||||||
cd = JsonConvert.DeserializeObject<CallbackData>(data);
|
|
||||||
|
|
||||||
return cd;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize(true);
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator string(CallbackData callbackData) => callbackData.Serialize();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,28 +11,28 @@ public class GroupForm : FormBase
|
|||||||
{
|
{
|
||||||
switch (message.MessageType)
|
switch (message.MessageType)
|
||||||
{
|
{
|
||||||
case MessageType.ChatMembersAdded:
|
case MessageType.NewChatMembers:
|
||||||
|
|
||||||
await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMembersAdded, message,
|
await OnMemberChanges(new MemberChangeEventArgs(MessageType.NewChatMembers, message,
|
||||||
message.Message.NewChatMembers));
|
message.Message.NewChatMembers));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MessageType.ChatMemberLeft:
|
case MessageType.LeftChatMember:
|
||||||
|
|
||||||
await OnMemberChanges(new MemberChangeEventArgs(MessageType.ChatMemberLeft, message,
|
await OnMemberChanges(new MemberChangeEventArgs(MessageType.LeftChatMember, message,
|
||||||
message.Message.LeftChatMember));
|
message.Message.LeftChatMember));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MessageType.ChatPhotoChanged:
|
case MessageType.NewChatPhoto:
|
||||||
case MessageType.ChatPhotoDeleted:
|
case MessageType.DeleteChatPhoto:
|
||||||
case MessageType.ChatTitleChanged:
|
case MessageType.NewChatTitle:
|
||||||
case MessageType.MigratedFromGroup:
|
case MessageType.MigrateFromChatId:
|
||||||
case MessageType.MigratedToSupergroup:
|
case MessageType.MigrateToChatId:
|
||||||
case MessageType.MessagePinned:
|
case MessageType.PinnedMessage:
|
||||||
case MessageType.GroupCreated:
|
case MessageType.GroupChatCreated:
|
||||||
case MessageType.SupergroupCreated:
|
case MessageType.SupergroupChatCreated:
|
||||||
case MessageType.ChannelCreated:
|
case MessageType.ChannelChatCreated:
|
||||||
|
|
||||||
await OnGroupChanged(new GroupChangedEventArgs(message.MessageType, message));
|
await OnGroupChanged(new GroupChangedEventArgs(message.MessageType, message));
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public class PromptDialog : ModalDialog
|
|||||||
{
|
{
|
||||||
var bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
|
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
|
||||||
await Device.Send(Message, (ReplyMarkupBase)bf);
|
await Device.Send(Message, (IReplyMarkup)bf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,8 +12,10 @@ public sealed class English : Localization
|
|||||||
Values["ButtonGrid_CurrentPage"] = "Page {0} of {1}";
|
Values["ButtonGrid_CurrentPage"] = "Page {0} of {1}";
|
||||||
Values["ButtonGrid_SearchFeature"] = "💡 Send a message to filter the list. Click the 🔍 to reset the filter.";
|
Values["ButtonGrid_SearchFeature"] = "💡 Send a message to filter the list. Click the 🔍 to reset the filter.";
|
||||||
Values["ButtonGrid_Back"] = "Back";
|
Values["ButtonGrid_Back"] = "Back";
|
||||||
Values["ButtonGrid_CheckAll"] = "Check all";
|
Values["TaggedButtonGrid_TotalTags"] = "Total: {0}";
|
||||||
Values["ButtonGrid_UncheckAll"] = "Uncheck all";
|
Values["TaggedButtonGrid_CheckedTags"] = "Checked: {0}";
|
||||||
|
Values["TaggedButtonGrid_CheckAll"] = "Check all";
|
||||||
|
Values["TaggedButtonGrid_UncheckAll"] = "Uncheck all";
|
||||||
Values["CalendarPicker_Title"] = "Pick date";
|
Values["CalendarPicker_Title"] = "Pick date";
|
||||||
Values["CalendarPicker_PreviousPage"] = "◀️";
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
Values["CalendarPicker_NextPage"] = "▶️";
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
@ -31,6 +33,7 @@ public sealed class English : Localization
|
|||||||
Values["PromptDialog_Back"] = "Back";
|
Values["PromptDialog_Back"] = "Back";
|
||||||
Values["ToggleButton_Changed"] = "Setting changed";
|
Values["ToggleButton_Changed"] = "Setting changed";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["ButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
|
Values["Label_Text"] = "Default label text";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,12 @@ public sealed class German : Localization
|
|||||||
Values["ButtonGrid_PreviousPage"] = "◀️";
|
Values["ButtonGrid_PreviousPage"] = "◀️";
|
||||||
Values["ButtonGrid_NextPage"] = "▶️";
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
Values["ButtonGrid_CurrentPage"] = "Seite {0} von {1}";
|
Values["ButtonGrid_CurrentPage"] = "Seite {0} von {1}";
|
||||||
Values["ButtonGrid_SearchFeature"] =
|
Values["ButtonGrid_SearchFeature"] = "💡 Sende eine Nachricht um die Liste zu filtern. Klicke die 🔍 um den Filter zurückzusetzen.";
|
||||||
"💡 Sende eine Nachricht um die Liste zu filtern. Klicke die 🔍 um den Filter zurückzusetzen.";
|
|
||||||
Values["ButtonGrid_Back"] = "Zurück";
|
Values["ButtonGrid_Back"] = "Zurück";
|
||||||
Values["ButtonGrid_CheckAll"] = "Alle auswählen";
|
Values["TaggedButtonGrid_TotalTags"] = "Gesamt: {0}";
|
||||||
Values["ButtonGrid_UncheckAll"] = "Keine auswählen";
|
Values["TaggedButtonGrid_CheckedTags"] = "Ausgewählt: {0}";
|
||||||
|
Values["TaggedButtonGrid_CheckAll"] = "Alle auswählen";
|
||||||
|
Values["TaggedButtonGrid_UncheckAll"] = "Keine auswählen";
|
||||||
Values["CalendarPicker_Title"] = "Datum auswählen";
|
Values["CalendarPicker_Title"] = "Datum auswählen";
|
||||||
Values["CalendarPicker_PreviousPage"] = "◀️";
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
Values["CalendarPicker_NextPage"] = "▶️";
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
@ -31,5 +32,8 @@ public sealed class German : Localization
|
|||||||
Values["MultiToggleButton_Changed"] = "Ausgewählt";
|
Values["MultiToggleButton_Changed"] = "Ausgewählt";
|
||||||
Values["PromptDialog_Back"] = "Zurück";
|
Values["PromptDialog_Back"] = "Zurück";
|
||||||
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
Values["ToggleButton_Changed"] = "Einstellung geändert";
|
||||||
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
|
Values["Label_Text"] = "Standard Label Text";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
namespace TelegramBotBase.Localizations
|
namespace TelegramBotBase.Localizations;
|
||||||
{
|
|
||||||
public sealed class Persian : Localization
|
public sealed class Persian : Localization
|
||||||
{
|
{
|
||||||
public Persian()
|
public Persian()
|
||||||
@ -12,8 +12,10 @@
|
|||||||
Values["ButtonGrid_CurrentPage"] = "صفحه ی {0} از {1}";
|
Values["ButtonGrid_CurrentPage"] = "صفحه ی {0} از {1}";
|
||||||
Values["ButtonGrid_SearchFeature"] = "💡 برای فیلتر کردن لیست پیام ارسال کنید. برای بازنشانی فیلتر روی 🔍 کلیک کنید.";
|
Values["ButtonGrid_SearchFeature"] = "💡 برای فیلتر کردن لیست پیام ارسال کنید. برای بازنشانی فیلتر روی 🔍 کلیک کنید.";
|
||||||
Values["ButtonGrid_Back"] = "بازگشت";
|
Values["ButtonGrid_Back"] = "بازگشت";
|
||||||
Values["ButtonGrid_CheckAll"] = "بررسی کردن همه";
|
Values["TaggedButtonGrid_TotalTags"] = "Total: {0}";
|
||||||
Values["ButtonGrid_UncheckAll"] = "بررسی نکردن همه";
|
Values["TaggedButtonGrid_CheckedTags"] = "Checked: {0}";
|
||||||
|
Values["TaggedButtonGrid_CheckAll"] = "بررسی کردن همه";
|
||||||
|
Values["TaggedButtonGrid_UncheckAll"] = "بررسی نکردن همه";
|
||||||
Values["CalendarPicker_Title"] = "تاریخ را انتخاب کنید";
|
Values["CalendarPicker_Title"] = "تاریخ را انتخاب کنید";
|
||||||
Values["CalendarPicker_PreviousPage"] = "◀️";
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
Values["CalendarPicker_NextPage"] = "▶️";
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
@ -31,7 +33,8 @@
|
|||||||
Values["PromptDialog_Back"] = "بازگشت";
|
Values["PromptDialog_Back"] = "بازگشت";
|
||||||
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
Values["ToggleButton_Changed"] = "تنظیمات تغییر کرد";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["ButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
}
|
Values["Label_Text"] = "متن برچسب پیشفرض";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,9 +11,11 @@ public sealed class Russian : Localization
|
|||||||
Values["ButtonGrid_NextPage"] = "▶️";
|
Values["ButtonGrid_NextPage"] = "▶️";
|
||||||
Values["ButtonGrid_CurrentPage"] = "Страница {0} из {1}";
|
Values["ButtonGrid_CurrentPage"] = "Страница {0} из {1}";
|
||||||
Values["ButtonGrid_SearchFeature"] = "💡 Отправьте сообщение, чтобы отфильтровать список. Нажмите на 🔍, чтобы сбросить фильтр.";
|
Values["ButtonGrid_SearchFeature"] = "💡 Отправьте сообщение, чтобы отфильтровать список. Нажмите на 🔍, чтобы сбросить фильтр.";
|
||||||
Values["ButtonGrid_Back"] = "Назада";
|
Values["ButtonGrid_Back"] = "Назад";
|
||||||
Values["ButtonGrid_CheckAll"] = "Выделить все";
|
Values["TaggedButtonGrid_TotalTags"] = "Всего: {0}";
|
||||||
Values["ButtonGrid_UncheckAll"] = "Отменить выбор";
|
Values["TaggedButtonGrid_CheckedTags"] = "Отмечено: {0}";
|
||||||
|
Values["TaggedButtonGrid_CheckAll"] = "Выделить все";
|
||||||
|
Values["TaggedButtonGrid_UncheckAll"] = "Отменить выбор";
|
||||||
Values["CalendarPicker_Title"] = "Календарь / Выберите дату";
|
Values["CalendarPicker_Title"] = "Календарь / Выберите дату";
|
||||||
Values["CalendarPicker_PreviousPage"] = "◀️";
|
Values["CalendarPicker_PreviousPage"] = "◀️";
|
||||||
Values["CalendarPicker_NextPage"] = "▶️";
|
Values["CalendarPicker_NextPage"] = "▶️";
|
||||||
@ -31,6 +33,7 @@ public sealed class Russian : Localization
|
|||||||
Values["PromptDialog_Back"] = "Назад";
|
Values["PromptDialog_Back"] = "Назад";
|
||||||
Values["ToggleButton_Changed"] = "Настройки изменены";
|
Values["ToggleButton_Changed"] = "Настройки изменены";
|
||||||
Values["ButtonGrid_SearchIcon"] = "🔍";
|
Values["ButtonGrid_SearchIcon"] = "🔍";
|
||||||
Values["ButtonGrid_TagIcon"] = "📁";
|
Values["TaggedButtonGrid_TagIcon"] = "📁";
|
||||||
|
Values["Label_Text"] = "Текст метки по умолчанию";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,6 +46,8 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
|||||||
mr.Device = session;
|
mr.Device = session;
|
||||||
ur.Device = session;
|
ur.Device = session;
|
||||||
|
|
||||||
|
session.OnMessageReceived(new(mr.Message));
|
||||||
|
|
||||||
var activeForm = session.ActiveForm;
|
var activeForm = session.ActiveForm;
|
||||||
|
|
||||||
//Pre Loading Event
|
//Pre Loading Event
|
||||||
@ -79,13 +81,16 @@ public class FormBaseMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction)
|
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
||||||
{
|
{
|
||||||
//Send Action event to controls
|
//Send Action event to controls
|
||||||
await activeForm.ActionControls(mr);
|
await activeForm.ActionControls(mr);
|
||||||
|
|
||||||
//Send Action event to form itself
|
if (!mr.Handled)
|
||||||
|
{
|
||||||
|
//Send Action event to form itself, if not already handled by a control
|
||||||
await activeForm.Action(mr);
|
await activeForm.Action(mr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!mr.Handled)
|
if (!mr.Handled)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -72,13 +72,16 @@ public class FullMessageLoop : IMessageLoopFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Action Event
|
//Action Event
|
||||||
if (!session.FormSwitched && mr.IsAction)
|
if (!session.FormSwitched && mr.IsAction && !mr.Handled)
|
||||||
{
|
{
|
||||||
//Send Action event to controls
|
//Send Action event to controls
|
||||||
await activeForm.ActionControls(mr);
|
await activeForm.ActionControls(mr);
|
||||||
|
|
||||||
//Send Action event to form itself
|
if (!mr.Handled)
|
||||||
|
{
|
||||||
|
//Send Action event to form itself, if not already handled by a control
|
||||||
await activeForm.Action(mr);
|
await activeForm.Action(mr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!mr.Handled)
|
if (!mr.Handled)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Attributes;
|
using TelegramBotBase.Attributes;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Factories;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Interfaces;
|
using TelegramBotBase.Interfaces;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
@ -145,9 +146,17 @@ public class SessionManager
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
FormBase form;
|
||||||
|
if (BotBase.StartFormFactory is ServiceProviderStartFormFactory diFactory)
|
||||||
|
{
|
||||||
|
form = diFactory.CreateForm(t);
|
||||||
|
}
|
||||||
//No default constructor, fallback
|
//No default constructor, fallback
|
||||||
if (!(t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) is FormBase form))
|
else if (t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) is FormBase f)
|
||||||
|
{
|
||||||
|
form = f;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
{
|
{
|
||||||
@ -293,7 +302,8 @@ public class SessionManager
|
|||||||
|
|
||||||
se.Values = ssea.Values;
|
se.Values = ssea.Values;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//Search for public properties with SaveState attribute
|
//Search for public properties with SaveState attribute
|
||||||
var fields = form.GetType()
|
var fields = form.GetType()
|
||||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
|
||||||
@ -305,6 +315,7 @@ public class SessionManager
|
|||||||
|
|
||||||
se.Values.Add("$" + f.Name, val);
|
se.Values.Add("$" + f.Name, val);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
states.Add(se);
|
states.Add(se);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,13 +131,9 @@ public class DeviceSession : IDeviceSession
|
|||||||
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
|
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
|
||||||
string urlToOpen = null)
|
string urlToOpen = null)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
|
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -157,17 +153,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(text.Length);
|
throw new MessageTooLongException(text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await Api(a =>
|
|
||||||
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -185,17 +172,9 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(text.Length);
|
throw new MessageTooLongException(text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await Api(a =>
|
|
||||||
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -215,19 +194,9 @@ public class DeviceSession : IDeviceSession
|
|||||||
throw new MessageTooLongException(message.Text.Length);
|
throw new MessageTooLongException(message.Text.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
return await Api(a => a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
||||||
{
|
|
||||||
return await Api(a =>
|
|
||||||
a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
|
||||||
replyMarkup: markup));
|
replyMarkup: markup));
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Edits the reply keyboard markup (buttons)
|
/// Edits the reply keyboard markup (buttons)
|
||||||
@ -237,15 +206,8 @@ public class DeviceSession : IDeviceSession
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
|
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -277,9 +239,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
var t = Api(a => a.SendMessage(deviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
||||||
{
|
|
||||||
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
@ -287,11 +247,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -336,20 +292,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
||||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -360,7 +311,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Message> Send(string text, ReplyMarkupBase markup, int replyTo = 0,
|
public async Task<Message> Send(string text, IReplyMarkup markup, int replyTo = 0,
|
||||||
bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown,
|
bool disableNotification = false, ParseMode parseMode = ParseMode.Markdown,
|
||||||
bool markdownV2AutoEscape = true)
|
bool markdownV2AutoEscape = true)
|
||||||
{
|
{
|
||||||
@ -379,20 +330,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendMessage(DeviceId, text, messageThreadId: null, parseMode: parseMode, replyParameters: replyTo,
|
||||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -414,20 +360,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendPhoto(DeviceId, file, messageThreadId: null, caption: caption, parseMode: parseMode, replyParameters: replyTo,
|
||||||
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -449,21 +390,16 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendVideo(DeviceId, file, caption: caption, parseMode: parseMode,
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
replyParameters: replyTo, replyMarkup: markup,
|
||||||
replyToMessageId: replyTo, replyMarkup: markup,
|
|
||||||
disableNotification: disableNotification));
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -484,21 +420,16 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendVideo(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
replyParameters: replyTo, replyMarkup: markup,
|
||||||
replyToMessageId: replyTo, replyMarkup: markup,
|
|
||||||
disableNotification: disableNotification));
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -520,24 +451,19 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var ms = new MemoryStream(video);
|
var ms = new MemoryStream(video);
|
||||||
|
|
||||||
var fts = InputFile.FromStream(ms, filename);
|
var fts = InputFile.FromStream(ms, filename);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -560,26 +486,21 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var fs = new FileStream(filepath, FileMode.Open);
|
var fs = new FileStream(filepath, FileMode.Open);
|
||||||
|
|
||||||
var filename = Path.GetFileName(filepath);
|
var filename = Path.GetFileName(filepath);
|
||||||
|
|
||||||
var fts = InputFile.FromStream(fs, filename);
|
var fts = InputFile.FromStream(fs, filename);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
var t = Api(a => a.SendVideo(DeviceId, fts, parseMode: parseMode, replyParameters: replyTo,
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -650,20 +571,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
markup = buttons;
|
markup = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
var t = Api(a => a.SendDocument(DeviceId, document, messageThreadId: null, thumbnail: null, caption: caption, replyMarkup: markup,
|
||||||
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
|
disableNotification: disableNotification, replyParameters: replyTo));
|
||||||
disableNotification: disableNotification, replyToMessageId: replyTo));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var o = GetOrigin(new StackTrace());
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
return await t;
|
return await t;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -714,8 +630,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
|
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
||||||
|
|
||||||
if (autoDeleteResponse && m != null)
|
if (autoDeleteResponse && m != null)
|
||||||
@ -724,12 +639,7 @@ public class DeviceSession : IDeviceSession
|
|||||||
}
|
}
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -759,13 +669,9 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
|
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
|
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetOrigin(StackTrace stackTrace)
|
private Type GetOrigin(StackTrace stackTrace)
|
||||||
@ -865,11 +771,11 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
#region "Users"
|
#region "Users"
|
||||||
|
|
||||||
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool? useIndependentGroupPermission = null, DateTime until = default)
|
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool useIndependentGroupPermission = false, DateTime until = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Api(a => a.RestrictChatMemberAsync(DeviceId, userId, permissions, useIndependentGroupPermission, until));
|
await Api(a => a.RestrictChatMember(DeviceId, userId, permissions, useIndependentChatPermissions: useIndependentGroupPermission, untilDate: until));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -878,49 +784,31 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
public virtual async Task<ChatMember> GetChatUser(long userId)
|
public virtual async Task<ChatMember> GetChatUser(long userId)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("User BanUser instead.")]
|
[Obsolete("User BanUser instead.")]
|
||||||
public virtual async Task KickUser(long userId, DateTime until = default)
|
public virtual async Task KickUser(long userId, DateTime until = default)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task BanUser(long userId, DateTime until = default)
|
public virtual async Task BanUser(long userId, DateTime until = default)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task UnbanUser(long userId)
|
public virtual async Task UnbanUser(long userId)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
|
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
@ -48,11 +48,7 @@ public class JsonStateMachine : IStateMachine
|
|||||||
{
|
{
|
||||||
var content = File.ReadAllText(FilePath);
|
var content = File.ReadAllText(FilePath);
|
||||||
|
|
||||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content, new JsonSerializerSettings
|
var sc = JsonSerializer.Deserialize<StateContainer>(content);
|
||||||
{
|
|
||||||
TypeNameHandling = TypeNameHandling.All,
|
|
||||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
|
||||||
});
|
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
@ -77,10 +73,9 @@ public class JsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings
|
var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
TypeNameHandling = TypeNameHandling.All,
|
WriteIndented = true,
|
||||||
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
|
|
||||||
});
|
});
|
||||||
|
|
||||||
File.WriteAllText(FilePath, content);
|
File.WriteAllText(FilePath, content);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
@ -49,7 +49,7 @@ public class SimpleJsonStateMachine : IStateMachine
|
|||||||
{
|
{
|
||||||
var content = File.ReadAllText(FilePath);
|
var content = File.ReadAllText(FilePath);
|
||||||
|
|
||||||
var sc = JsonConvert.DeserializeObject<StateContainer>(content);
|
var sc = JsonSerializer.Deserialize<StateContainer>(content);
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,9 @@ public class SimpleJsonStateMachine : IStateMachine
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var content = JsonConvert.SerializeObject(e.States, Formatting.Indented);
|
var content = JsonSerializer.Serialize(e.States, new JsonSerializerOptions() {
|
||||||
|
WriteIndented = true
|
||||||
|
});
|
||||||
|
|
||||||
File.WriteAllText(FilePath, content);
|
File.WriteAllText(FilePath, content);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
|
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -14,11 +14,11 @@
|
|||||||
<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="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="22.2.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="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
|
<dependency id="Telegram.Bot" version="22.2.0" exclude="Build,Analyzers" />
|
||||||
</group>
|
</group>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
@ -32,7 +32,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotAndWebApplication", "Exa
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyInjection", "Examples\DependencyInjection\DependencyInjection.csproj", "{689B16BC-200E-4C68-BB2E-8B209070849B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyInjection", "Examples\DependencyInjection\DependencyInjection.csproj", "{689B16BC-200E-4C68-BB2E-8B209070849B}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.Serializer.Database.PostgreSql", "TelegramBotBase.Extensions.Serializer.Database.PostgreSql\TelegramBotBase.Extensions.Serializer.Database.PostgreSql.csproj", "{7C55D9FF-7DC1-41D0-809C-469EBFA20992}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotBase.Extensions.Images.IronSoftware", "TelegramBotBase.Extensions.Images.IronSoftware\TelegramBotBase.Extensions.Images.IronSoftware.csproj", "{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Элементы решения", "Элементы решения", "{040F54FA-B51F-475F-89F8-2DD23CDC2989}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.gitea\workflows\TelegramBotFramework.nuget.yaml = .gitea\workflows\TelegramBotFramework.nuget.yaml
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -84,6 +93,14 @@ Global
|
|||||||
{689B16BC-200E-4C68-BB2E-8B209070849B}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{689B16BC-200E-4C68-BB2E-8B209070849B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7C55D9FF-7DC1-41D0-809C-469EBFA20992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7C55D9FF-7DC1-41D0-809C-469EBFA20992}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7C55D9FF-7DC1-41D0-809C-469EBFA20992}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7C55D9FF-7DC1-41D0-809C-469EBFA20992}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -98,6 +115,8 @@ Global
|
|||||||
{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}
|
{689B16BC-200E-4C68-BB2E-8B209070849B} = {BFA71E3F-31C0-4FC1-A320-4DCF704768C5}
|
||||||
|
{7C55D9FF-7DC1-41D0-809C-469EBFA20992} = {E3193182-6FDA-4FA3-AD26-A487291E7681}
|
||||||
|
{DC521A4C-7446-46F7-845B-AAF10EDCF8C6} = {E3193182-6FDA-4FA3-AD26-A487291E7681}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}
|
SolutionGuid = {59CB40E1-9FA7-4867-A56F-4F418286F057}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user