简体   繁体   中英

How to make the bot initiate 1:1 conversation in a group with the user in Slack using Microsoft bot-framework?

I am using Microsoft bot-framework for Nodejs. I want my bot to start a private conversation within a group with a user. Currently, my bot carries on the conversation with any member responding. For example,

Me: Hi @bot

Bot: Hi

Me: I need to order a pizza

Bot: What would you like on your pizza?

SomeTeamMember: Mushrooms and Onions

Bot: Ordering Pizza with Mushrooms and Onions.

As you can see, the conversation was hijacked by some other member, this is the issue I am facing, I want to avoid this from happening. I want the bot to only communicate with one member at a time and when the conversation ends with that user, it is open to communicate with anyone in the same manner as previous user. Any suggestion would be great!

You are using slack? Anyway, when you reach "Bot: What would you like on your pizza?", you should be in a completely new dialog where you can use each conversation member Id and store it to data bag (context.ConversationData) in order to have context.

When "SomeTeamMember" joins the conversation, you can check his or hers conversation member id to get the state for each member, and act accordingly.

Hope this helps :)

Alex

I think you could use the session object and access the message sender id ie session.message.user.id . And maybe filter out messages coming from other users other than the one that said I need to order a pizza .

Also from the documentation I think you could use something like dialog triggered by an action , activated right after I need to order a pizza . You could then check the user's id, and reroute to dialogs where the other users will be filtered out, except for the sender of I need to order a pizza ...

If you try something like, or complexify:

bot.dialog('pizzarouting', function (session, args, next) {

})
// Once triggered, will start a new dialog as specified by
// the 'onSelectAction' option.
.triggerAction({
    matches: /^Pizza$/i,
    onSelectAction: (session, args, next) => {
        // Add the help dialog to the top of the dialog stack 
        // (override the default behavior of replacing the stack)
        session.send('What would you like on your pizza?')
        console.log(session.message);
        // Reroute to dialog that filter out the other people id
        // session.beginDialog(args.action, args);
    }
});

This gets activated only if a user sends 'Pizza' in chat. You'll see that the session object holds the message object, which you could use for example to identify the user who sent I need to order a pizza and get his id for subsequent filtering. I hope you or anyone who gets around this gets interesting ideas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM