Forum Discussion
Lakshmi_145
Oct 20, 2023Iron Contributor
Create a new turn context for teams bot
I am working in a bot framework project. We want to send an email to user's email id once the user has closed the conversation with the Agent in the Teams channel. When the agent disconnects the con...
Prasad_Das-MSFT
Microsoft
Oct 23, 2023Proactive messages are messages that are sent by the bot to start a conversation. You can use this feature to send a sign-in card to the user after the conversation with the agent ends.
- When the conversation between the agent and the user starts, capture the user's conversation reference and store it. You can get the conversation reference from the turn context of the conversation.
var conversationReference = turnContext.Activity.GetConversationReference();
- When the agent ends the conversation, use the stored conversation reference to create a new turn context. You can do this by using the
ContinueConversationAsyncmethod of theBotAdapterclass.
await adapter.ContinueConversationAsync(appId, conversationReference, BotCallback, cancellationToken);
- In the
BotCallbackmethod, send a sign-in card to the user. You can do this by using theSendActivityAsyncmethod of the turn context.
async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken)
{
var signInCard = new SigninCard
{
Text = "Please sign in to continue",
Buttons = new List<CardAction> { new CardAction(ActionTypes.Signin, "Sign In", null, null, null, "https://login.microsoftonline.com") }
};
var message = MessageFactory.Attachment(new Attachment
{
ContentType = HeroCard.ContentType,
Content = signInCard
});
await turnContext.SendActivityAsync(message, cancellationToken);
}
For more information, you can refer to the following documentation:
Thanks,
Prasad Das
------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.