Forum Discussion

Lakshmi_145's avatar
Lakshmi_145
Iron Contributor
Oct 20, 2023

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 conversation with the user, the agent won't be able to send the email as we are using graph client for email sending and it needs user sign-in. 

So is it possible to create a turn context with user conversation reference and send the sign-in card from team agent context to team user context.

Or is there any other possible ways to send Sign in card from one context to another context.

 

1 Reply

  • Lakshmi_145 - 

    Proactive 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.

    1. 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();
    
    1. When the agent ends the conversation, use the stored conversation reference to create a new turn context. You can do this by using the ContinueConversationAsync method of the BotAdapter class.
    await adapter.ContinueConversationAsync(appId, conversationReference, BotCallback, cancellationToken);
    
    1. In the BotCallback method, send a sign-in card to the user. You can do this by using the SendActivityAsync method 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. 

Resources