DEV: Publish AI Bot PM title update to message bus channel (#781)
This commit is contained in:
parent
41054c4fb8
commit
94f6c632bf
|
@ -12,6 +12,13 @@ module ::Jobs
|
||||||
return unless post.topic.custom_fields[DiscourseAi::AiBot::EntryPoint::REQUIRE_TITLE_UPDATE]
|
return unless post.topic.custom_fields[DiscourseAi::AiBot::EntryPoint::REQUIRE_TITLE_UPDATE]
|
||||||
|
|
||||||
DiscourseAi::AiBot::Playground.new(bot).title_playground(post)
|
DiscourseAi::AiBot::Playground.new(bot).title_playground(post)
|
||||||
|
|
||||||
|
publish_update(post.topic, { title: post.topic.title })
|
||||||
|
end
|
||||||
|
|
||||||
|
def publish_update(topic, payload)
|
||||||
|
allowed_users = topic.topic_allowed_users.pluck(:user_id)
|
||||||
|
MessageBus.publish("/discourse-ai/ai-bot/topic/#{topic.id}", payload, user_ids: allowed_users)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,4 +39,27 @@ RSpec.describe Jobs::UpdateAiBotPmTitle do
|
||||||
expect(post.reload.topic.title).to eq("My amazing title")
|
expect(post.reload.topic.title).to eq("My amazing title")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "will post an update with the new title to the message bus channel" do
|
||||||
|
SiteSetting.ai_bot_allowed_groups = Group::AUTO_GROUPS[:staff]
|
||||||
|
post =
|
||||||
|
create_post(
|
||||||
|
user: user,
|
||||||
|
raw: "Hello there",
|
||||||
|
title: "does not matter should be updated",
|
||||||
|
archetype: Archetype.private_message,
|
||||||
|
target_usernames: bot_user.username,
|
||||||
|
)
|
||||||
|
title_result = "A great title would be:\n\nMy amazing title\n\n"
|
||||||
|
|
||||||
|
DiscourseAi::Completions::Llm.with_prepared_responses([title_result]) do
|
||||||
|
messages =
|
||||||
|
MessageBus.track_publish("/discourse-ai/ai-bot/topic/#{post.topic.id}") do
|
||||||
|
subject.execute(bot_user_id: bot_user.id, post_id: post.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
final_update = messages.last.data
|
||||||
|
expect(final_update[:title]).to eq("My amazing title")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue