Cat
Cat

Reputation: 73

Microsoft Bot Framework dialog with multiple users

I am using the Microsoft Bot Framework for .NET to create a simple question/answer bot, as an ASP.NET MVC WebApi, written in C#, that will be used primarily on Slack channels with multiple users.

I have created a dialog which I initiate from my message controller as per the framework documentation:

await Conversation.SendAsync(activity, () => new QuestionDialog());

The lambda expression indicates to the Bot Framework which constructor to use for a dialog. QuestionDialog implements IDialog. After a dialog is initiated the dialog class is serialized and stored in the Bot Connector cloud, saving the current question and expected answer, then deserialized whenever a new message is received in the current conversation.

I want any user to be able to answer a random question presented by the Bot regardless of which user initiated the dialog but it seems that a new QuestionDialog is created for each user interacting with the bot so only the user initiating the question can answer it.

Is there any way of creating a dialog that is tied to the conversation/channel only rather than the combination of conversation/channel and user? Does it even make sense to attempt using a dialog in this way?

Upvotes: 1

Views: 925

Answers (1)

Tomi Paananen
Tomi Paananen

Reputation: 86

I guess the way I would implement this is to:

  1. Store the state (the latest question) for each of the channels separately. For example, create a serializable class "QuestionState" which has at least the following properties: Service URL, conversation account ID and the question itself.
  2. For each incoming activity (message), check the service URL and the conversation account ID of the sender and compare that against your list of states. If you find a match, evaluate the message (answer) in respect to the latest question. If there are no matches, this is a channel without previous state, so you need to create one and ask the first question.

Azure Table storage is a handy service to store the states in. You can, of course, use any service you like. Just keep in mind that in-memory state storage only works for testing.

In addition, you don't have necessarily have to use dialogs for this solution at all - you can do all you need to do in the MessagesController.

Upvotes: 0

Related Questions