How do I include in the MS Teams "Post a Message" action to use an @mention to tag/target an individual?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 02:00 AM
Hi
I successfully created a flow in Flow Designer to trigger when an incident's Next Action date/time is overdue and send a message using the MS Team's Post a Message action to an MS Teams Channel.
What I cannot do is include a "mention" to tag/target the "Assigned to" of the incident in the message.
Has anyone had any success? Does it get done via an inline script? - if so can someone share the code please?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 06:49 AM
Hi mkegruber,
I am also working on pretty much the same thing! Unfortunately, I'm having the same problem as you. I'm sure you've done some digging yourself, but here's some info that I have gathered over the last day on this:
It seems that if you are using the "Microsoft Teams" spoke (screenshot below) you cannot specify a GroupID or Channel ID which are needed for mentioning in a teams channel:
You would instead need to use the "Microsoft Teams Graph" here:
Conceptually, I believe it is similar to this post which does mentions in PowerAutomate. However, since I cannot webhook into this, I need to actually build a connection for the Microsoft Teams Graph to function. Thus, I am at the will of another team internally. I'll keep you posted if I make any progress. Good luck!
-Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2022 07:27 PM
Matt,
I'll look into this, I'll have to see whether my company has this interface.
Plan B at the moment is using a Power Automate flow to detect a unique keyword I insert into the ServiceNow message and extract all the key info i.e. case#, case owner etc and post a 2nd MS Teams message with an "@mention" tag. It's not the prettiest workaround as it will generate double messages in the channel.
regards
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2022 09:49 PM
Hi,
I haven't explored the MS Teams Graph action yet (waiting for my company to activate it). So my solution was to create a Power Automate flow to detect a keyword included in the message sent from ServiceNow, extract all the key info from the message and issue a reply with an "@mention" using the "Assign to" email address.
This is my first Power Automate flow, so its not pretty. I think "Compose 2" and "Compose 3" are not required. If there are any suggestions on how to eliminate the need for 2x "Parse JSON" steps I am all ears. If there is a way to bypass the JSON steps altogether, even better.
I hope my experience, can help someone else.
I'm not sure how to express the details of a flow, but I hope you can see what I did below...
Power Automate – Trigger
When keywords are mentioned
Message type: Channel
Keywords to search for: “[my keyword]”
Team: [my channel]
Channel – 1: General
Power Automate – Actions
Initialize variable – msg email
Name: msg_email
Type: String
Value: [empty]
Initialize variable – msg caseNumber
Name: msg_caseNumber
Type: String
Value: [empty]
Initialize variable – msg nextAction
Name: msg_nextAction
Type: String
Value: [empty]
Apply to each
Select an output from previous steps: Value = triggerOutputs()?[‘body/value’]
Get message details
Message: Message ID = items(‘Apply_to_each’)?[messageId’]
Message type: Channel
Team: Team ID = items(‘Apply_to_each’)?[‘teamId’]
Channel: Channel ID = items(‘Apply_to_each’)?[‘channelId’]
Parent message ID = [empty]
Parse JSON
Content: Body = body(‘Get_message_details’)
Schema: [I took the output of the message and generated a schema]
{
"type": "object",
"properties": {
"@@odata.context": {
"type": "string"
},
"id": {
"type": "string"
},
"replyToId": {},
"etag": {
"type": "string"
},
"messageType": {
"type": "string"
},
"createdDateTime": {
"type": "string"
},
"lastModifiedDateTime": {
"type": "string"
},
"lastEditedDateTime": {},
"deletedDateTime": {},
"subject": {},
"summary": {
"type": "string"
},
"chatId": {},
"importance": {
"type": "string"
},
"locale": {
"type": "string"
},
"webUrl": {
"type": "string"
},
"policyViolation": {},
"eventDetail": {},
"from": {
"type": "object",
"properties": {
"device": {},
"user": {},
"application": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"displayName": {
"type": "string"
},
"applicationIdentityType": {
"type": "string"
}
}
}
}
},
"body": {
"type": "object",
"properties": {
"contentType": {
"type": "string"
},
"content": {
"type": "string"
},
"plainTextContent": {
"type": "string"
}
}
},
"channelIdentity": {
"type": "object",
"properties": {
"teamId": {
"type": "string"
},
"channelId": {
"type": "string"
}
}
},
"attachments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"contentType": {
"type": "string"
},
"contentUrl": {},
"content": {
"type": "string"
},
"name": {},
"thumbnailUrl": {}
},
"required": [
"id",
"contentType",
"contentUrl",
"content",
"name",
"thumbnailUrl"
]
}
},
"mentions": {
"type": "array"
},
"reactions": {
"type": "array"
},
"messageLink": {
"type": "string"
},
"threadType": {
"type": "string"
},
"teamId": {
"type": "string"
},
"channelId": {
"type": "string"
}
}
}
Apply to each 3
Select an output from previous steps: attachments = body(‘Parse_JSON’)?[‘attachments’]
Compose 2
Inputs: content x = items(‘Apply_to_each_3’)?[‘content’]
Parse JSON 2
Content: Outputs x = outputs(‘Compose_2’)
Schema: [I took the output of the attachment item and generated a schema]
{
"type": "object",
"properties": {
"summary": {
"type": "string"
},
"title": {
"type": "string"
},
"themeColor": {
"type": "string"
},
"sections": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string"
},
"title": {
"type": "string"
},
"activityTitle": {
"type": "string"
},
"activitySubtitle": {
"type": "string"
},
"activityText": {
"type": "string"
},
"markdown": {
"type": "boolean"
},
"startGroup": {
"type": "boolean"
}
},
"required": [
"markdown",
"startGroup"
]
}
},
"potentialAction": {
"type": "array"
}
}
}
Compose 3
Inputs: bodu(…) x = body(‘Parse_JSON_2’)[‘sections’][0][‘text’]
Note: after Compose 3 there are 3 parallel branches to create 3 variables which then converge back at Get an @mention token for a user.
1. Branch for variable msg_email
Find text position “(“
Text: Outputs x = outputs(‘Compose_3’)
Search Text: (
Substring email
Text: Outputs x = outputs(‘Compose_3’)
Starting Position: add(…) x = add(int(outputs('Find_text_position_"("')?['body']),1)
Length: sub(…) x = sub(sub(int(outputs('Find_text_position_")"')?['body']),int(outputs('Find_text_position_"("')?['body'])),1)
Set variable msg email
Name: msg_email
Value: Body x = body(‘Substring_email’)
2. Branch for variable msg_caseNumber
Find text position “[case prefix]“
Text: Outputs x = outputs(‘Compose_3’)
Search Text: [case prefix]
Substring caseNumber
Text: Outputs x = outputs(‘Compose_3’)
Starting Position: Body x = body(‘Find_text_position_”[case prefix]”’)
Length: 11
Set variable msg caseNumber
Name: msg_caseNumber
Value: Body x = body(‘Substring_caseNumber’)
3. Branch for variable msg_nextAction
Find text position “colour:blue“
Text: Outputs x = outputs(‘Compose_3’)
Search Text: color:blue
Substring nextAction+end tag
Text: Outputs x = outputs(‘Compose_3’)
Starting Position: add(…) x = add(12,int(outputs('Find_text_position_"color:blue"')?['body']))
Length: [empty]
Substring nextAction
Text: Body x = body(‘Substring_nextAction+end_tag’)
Starting Position: 0
Length: sub(…) x = sub(length(outputs('Substring_nextAction+end_tag')?['body']),7)
Set variable msg nextAction
Name: msg_nextAction
Value: Body = body(‘Substring_nextAction’)
Get an @mention token for a user
User: variables(‘msg_email’)
Reply with a message in a channel
Post as: Flow bot
Post in: Channel
Message ID: outputs(‘Get_message_deatils’)?[‘body/id’]
Channel: Channel ID = outputs(‘Get_message_details’)?[‘body/channelId’]
Message:
<p>@{outputs('Get_an_@mention_token_for_a_user')?['body/atMention']} Case @{variables('msg_caseNumber')} has an <span style="color: red"><strong>overdue Next Action</strong></span>. The stated action was:.<br>
<br>
<span style="color: blue"></span><span style="color: blue">@{variables('msg_nextAction')}</span><span style="color: blue"></span></p>
Regards
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2022 11:33 PM
Hi,
I got the Microsoft Teams Graph spoke activated in my company's DEV environment recently (after successfully using the MS Teams spoke).
I understand where to source Group/Team IDs and Channel IDs, etc, but I'm stumped on where a get a data pill that is compatible with the Mentions field (see image below).
I was sure a "For Each Items > Look Up Records > Case Records > Assigned To > Email" would do the trick, but no. I'm missing something here, and I can't find it via Google.
If someone has successfully used this action, please detail what you did to issue a mention inside the message.
regards
Michael