NIYATI ACHARYA
NIYATI ACHARYA

Reputation: 73

How to send message to another user via bot and come back to original conversation with first user without losing the context?

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:

  1. User places a request to the bot.
  2. Bot informs user's manager to either approve or reject the request
  3. 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

Upvotes: 1

Views: 950

Answers (3)

ashish
ashish

Reputation: 878

You could keep a context stack for each user, pushing an item on top of the stack for each message sent by the bot and matching context in FIFO order for each message recieved. Now this context stack goes into a map identified by the userId/userKey.

Bot-context is a library which does exactly this. The related blog post.

Upvotes: 0

OmG
OmG

Reputation: 18838

After sending the message to a second user using the following code and storing in the inbox of the first user, you can send the stored result, again using the above code, to the first user and follow their conversations.

string recipientId ="123456789"; // For Example
string serviceUrl = "https://telegram.botframework.com"; // For Example

var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, recipientId);
newMessage.Recipient = new ChannelAccount(recipientId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);

The code comes from here.

Upvotes: 1

pl0x
pl0x

Reputation: 131

check this page, specifically the start conversation section.

Upvotes: 0

Related Questions