Skip to content

A platform for community discussion. Free, open, simple.

FIX: Discord Bot crash due to missing BotContext in PersonaReplier (#36429)

DevTekVE8b29528420a0
diff --git a/plugins/discourse-ai/lib/discord/bot/persona_replier.rb b/plugins/discourse-ai/lib/discord/bot/persona_replier.rb
index 807ffd834f2..ab1f92f2e2a 100644
--- a/plugins/discourse-ai/lib/discord/bot/persona_replier.rb
+++ b/plugins/discourse-ai/lib/discord/bot/persona_replier.rb
@@ -21,10 +21,15 @@ module DiscourseAi
def handle_interaction!
last_update_sent_at = Time.now - 1
reply = +""
+
+ context =
+ DiscourseAi::Personas::BotContext.new(
+ messages: [{ type: :user, content: @query }],
+ skip_show_thinking: true,
+ )
+
full_reply =
- @bot.reply(
- { conversation_context: [{ type: :user, content: @query }], skip_show_thinking: true },
- ) do |partial, _something|
+ @bot.reply(context) do |partial, _something|
reply << partial
next if reply.blank?
diff --git a/plugins/discourse-ai/spec/lib/discord/bot/persona_replier_spec.rb b/plugins/discourse-ai/spec/lib/discord/bot/persona_replier_spec.rb
index 09b6beb7b1e..d6f9a0ac9bf 100644
--- a/plugins/discourse-ai/spec/lib/discord/bot/persona_replier_spec.rb
+++ b/plugins/discourse-ai/spec/lib/discord/bot/persona_replier_spec.rb
@@ -23,5 +23,14 @@ RSpec.describe DiscourseAi::Discord::Bot::PersonaReplier do
persona_replier.handle_interaction!
expect(persona_replier).to have_received(:create_reply).at_least(:once)
end
+
+ it "uses a BotContext to generate the reply" do
+ expect_any_instance_of(DiscourseAi::Personas::Bot).to receive(:reply) do |bot, context|
+ expect(context).to be_a(DiscourseAi::Personas::BotContext)
+ [["This is a reply from bot!"]]
+ end
+
+ persona_replier.handle_interaction!
+ end
end
end