Skip to content

Commit c7bd0bf

Browse files
author
pmosk
committed
Simplify choice message
1 parent e50162e commit c7bd0bf

File tree

4 files changed

+21
-88
lines changed

4 files changed

+21
-88
lines changed

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)