FEATURE: optional warning attached to all AI bot conversations (#137)
* FEATURE: optional warning attached to all AI bot conversations This commit introduces `ai_bot_enable_chat_warning` which can be used to warn people prior to starting a chat with the bot. In particular this is useful if moderators are regularly reading chat transcripts as it sets expectations early. By default this is disabled. Also: - Stops making ajax call prior to opening composer - Hides PM title when starting a bot PM Co-authored-by: Rafael dos Santos Silva <[email protected]>
This commit is contained in:
co-authored by
Rafael dos Santos Silva
parent
49f2453c2d
commit
01f833f86e
@@ -10,7 +10,7 @@ export default class AiBotHeaderPanel extends Component {
|
||||
@service composer;
|
||||
|
||||
@action
|
||||
async composeMessageWithTargetBot(target) {
|
||||
composeMessageWithTargetBot(target) {
|
||||
this.#composeAiBotMessage(target);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export default class AiBotHeaderPanel extends Component {
|
||||
return this.siteSettings.ai_bot_enabled_chat_bots.split("|");
|
||||
}
|
||||
|
||||
async #composeAiBotMessage(targetBot) {
|
||||
#composeAiBotMessage(targetBot) {
|
||||
this.args.closePanel();
|
||||
composeAiBotMessage(targetBot, this.composer);
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{{#if this.isAiBotChat}}
|
||||
<DSection @bodyClass="ai-bot-chat" />
|
||||
{{#if this.renderChatWarning}}
|
||||
<div class="ai-bot-chat-warning">{{i18n
|
||||
"discourse_ai.ai_bot.pm_warning"
|
||||
}}</div>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { inject as service } from "@ember/service";
|
||||
import { computed } from "@ember/object";
|
||||
|
||||
export default class extends Component {
|
||||
static shouldRender() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@service currentUser;
|
||||
@service siteSettings;
|
||||
|
||||
get composerModel() {
|
||||
return this.args.outletArgs.model;
|
||||
}
|
||||
|
||||
get renderChatWarning() {
|
||||
return this.siteSettings.ai_bot_enable_chat_warning;
|
||||
}
|
||||
|
||||
@computed("composerModel.targetRecipients")
|
||||
get isAiBotChat() {
|
||||
if (this.composerModel.targetRecipients) {
|
||||
let reciepients = this.composerModel.targetRecipients.split(",");
|
||||
|
||||
return this.currentUser.ai_enabled_chat_bots.any((bot) =>
|
||||
reciepients.any((username) => username === bot.username)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import Composer from "discourse/models/composer";
|
||||
import I18n from "I18n";
|
||||
|
||||
export async function composeAiBotMessage(targetBot, composer) {
|
||||
let botUsername = await ajax("/discourse-ai/ai-bot/bot-username", {
|
||||
data: { username: targetBot },
|
||||
}).then((data) => {
|
||||
return data.bot_username;
|
||||
});
|
||||
export function composeAiBotMessage(targetBot, composer) {
|
||||
const currentUser = composer.currentUser;
|
||||
|
||||
let botUsername = currentUser.ai_enabled_chat_bots.find(
|
||||
(bot) => bot.model_name === targetBot
|
||||
).username;
|
||||
|
||||
composer.focusComposer({
|
||||
fallbackToNewTopic: true,
|
||||
|
||||
Reference in New Issue
Block a user