Skip to content

Commit

Permalink
Fix GPT commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Dec 31, 2023
1 parent 3a0da7f commit 03d4653
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 5 additions & 1 deletion BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ select ChatMessage.FromText(
// Track thread
_telegramMessageCache.Add(
message: AIResponseMessage.FromMessage(responseMessage, "AI")
message: AIResponseMessage.FromMessage(
message: responseMessage,
replyToMessageId: command.PromptMessageId,
callSign: "AI"
)
);
});
}
Expand Down
5 changes: 3 additions & 2 deletions BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ await _telegramBotClient.EditMessageTextAsync(
// Track thread
_telegramMessageCache.Add(
message: AIResponseMessage.FromMessage(
responseMessage,
command.CallSign
message: responseMessage,
replyToMessageId: command.PromptMessageId,
callSign: command.CallSign
)
);
});
Expand Down
10 changes: 6 additions & 4 deletions BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public async Task Handle(AICallCommand command, CancellationToken cancellationTo
await _commandQueue.DispatchAsync(
command: OpenAITextPrompt.FromAICallCommand(
aiCallCommand: command,
thread: _telegramMessageCache.GetThread(
messageId: command.MessageId,
chatId: command.ChatId
)
thread: command.ReplyToMessageId.HasValue
? _telegramMessageCache.GetThread(
messageId: command.ReplyToMessageId.Value,
chatId: command.ChatId
)
: Enumerable.Empty<MessageBase>()
)
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public async Task Handle(AIFollowUpMessage command, CancellationToken cancellati
await _commandQueue.DispatchAsync(
command: OpenAITextPrompt.FromAIFollowUpMessage(
aiFollowUpMessage: command,
thread: _telegramMessageCache.GetThread(
messageId: command.MessageId,
chatId: command.ChatId
)
thread: command.ReplyToMessageId.HasValue
? _telegramMessageCache.GetThread(
messageId: command.ReplyToMessageId.Value,
chatId: command.ChatId
)
: Enumerable.Empty<MessageBase>()
)
);
break;
Expand Down
8 changes: 2 additions & 6 deletions BotNet.Commands/BotUpdate/Message/AIResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@ string callSign

public static AIResponseMessage FromMessage(
Telegram.Bot.Types.Message message,
int replyToMessageId,
string callSign
) {
// Message must be a reply
if (message.ReplyToMessage is not { } replyToMessage) {
throw new ArgumentException("Message must be a reply.", nameof(message));
}

return new(
messageId: message.MessageId,
chatId: message.Chat.Id,
senderId: message.From!.Id,
senderName: callSign,
text: message.Text ?? message.Caption ?? "",
imageFileId: message.Photo?.FirstOrDefault()?.FileId,
replyToMessageId: replyToMessage.MessageId,
replyToMessageId: replyToMessageId,
replyToMessage: null,
callSign: callSign
);
Expand Down

0 comments on commit 03d4653

Please sign in to comment.