How to reply on the same Slack Thread using Azure Custom QuestionAnswering

Azzollini, Gianluca 25 Reputation points
2024-11-29T09:40:24.35+00:00

I would kindly ask you to help on this topic if possible.

My Azure Bot based on Custom Question Answering is actually up and running: based on the knowledge fixed question I get the corresponding answer.

This is the actual code I'm using within the qnaBotWithMSI.js file:

const { ActivityHandler } = require('botbuilder');
class QnABotWithMSI extends ActivityHandler {
    /**
     *
     * @param {ConversationState} conversationState
     * @param {UserState} userState
     * @param {Dialog} dialog
     */
    constructor(conversationState, userState, dialog) {
        super();
        if (!conversationState) throw new Error('[QnABotWithMSI]: Missing parameter. conversationState is required');
        if (!userState) throw new Error('[QnABotWithMSI]: Missing parameter. userState is required');
        if (!dialog) throw new Error('[QnABotWithMSI]: Missing parameter. dialog is required');

        this.conversationState = conversationState;
        this.userState = userState;
        this.dialog = dialog;
        this.dialogState = this.conversationState.createProperty('DialogState');

        this.onMessage(async (context, next) => {
            console.log('Running dialog with Message Activity.');

            // Run the Dialog with the new message Activity.
            await this.dialog.run(context, this.dialogState);

            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });
        // If a new user is added to the conversation:
        this.onMembersAdded(async (context, next) => {
            const membersAdded = context.activity.membersAdded;
            for (let cnt = 0; cnt < membersAdded.length; cnt++) {
                if (membersAdded[cnt].id !== context.activity.recipient.id) {
                    const defaultWelcome = process.env.DefaultWelcomeMessage;
                    if (defaultWelcome !== '') await context.sendActivity(defaultWelcome);
                    else await context.sendActivity('Welcome to the QnA Maker');
                }
            }
            await next();
        });
    }
    async run(context) {
        await super.run(context);
        // Save any state changes. The load happened during the execution of the Dialog.
        await this.conversationState.saveChanges(context, false);
        await this.userState.saveChanges(context, false);
    }
}

The main goal would be to ask the question on Slack and have the bot replying. For that there's a Channel integration available via Azure Bot. However the answer is provided not on the same corresponding message Thread, but as a new message published on the same Channel used for the integration, where the question has been asked.If this is possible, may you kindly suggest how to edit the code, in order to get the answer on the same "question thread", rather than having a new message popping up in the channel?

Thank you in advance for your help :)

All details provided above, I'm actually not finding a proper solution for this

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
871 questions
Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
432 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.