Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
azzollinigianluca95 opened this issue Nov 29, 2024 · 0 comments

Comments

@azzollinigianluca95
Copy link

Hello Team, posting the question here, as I've already asked here on StackOverflow, and I got an answer on Microsoft Community, to redirect this to the official bot page, I'd like to ask the same question here.

I have created via Azure my CustomQ&A knowledge base language.
Then I've created a bot automatically (via Azure), and then my end goal would be to have QandA (using the bot) on Slack (using Slack integration as well) but with an answer in the same question thread.

Unfortunately it seems that I can only get QandA on completely unrelated messages at the moment.

The auto-generated bot code is the one here on 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);
    }
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant