Skip to content

Commit ec332c0

Browse files
author
Igor Evdokimov
committed
- refactoring
- appsettings fix - layouts support in AddTelegramBot() now
1 parent a750ad5 commit ec332c0

File tree

9 files changed

+23
-38
lines changed

9 files changed

+23
-38
lines changed

Botticelli.Framework.Telegram/Extensions/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static IServiceCollection AddTelegramBot(this IServiceCollection services
6666
/// <param name="optionsBuilderFunc"></param>
6767
/// <param name="analyticsOptionsBuilderFunc"></param>
6868
/// <param name="serverSettingsBuilderFunc"></param>
69+
/// <param name="dataAccessSettingsBuilderFunc"></param>
6970
/// <returns></returns>
7071
public static IServiceCollection AddTelegramBot(this IServiceCollection services,
7172
Action<BotSettingsBuilder<TelegramBotSettings>> optionsBuilderFunc,
@@ -88,7 +89,8 @@ public static IServiceCollection AddTelegramBot(this IServiceCollection services
8889
.AddClient(clientBuilder);
8990
var bot = botBuilder.Build();
9091
return services.AddSingleton<IBot<TelegramBot>>(bot)
91-
.AddSingleton<IBot>(bot);
92+
.AddSingleton<IBot>(bot)
93+
.AddTelegramLayoutsSupport();
9294
}
9395

9496
public static IServiceCollection AddTelegramLayoutsSupport(this IServiceCollection services) =>

Samples/AiSample.Common/AiCommandProcessor.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ public AiCommandProcessor(ILogger<AiCommandProcessor<TReplyMarkup>> logger,
3737

3838
_bus.OnReceived += async (sender, response) =>
3939
{
40-
if (response != null)
41-
await Bot.SendMessageAsync(new SendMessageRequest(response.Uid)
42-
{
43-
Message = response.Message,
44-
ExpectPartialResponse = response.IsPartial,
45-
SequenceNumber = response.SequenceNumber,
46-
IsFinal = response.IsFinal
47-
},
48-
options,
49-
CancellationToken.None);
40+
await Bot.SendMessageAsync(new SendMessageRequest(response.Uid)
41+
{
42+
Message = response.Message,
43+
ExpectPartialResponse = response.IsPartial,
44+
SequenceNumber = response.SequenceNumber,
45+
IsFinal = response.IsFinal
46+
},
47+
options,
48+
CancellationToken.None);
5049
};
5150
}
5251

Samples/TelegramCommandChainSample/Program.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using Botticelli.Framework.Extensions;
44
using Botticelli.Framework.Telegram;
55
using Botticelli.Framework.Telegram.Extensions;
6-
using Botticelli.Schedule.Quartz.Extensions;
7-
using Botticelli.Talks.Extensions;
86
using MessagingSample.Common.Commands;
97
using MessagingSample.Common.Commands.Processors;
108
using NLog.Extensions.Logging;
@@ -17,17 +15,13 @@
1715
builder.Services
1816
.AddTelegramBot(builder.Configuration)
1917
.AddLogging(cfg => cfg.AddNLog())
20-
.AddQuartzScheduler(builder.Configuration)
2118
.AddScoped<StartCommandProcessor<ReplyMarkupBase>>()
2219
.AddScoped<StopCommandProcessor<ReplyMarkupBase>>()
2320
.AddScoped<InfoCommandProcessor<ReplyMarkupBase>>()
24-
.AddOpenTtsTalks(builder.Configuration)
25-
.AddScoped<ILayoutParser, JsonLayoutParser>()
2621
.AddBotCommand<InfoCommand, InfoCommandProcessor<ReplyMarkupBase>, PassValidator<InfoCommand>>()
2722
.AddBotCommand<StartCommand, StartCommandProcessor<ReplyMarkupBase>, PassValidator<StartCommand>>()
2823
.AddBotCommand<StopCommand, StopCommandProcessor<ReplyMarkupBase>, PassValidator<StopCommand>>();
2924

30-
3125
// Command processing chain is being initialized here...
3226
builder.Services.AddBotChainProcessedCommand<GetNameCommand, PassValidator<GetNameCommand>>()
3327
.AddNext<GetNameCommandProcessor>()

Samples/TelegramCommandChainSample/TelegramCommandChainSample.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.*"/>
2121
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2"/>
22-
<ProjectReference Include="..\..\Botticelli.Scheduler.Quartz\Botticelli.Scheduler.Quartz.csproj" />
23-
<ProjectReference Include="..\..\Botticelli.Talks\Botticelli.Talks.csproj" />
2422
<ProjectReference Include="..\MessagingSample.Common\MessagingSample.Common.csproj"/>
2523
</ItemGroup>
2624

Samples/TelegramCommandChainSample/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
}
77
},
88
"DataAccess": {
9-
"ConnectionString": "Filename=database.db;Password=123;ReadOnly=false"
9+
"ConnectionString": "database.db;Password=123"
1010
},
1111
"Server": {
12-
"ServerUri": "http://113.30.189.83:5042/v1/"
12+
"ServerUri": "http://103.252.116.18:5042/v1/"
1313
},
1414
"AnalyticsClient": {
1515
"TargetUrl": "http://localhost:5251/v1/"

Samples/TelegramMessagingSample/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
builder.Services
1515
.AddTelegramBot(builder.Configuration)
1616
.AddLogging(cfg => cfg.AddNLog())
17-
.AddQuartzScheduler(builder.Configuration)
18-
.AddScoped<ILayoutParser, JsonLayoutParser>();
17+
.AddQuartzScheduler(builder.Configuration);
1918

2019
builder.Services.AddBotCommand<InfoCommand>()
2120
.AddProcessor<InfoCommandProcessor<ReplyMarkupBase>>()

Samples/TelegramMessagingSample/TelegramMessagingSample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.*"/>
2525
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2"/>
2626
<ProjectReference Include="..\..\Botticelli.Scheduler.Quartz\Botticelli.Scheduler.Quartz.csproj" />
27-
<ProjectReference Include="..\..\Botticelli.Talks\Botticelli.Talks.csproj" />
2827
<ProjectReference Include="..\MessagingSample.Common\MessagingSample.Common.csproj"/>
2928
</ItemGroup>
3029

Samples/TelegramMonadsBasedBot/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
using Botticelli.Framework.Telegram.Layout;
99
using NLog.Extensions.Logging;
1010
using Telegram.Bot.Types.ReplyMarkups;
11-
using TelegramMonadsBasedBot;
1211
using TelegramMonadsBasedBot.Commands;
1312

1413
var builder = WebApplication.CreateBuilder(args);
1514

1615
builder.Services
1716
.AddTelegramBot(builder.Configuration)
1817
.AddLogging(cfg => cfg.AddNLog())
19-
.AddScoped<ILayoutParser, JsonLayoutParser>()
2018
.AddTelegramLayoutsSupport();
2119

2220
builder.Services.AddBotCommand<MathCommand>()

Samples/VkMessagingSample/Program.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using Botticelli.Framework.Commands.Validators;
2-
using Botticelli.Framework.Controls.Parsers;
32
using Botticelli.Framework.Extensions;
4-
using Botticelli.Framework.Options;
53
using Botticelli.Framework.Vk.Messages;
64
using Botticelli.Framework.Vk.Messages.API.Markups;
75
using Botticelli.Framework.Vk.Messages.Extensions;
8-
using Botticelli.Framework.Vk.Messages.Options;
96
using Botticelli.Schedule.Quartz.Extensions;
107
using Botticelli.Talks.Extensions;
118
using MessagingSample.Common.Commands;
@@ -15,15 +12,14 @@
1512
var builder = WebApplication.CreateBuilder(args);
1613

1714
builder.Services
18-
.AddVkBot(builder.Configuration)
19-
.AddLogging(cfg => cfg.AddNLog())
20-
.AddQuartzScheduler(builder.Configuration)
21-
.AddScoped<StartCommandProcessor<VkKeyboardMarkup>>()
22-
.AddScoped<StopCommandProcessor<VkKeyboardMarkup>>()
23-
.AddOpenTtsTalks(builder.Configuration)
24-
.AddScoped<ILayoutParser, JsonLayoutParser>()
25-
.AddBotCommand<StartCommand, StartCommandProcessor<VkKeyboardMarkup>, PassValidator<StartCommand>>()
26-
.AddBotCommand<StopCommand, StopCommandProcessor<VkKeyboardMarkup>, PassValidator<StopCommand>>();
15+
.AddVkBot(builder.Configuration)
16+
.AddLogging(cfg => cfg.AddNLog())
17+
.AddQuartzScheduler(builder.Configuration)
18+
.AddScoped<StartCommandProcessor<VkKeyboardMarkup>>()
19+
.AddScoped<StopCommandProcessor<VkKeyboardMarkup>>()
20+
.AddOpenTtsTalks(builder.Configuration)
21+
.AddBotCommand<StartCommand, StartCommandProcessor<VkKeyboardMarkup>, PassValidator<StartCommand>>()
22+
.AddBotCommand<StopCommand, StopCommandProcessor<VkKeyboardMarkup>, PassValidator<StopCommand>>();
2723

2824

2925
var app = builder.Build();

0 commit comments

Comments
 (0)