@@ -162,7 +162,7 @@ def self.schedule_reply(post)
162162 end
163163 end
164164
165- def self . reply_to_post ( post :, user : nil , persona_id : nil , whisper : nil )
165+ def self . reply_to_post ( post :, user : nil , persona_id : nil , whisper : nil , add_user_to_pm : false )
166166 ai_persona = AiPersona . find_by ( id : persona_id )
167167 raise Discourse ::InvalidParameters . new ( :persona_id ) if !ai_persona
168168 persona_class = ai_persona . class_instance
@@ -173,7 +173,12 @@ def self.reply_to_post(post:, user: nil, persona_id: nil, whisper: nil)
173173 bot = DiscourseAi ::AiBot ::Bot . as ( bot_user , persona : persona )
174174 playground = DiscourseAi ::AiBot ::Playground . new ( bot )
175175
176- playground . reply_to ( post , whisper : whisper , context_style : :topic )
176+ playground . reply_to (
177+ post ,
178+ whisper : whisper ,
179+ context_style : :topic ,
180+ add_user_to_pm : add_user_to_pm ,
181+ )
177182 end
178183
179184 def initialize ( bot )
@@ -433,7 +438,14 @@ def get_context(participants:, conversation_context:, user:, skip_tool_details:
433438 result
434439 end
435440
436- def reply_to ( post , custom_instructions : nil , whisper : nil , context_style : nil , &blk )
441+ def reply_to (
442+ post ,
443+ custom_instructions : nil ,
444+ whisper : nil ,
445+ context_style : nil ,
446+ add_user_to_pm : true ,
447+ &blk
448+ )
437449 # this is a multithreading issue
438450 # post custom prompt is needed and it may not
439451 # be properly loaded, ensure it is loaded
@@ -470,7 +482,7 @@ def reply_to(post, custom_instructions: nil, whisper: nil, context_style: nil, &
470482 stream_reply = post . topic . private_message?
471483
472484 # we need to ensure persona user is allowed to reply to the pm
473- if post . topic . private_message?
485+ if post . topic . private_message? && add_user_to_pm
474486 if !post . topic . topic_allowed_users . exists? ( user_id : reply_user . id )
475487 post . topic . topic_allowed_users . create! ( user_id : reply_user . id )
476488 end
@@ -485,6 +497,7 @@ def reply_to(post, custom_instructions: nil, whisper: nil, context_style: nil, &
485497 skip_validations : true ,
486498 skip_jobs : true ,
487499 post_type : post_type ,
500+ skip_guardian : true ,
488501 )
489502
490503 publish_update ( reply_post , { raw : reply_post . cooked } )
@@ -560,6 +573,7 @@ def reply_to(post, custom_instructions: nil, whisper: nil, context_style: nil, &
560573 raw : reply ,
561574 skip_validations : true ,
562575 post_type : post_type ,
576+ skip_guardian : true ,
563577 )
564578 end
565579
0 commit comments