Skip to content

Commit db68996

Browse files
authored
Merge pull request #51 from GarageGroup/feature/fix-lock-error
Fix lock error
2 parents 823371c + c7bd0bf commit db68996

File tree

7 files changed

+40
-94
lines changed

7 files changed

+40
-94
lines changed

src/app/AzureFunc/Applicaton/App.Bot.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
using System;
22
using GarageGroup.Infra;
33
using GarageGroup.Infra.Bot.Builder;
4+
using Microsoft.Azure.Functions.Worker;
45
using Microsoft.Bot.Builder;
6+
using Microsoft.DurableTask.Client;
57
using PrimeFuncPack;
68

79
namespace GarageGroup.Internal.Support;
810

911
partial class Application
1012
{
1113
[HttpFunction("HandleHttpBotMessage", HttpMethodName.Post, Route = "messages", AuthLevel = HttpAuthorizationLevel.Function)]
14+
internal static Dependency<IBotSignalHandler> UseBotSignal([DurableClient] DurableTaskClient client)
15+
=>
16+
Dependency.Of(
17+
client)
18+
.UseOrchestrationEntityApi()
19+
.UseBotSignalHandler(
20+
BotEntityName);
21+
22+
[EntityFunction("HandleBotRequest", EntityName = BotEntityName)]
1223
internal static Dependency<IBotRequestHandler> UseBot()
1324
=>
1425
Dependency.From(
@@ -24,5 +35,5 @@ private static IBot ResolveBot(this IServiceProvider serviceProvider)
2435
.UseAuthorizationFlow()
2536
.UseBotInfoFlow()
2637
.UseIncidentCreateFlow()
27-
.Build(true);
38+
.Build();
2839
}

src/app/AzureFunc/Applicaton/Applicaton.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal static partial class Application
2020

2121
private const string IncidentCompleteSectionName = "IncidentComplete";
2222

23+
private const string BotEntityName = "BotRequest";
24+
2325
private static Dependency<HttpMessageHandler> UseHttpMessageHandlerStandard(string loggerCategoryName)
2426
=>
2527
PrimaryHandler.UseStandardSocketsHttpHandler()

src/app/AzureFunc/AzureFunc.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="GarageGroup.Infra.Azure.Handler" Version="0.8.0" />
31-
<PackageReference Include="GarageGroup.Infra.Azure.HealthCheck" Version="0.5.0" />
32-
<PackageReference Include="GarageGroup.Infra.Azure.Hosting" Version="0.3.1" />
30+
<PackageReference Include="GarageGroup.Infra.Azure.DurableTask" Version="0.3.0" />
31+
<PackageReference Include="GarageGroup.Infra.Azure.HealthCheck" Version="0.6.0" />
32+
<PackageReference Include="GarageGroup.Infra.Azure.Hosting" Version="0.4.0" />
3333
<PackageReference Include="GarageGroup.Infra.Azure.Services.AzureUser.Api" Version="0.1.1" />
3434
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Authorization.Dataverse" Version="0.4.0" />
3535
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Command.Info" Version="0.2.0" />
3636
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Command.Stop" Version="0.2.0" />
3737
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.CosmosStorage" Version="0.2.0" />
38-
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.Handler" Version="0.3.2" />
38+
<PackageReference Include="GarageGroup.Infra.Bot.Builder.Integration.Handler" Version="0.4.0" />
3939
<PackageReference Include="GarageGroup.Infra.Dataverse.Api" Version="3.12.0" />
4040
<PackageReference Include="GarageGroup.Infra.Dataverse.DataverseUser.Api" Version="1.3.0" />
4141
<PackageReference Include="GarageGroup.Infra.Http.Polly" Version="1.1.1" />
4242
<PackageReference Include="GarageGroup.Infra.Sql.Api" Version="2.1.0" />
4343
<PackageReference Include="GarageGroup.Infra.Sql.Api.Provider.Microsoft" Version="2.1.0" />
44-
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.11.0" OutputItemType="Analyzer" />
44+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.1" OutputItemType="Analyzer" />
4545
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
4646
<PackageReference Include="PrimeFuncPack.DependencyRegistry" Version="1.2.1" />
4747
</ItemGroup>

src/endpoint/Incident.Create/Flow/FlowState/IncidentGptFlowState.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ internal readonly record struct IncidentGptFlowState
1010
[JsonProperty("sourceMessage")]
1111
public string? SourceMessage { get; init; }
1212

13-
[JsonProperty("temporaryActivityId")]
14-
public string? TemporaryActivityId { get; init; }
15-
1613
[JsonProperty("errorMessage")]
1714
public string? ErrorMessage { get; init; }
1815
}

src/endpoint/Incident.Create/Flow/Step.AwaitTitle/TitleAwaitHelper.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Text;
34
using GarageGroup.Infra.Bot.Builder;
45

56
namespace GarageGroup.Internal.Support;
@@ -23,14 +24,24 @@ internal static ValueStepOption<string> GetStepOption(IChatFlowContext<IncidentC
2324
return new("Укажите заголовок");
2425
}
2526

27+
var messageBuilder = new StringBuilder("Укажите заголовок или используйте сгенерированный вариант:\n\r");
28+
29+
if (context.IsNotTelegramChannel())
30+
{
31+
messageBuilder = messageBuilder.Append(context.FlowState.Gpt.Title);
32+
}
33+
else
34+
{
35+
messageBuilder = messageBuilder.Append("<code>").Append(context.FlowState.Gpt.Title).Append("</code>");
36+
}
37+
2638
return new(
27-
messageText: "Укажите заголовок или подтвердите вариант, сгенерированный нейросетью",
28-
suggestions: new[]
39+
messageText: messageBuilder.ToString(),
40+
suggestions: new KeyValuePair<string, string>[][]
2941
{
30-
new KeyValuePair<string, string>[]
31-
{
32-
new("Подтвердить предложение нейросети", context.FlowState.Gpt.Title.TruncateTitle())
33-
}
42+
[
43+
new("Использовать сгенерированный заголовок", context.FlowState.Gpt.Title.TruncateTitle())
44+
]
3445
});
3546
}
3647

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
using GarageGroup.Infra.Bot.Builder;
2-
using Microsoft.Bot.Schema;
32

43
namespace GarageGroup.Internal.Support;
54

65
internal static class GptCallFlowStep
76
{
8-
internal static ChatFlow<IncidentCreateFlowState> CallGpt(this ChatFlow<IncidentCreateFlowState> chatFlow, ISupportGptApi gptApi)
7+
internal static ChatFlow<IncidentCreateFlowState> CallGpt(
8+
this ChatFlow<IncidentCreateFlowState> chatFlow, ISupportGptApi gptApi)
99
=>
10-
chatFlow.SetTypingStatus(
11-
GptCallHelper.CreateTemporaryActivity,
12-
ApplyTemporaryActivityId)
13-
.NextValue(
14-
gptApi.CompleteIncidentAsync)
15-
.ReplaceActivityOrSkip(
16-
GptCallHelper.CreateResultActivity);
17-
18-
private static IncidentCreateFlowState ApplyTemporaryActivityId(IncidentCreateFlowState flowState, ResourceResponse activityResponse)
19-
=>
20-
flowState with
21-
{
22-
Gpt = flowState.Gpt with
23-
{
24-
TemporaryActivityId = activityResponse.Id
25-
}
26-
};
10+
chatFlow.SetTypingStatus().NextValue(
11+
gptApi.CompleteIncidentAsync);
2712
}

src/endpoint/Incident.Create/Flow/Step.CallGpt/GptCallHelper.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,13 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using System.Web;
65
using GarageGroup.Infra.Bot.Builder;
7-
using Microsoft.Bot.Builder;
8-
using Microsoft.Bot.Schema;
96
using Microsoft.Extensions.Logging;
107

118
namespace GarageGroup.Internal.Support;
129

1310
internal static class GptCallHelper
1411
{
15-
internal static IActivity? CreateTemporaryActivity(IChatFlowContext<IncidentCreateFlowState> context)
16-
{
17-
if (context.IsNotTelegramChannel())
18-
{
19-
return null;
20-
}
21-
22-
var telegramActivity = context.Activity.CreateReply();
23-
24-
telegramActivity.ChannelData = new TelegramChannelData(
25-
parameters: new("ИИ генерирует заголовок...")
26-
{
27-
DisableNotification = true
28-
})
29-
.ToJObject();
30-
31-
return telegramActivity;
32-
}
33-
34-
internal static IActivity CreateResultActivity(IChatFlowContext<IncidentCreateFlowState> context)
35-
{
36-
var activity = InnerCreateActivity(context);
37-
if (string.IsNullOrEmpty(context.FlowState.Gpt.TemporaryActivityId))
38-
{
39-
return activity;
40-
}
41-
42-
activity.Id = context.FlowState.Gpt.TemporaryActivityId;
43-
return activity;
44-
45-
static IActivity InnerCreateActivity(IChatFlowContext<IncidentCreateFlowState> context)
46-
{
47-
if (string.IsNullOrEmpty(context.FlowState.Gpt.Title))
48-
{
49-
var errorMessage = context.FlowState.Gpt.ErrorMessage.OrNullIfWhiteSpace() ?? "Нейросеть не смогла подобрать заголовок";
50-
return MessageFactory.Text(errorMessage);
51-
}
52-
53-
if (context.IsNotTelegramChannel())
54-
{
55-
return MessageFactory.Text($"Нейросеть предлагает заголовок:\n\r{context.FlowState.Gpt.Title}");
56-
}
57-
58-
var telegramActivity = context.Activity.CreateReply();
59-
var encodedText = HttpUtility.HtmlEncode(context.FlowState.Gpt.Title);
60-
61-
telegramActivity.ChannelData = new TelegramChannelData(
62-
parameters: new($"Нейросеть предлагает заголовок:\n\r<code>{encodedText}</code>")
63-
{
64-
ParseMode = TelegramParseMode.Html
65-
})
66-
.ToJObject();
67-
68-
return telegramActivity;
69-
}
70-
}
71-
7212
internal static ValueTask<IncidentCreateFlowState> CompleteIncidentAsync(
7313
this ISupportGptApi gptApi, IChatFlowContext<IncidentCreateFlowState> context, CancellationToken cancellationToken)
7414
=>

0 commit comments

Comments
 (0)