How to add a mention in Teams alongside an adaptive card using Bot Framework

后端 未结 2 529
猫巷女王i
猫巷女王i 2021-01-26 03:05

I\'m trying to send an activity with an adaptive card attachment and include a mention to the user who created the post. From reading online I found you can\'t currently include

2条回答
  •  梦毁少年i
    2021-01-26 03:32

    Have you thought about (a) sending the adaptive card and (b) sending a "Reply" message to the original Adaptive Card you sent? I haven't done this before, but I'm guessing the id that comes back from turnContext.SendActivityAsync (on the ResourceResponse instance) is the id you can use to "reply" to the message you just created.

    Update: I got it working. This is -very- rough code but hopefully enough that you can figure out/adjust to your scenario:

     var result = connector.Conversations.SendToConversationAsync([your conversation id], activity).Result;
    
    // I'm re-using the same activity just as a test, you can do whatever (e.g. create a new one)
    activity.Text = "Msg 2";
    var conversationReference = activity.GetReplyConversationReference(result);
    conversationReference.Conversation.Id = conversationReference.Conversation.Id + ";messageid=" + result.Id;
    activity.ApplyConversationReference(conversationReference);
    
    connector.Conversations.SendToConversationAsync(conversationReference.Conversation.Id, activity);
    

    So note, really important, you need to change your conversation id to add ";messageid=" to the end, and ADD the reference the message you just posted.

    Here's a screenshot:

    Hope that helps, and thanks for this - gave me a chance to learn something useful!

提交回复
热议问题