0

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 mentions in adaptive cards. Is there a way to mention someone when sending the activity, for example in another attachment?. I have tried setting the activity.Text = mention, this works however it creates two posts, the first with the mention and then another post with the adaptive card as a separate message. I feel there must be a way to do this, else if you created a post and someone responded to you, you'd never know automatically on reply. Also note I'm not using Flow. Code Teams Post

AlexCurtis
  • 39
  • 1
  • 7

2 Answers2

1

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: Msg Reply

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

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • 2
    I'm just realising I've sent you several answers the last few weeks, but none seems to have been "Accepted". Was it something I said?? – Hilton Giesenow Jan 31 '20 at 11:45
  • Sorry, I'm fairly new to posting! I was pressing the up button, but don't have the reputation yet, didn't see the Tick represented the accepted answer, apologies! Will go back today and mark them(sorry again). They have all helped me progress further. Good idea, will try your suggestion now. – AlexCurtis Jan 31 '20 at 11:50
  • no worries, was only kidding and glad to help. Let me know how this goes, would love to know if it works. – Hilton Giesenow Jan 31 '20 at 11:52
  • fyi on this - "upvote" is useful to future viewers to help indicate the answer was helpful, but "accept" indicates that it's correct, so people will know you've accepted it as such, and it can help them with the same/a similar problem – Hilton Giesenow Jan 31 '20 at 11:56
  • I'm just reading your original question again and wondering - maybe the adaptive card *itself* should be a reply to the original message... – Hilton Giesenow Jan 31 '20 at 12:11
  • Replying to original message is a good, workable idea however can't get a reply to work. Can update the activity fine but not reply to it. I've tried storing the activity id, conversation, and service url. But still creates a separate post. – AlexCurtis Jan 31 '20 at 15:35
  • What does your conversation id look like? Does it include the message Id? Also, what code exactly are you using to send the message? turnContext.SendActivityAsync? – Hilton Giesenow Feb 01 '20 at 16:30
  • I'll debug it to find the first two answers out. Here is the code for the method [link](https://pastebin.com/gqD2E8tT) as you can see i'm trying to get the activity id from first message set that to the second, and apply conversationreference to the second message. Thought a ConversationReference would work but guess not. Still sends as two separate messages, the adaptive card then the mention in separate post. – AlexCurtis Feb 01 '20 at 16:49
  • Out of interest, is this in a 1-1, or inside a team (channel)? – Hilton Giesenow Feb 01 '20 at 17:46
  • This is a teams channel, at work we have an Escalation Channel for issues. – AlexCurtis Feb 01 '20 at 18:00
  • that's strange then - in my testing, a normal adaptive card response, in a Teams channel, will automatically be a "reply" to the original message. I'm checking your original screenshot though, and that's 1-1...? – Hilton Giesenow Feb 01 '20 at 18:28
  • The original was on a Teams Channel, not sure if this changes things but as i'm testing on my own personal Teams, i'm currently the only one in the channel. Thought i'd test on here and not our Company's Team. Here is an attached image to better show the channel setup. [TeamsBot](https://i.imgur.com/q37WOuJ.png) – AlexCurtis Feb 01 '20 at 18:42
  • ok thanks for clarifying. Who starts the conversation though? These are all looking like bot-initiated right now (i.e. Pro-active messages). Is that the correct scenario? – Hilton Giesenow Feb 01 '20 at 18:53
  • So the user clicks the Robot Icon(message extension) at the bottom, this brings up a form for them to fill in, when they press send the post is put into the teams channel as the bot sent it.Ideally I'd like it as the User sent it but not sure how to do that? Since the bot posts the message, if lets say you reply to said post, The user who created it currently won't get notified, as i think the bot posted it. If that makes sense. Therefore if I can't get the form post to be the user posting it, if I can mention them immediately as a response, when someone responds they'd be notified. – AlexCurtis Feb 01 '20 at 19:01
  • ahhhhh ok, now I see - I remember now some of your other questions this week about the message extension. So, have you thought about another design altogether? Having a 1-1 bot that the user interacts with? the user could say, for instance, "log issue" in that chat, get an adaptive card to complete, etc. When they're done, then the bot posts a pro-active message into the actual Escalation channel, including @mention and anything else. – Hilton Giesenow Feb 01 '20 at 19:11
  • I've redesigned it once from a conversational bot to instead use a message extension. I'm reluctant somewhat to redo it again in another form since it's almost there. With your suggestion wouldn't the outcome be the same, that still it's a bot sending the message, the attachment is still the same(adaptive card). Only thing that has changed is it going from a 1-1 conversation to posting in another channel?My plan is to get this working with a mention release this, then later on the year refactor it potentially in a better format. – AlexCurtis Feb 01 '20 at 20:32
1

Currently Adaptive Card @mention is in developer preview but you can achieve the @Mention in adaptive card with Adaptive card 1.2 version.

You can @Mention a user in adaptive card using following JSON

{

  "type": "AdaptiveCard",

  "body": [

    {

      "type": "TextBlock",

      "size": "Medium",

      "weight": "Bolder",

      "text": "Hi <at>Mention_Name</at> This is new feature in Adaptive Card version 1.2 Please test..."

    }

  ],

  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",

  "version": "1.0",

  "channelId": {

    "entities": [

      {

        "type": "mention",

        "text": "<at>Name</at>",

        "mentioned": {

          "id": "29:124124124124",

          "name": "Mungo"

        }

      }

    ]

  }

} 

You need to specify channelID, and mentioned ID which you can fetch from the activity object itself

Fetch Channel Id and Mentioned Id from Activity Object

Trinetra-MSFT
  • 957
  • 5
  • 9
  • Unable to get this to work, here's what i'm doing [Adaptive Card](https://i.imgur.com/9yzujdg.png). Trying with this code, [code](https://i.imgur.com/GLCV6il.png) Currently in the card it's just outputting Alex Curtis with no mention. – AlexCurtis Feb 04 '20 at 06:56
  • To @Mention a user you need to provide channelId and the user id which you can get from the activity object itself. This feature is in developer preview currently but yes you can try to send a json too with adaptive card version 1.2. Hope this helps. – Trinetra-MSFT Feb 04 '20 at 07:41
  • I've put the User Id in and channelId in haven't had any luck. When debugging my ChannelId seem to be "msteams", which i hardcoded before sending the message and i got my user id from, turncontext.activity.from and set this in the mention id in json(used your json provided). Haven't been successful. Could this be because you appear to be using dialogs? Whereas I've added the TeamsMessagingExtensionsActionPreviewBot so when a user fills in a form and presses submit the adaptive card is posted straight to the channel. Is it possible if you could show me more code around yours please? – AlexCurtis Feb 04 '20 at 20:29