How to send message to another user via bot and come back to original conversation with first user without losing the context?
Hi,
I am trying to build a bot that can address the requests placed by the user. However, the bot needs to ask permission of the user's manager for the same. So this is the flow:
- User places a request to the bot.
- Bot informs user's manager to either approve or reject the request
- Based on the response from manager, bot either address the request or does not and informs the user.
I am able to make a 1:1 conversation between bot and user using the PromptDialog, and perform steps 1 and 3. However, I am not sure how to send message to another user for approval or rejection and continue the earlier conversation with the first user. I am using C# for this bot. Any ideas on how could I do this?
Thanks Niyati
Hi,
You need some datastore where you save a mapping of managers and their users. Then maybe some kind of registration mechanism. Something like:
- manager sends register command with some identifier
- bot saves the channel/serviceUrl and conversation id of the manager in datastore
- user sends a message
- bot saves the channel/serviceUrl and conversation id of the user in datastore
- retreive the correct manager for the user and his conversationId + channel/serviceUrl from datastore
- send a message to the manager:
var connector = new ConnectorClient(new Uri(--managers channel/serviceUrl----), new MicrosoftAppCredentials()); IMessageActivity newMessage = Activity.CreateMessageActivity(); newMessage.Type = ActivityTypes.Message; newMessage.Timestamp = DateTime.Now; newMessage.From = new ChannelAccount(; newMessage.Conversation = new ConversationAccount(false, ---- managers id ---- ); newMessage.Recipient = new ChannelAccount(); newMessage.Text = "Request"; connector.Conversations.SendToConversationAsync((Activity)newMessage);
-manager sends approval or rejection
- retreive the user conversationId + serviceUrl from the datastore
- send to user like above
You'll need to store additional state in the conversation contexts but that should give you a direction
Edit: I dont think there is a possibility to save the context. You may need to pass the context between the different conversations
@RaffaelHold's suggestion seems reasonable. If you want to send a message proactively to a different user, you would have saved their contact information (the fields in ResumptionCookie) from a previous conversations to a store somewhere, so that you can instantiate a ConnectorClient to send them messages.
I'm going to close this issue, but feel free to open a new issue for further discussions.