From 084bbc123ecc9bd9eb45dfc808273b5c916ba70e Mon Sep 17 00:00:00 2001 From: Jegadeesh V Date: Tue, 24 Dec 2024 10:18:02 +0530 Subject: [PATCH 1/2] Updating Feedback buttons to the sample --- .../f.chatModeration/src/bot.ts | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts b/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts index 1c8244e75..c9afe4d3c 100644 --- a/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts +++ b/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts @@ -9,7 +9,7 @@ import { OpenAIModerator, Moderator } from '@microsoft/teams-ai'; -import { MemoryStorage, TurnContext } from 'botbuilder'; +import { ActivityTypes, CardFactory, MemoryStorage, TaskModuleTaskInfo, TurnContext } from 'botbuilder'; import * as path from 'path'; if (!process.env.OPENAI_KEY && !process.env.AZURE_OPENAI_KEY) { @@ -90,7 +90,8 @@ const app = new Application({ storage, ai: { planner, - moderator + moderator, + enable_feedback_loop: true } }); @@ -104,7 +105,11 @@ app.conversationUpdate('membersAdded', async (context, state) => { // Ignore the bot joining the conversation if (membersAdded[member].id !== context.activity.recipient.id) { await context.sendActivity( - `Hello and welcome! With this sample you can see the functionality of the Content Safety Moderator of Azure Open AI services.` + `Hello and welcome! With this sample, you can see the functionality of the Content Safety Moderator of Azure Open AI services. + Additionally, you can explore the feedback functionality by using the following commands: + +- **Default Feedback:** Test the default feedback feature. +- **Custom Feedback:** Try out the custom feedback option.` ); } } @@ -115,6 +120,77 @@ app.message('/reset', async (context, state) => { await context.sendActivity(`Ok lets start this over.`); }); +app.message('default feedback', async (context, state) => { + + await context.sendActivity({ + type: ActivityTypes.Message, + text: "We'd love to hear your thoughts! Please click below to provide feedback.", + channelData: { + feedbackLoop: { + type: "default" + } + }, + }); +}); + +app.message('custom feedback', async (context, state) => { + + await context.sendActivity({ + type: ActivityTypes.Message, + text: "We'd love to hear your thoughts! Please click below to provide feedback.", + channelData: { + feedbackLoop: { + type: "custom" + } + }, + }); +}); + +app.messages.fetch(async (context, state, data) => { + var taskInfo = {} as any; // TaskModuleTaskInfo + const createAdaptiveCardAttachment = () => + CardFactory.adaptiveCard({ + version: '1.0.0', + type: 'AdaptiveCard', + body: [ + { + type: 'TextBlock', + text: 'Enter Text Here' + }, + { + type: 'Input.Text', + id: 'usertext', + placeholder: 'This is a custom feedback form built with Adaptive Card.', + IsMultiline: true + } + ], + actions: [ + { + type: 'Action.Submit', + title: 'Submit' + } + ] + }); + + const setTaskInfo = (taskInfo: any, uiSettings: any) => { + taskInfo.height = uiSettings.height; + taskInfo.width = uiSettings.width; + taskInfo.title = uiSettings.title; + } + + taskInfo.card = createAdaptiveCardAttachment(); + + setTaskInfo(taskInfo, { + width: 400, + height: 200, + title: 'Custom Feedback Form', + id: path, + buttonTitle: 'Custom Feedback Form' + }); + + return Promise.resolve(taskInfo as string | TaskModuleTaskInfo); +}); + app.ai.action(AI.FlaggedInputActionName, async (context, state, data) => { let message = ''; if (data?.categories?.hate) { @@ -133,6 +209,7 @@ app.ai.action(AI.FlaggedInputActionName, async (context, state, data) => { await context.sendActivity( `I'm sorry your message was flagged due to triggering Azure OpenAI’s content management policy. Reason: ${message}` ); + return AI.StopCommandName; }); @@ -145,3 +222,9 @@ app.ai.action(AI.HttpErrorActionName, async (context, state, data) => { await context.sendActivity('An AI request failed. Please try again later.'); return AI.StopCommandName; }); + +app.feedbackLoop(async (context, state, data) => { + await context.sendActivity('Thank you for your feedback!'); + const Feedback = typeof data.actionValue.feedback === 'string' ? JSON.parse(data.actionValue.feedback) : data.actionValue.feedback; + await context.sendActivity('Provided reaction: '+ data.actionValue.reaction + '
Feedback: ' + (Feedback.usertext != undefined ? Feedback.usertext : Feedback.feedbackText)); +}); \ No newline at end of file From 1570ae7cb069682161a41e0f925e779877f9259e Mon Sep 17 00:00:00 2001 From: Jegadeesh V Date: Tue, 7 Jan 2025 14:46:32 +0530 Subject: [PATCH 2/2] Fixing pr comments --- js/samples/03.ai-concepts/f.chatModeration/src/bot.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts b/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts index c9afe4d3c..577c25af9 100644 --- a/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts +++ b/js/samples/03.ai-concepts/f.chatModeration/src/bot.ts @@ -91,7 +91,8 @@ const app = new Application({ ai: { planner, moderator, - enable_feedback_loop: true + enable_feedback_loop: true, + feedback_loop_type: 'custom' } });