@@ -23,24 +23,37 @@ export function showShareConversationModal(modal, topicId) {
23
23
. catch ( popupAjaxError ) ;
24
24
}
25
25
26
- export function composeAiBotMessage ( targetBot , composer ) {
26
+ export async function composeAiBotMessage (
27
+ targetBot ,
28
+ composer ,
29
+ options = {
30
+ skipFocus : false ,
31
+ topicBody : "" ,
32
+ }
33
+ ) {
27
34
const currentUser = composer . currentUser ;
28
35
const draftKey = "new_private_message_ai_" + new Date ( ) . getTime ( ) ;
29
36
30
- let botUsername = currentUser . ai_enabled_chat_bots . find (
31
- ( bot ) => bot . model_name === targetBot
32
- ) . username ;
37
+ const botUsername = ! targetBot
38
+ ? currentUser . ai_enabled_chat_bots [ 0 ] . username
39
+ : currentUser . ai_enabled_chat_bots . find (
40
+ ( bot ) => bot . model_name === targetBot
41
+ ) ?. username ;
33
42
34
- composer . focusComposer ( {
35
- fallbackToNewTopic : true ,
36
- openOpts : {
37
- action : Composer . PRIVATE_MESSAGE ,
38
- recipients : botUsername ,
39
- topicTitle : i18n ( "discourse_ai.ai_bot.default_pm_prefix" ) ,
40
- archetypeId : "private_message" ,
41
- draftKey,
42
- hasGroups : false ,
43
- warningsDisabled : true ,
44
- } ,
45
- } ) ;
43
+ const data = {
44
+ action : Composer . PRIVATE_MESSAGE ,
45
+ recipients : botUsername ,
46
+ topicTitle : i18n ( "discourse_ai.ai_bot.default_pm_prefix" ) ,
47
+ archetypeId : "private_message" ,
48
+ draftKey,
49
+ hasGroups : false ,
50
+ warningsDisabled : true ,
51
+ } ;
52
+
53
+ if ( options . skipFocus ) {
54
+ data . topicBody = options . topicBody ;
55
+ await composer . open ( data ) ;
56
+ } else {
57
+ composer . focusComposer ( { fallbackToNewTopic : true , openOpts : data } ) ;
58
+ }
46
59
}
0 commit comments