cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
burgett94
Resolver II
Resolver II

Collecting Reactions from Teams Messages

Hello!

 

I am not sure if anyone has done this but we are looking to run a flow every day to retrieve the reactions from messages posted 14 days ago. We have allowed the post to be live for 14 days to ensure we allow users time to read and react to a post.

 

From previous flows I can filter the "Get messages" action to only show messages posted 14 days ago however, I am stuck trying to get total the "Message reactions" to show something like the below in a SharePoint list:

 

Message IDlikeheartlaughsurprisedsadangry
486565156156551100
516168464644250300
618468464868160200

 

I believe I need to group the reactions by the "reactionType" then total the amount? Or potentially filter each message to just show where 'like' was used then do a length() to get the number of items and repeat that step for the other 5 reactions.

 

Unsure of the best way to do it so looking for guidance on how best to set this up 🙂

Best regards,

Bradley
If this post helps, then please consider Accept it as the solution to help the other members find it more
1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

This would be my approach, at first I thought it would be quite complex, but you can get it done quite easily:

https://ibb.co/dcsgq3q

TeamsReactions.jpg

Explanation:

  1. Get messages
  2. Go into an apply each loop for each message.
  3. The reactions array associated with each message is filtered to match every type of reaction.
  4. A compose action outputs the message ID along with the length of each reaction array (the count of each reaction type).
  5. The final array of results is produced outside of the apply-each loop.

Results look like this:

[
  {
    "messageID": "1612948631606",
    "like": "4",
    "heart": "0",
    "laugh": "0",
    "surprised": "2",
    "sad": "0",
    "angry": "1"
  },
  {
    "messageID": "1612948620934",
    "like": "0",
    "heart": "0",
    "laugh": "2",
    "surprised": "1",
    "sad": "0",
    "angry": "0"
  },
  {
    "messageID": "1612948608713",
    "like": "6",
    "heart": "4",
    "laugh": "0",
    "surprised": "0",
    "sad": "0",
    "angry": "0"
  }
]

What is nice about this solution is that because no variables are being used. You can change the concurrency control on the apply-each loop to make it run much faster. 

 

The code in the messageReaction compose action is:

{
  "messageID": "@{items('Apply_to_each')?['id']}",
  "like": "@{length(body('filterLike'))}",
  "heart": "@{length(body('filterHeart'))}",
  "laugh": "@{length(body('filterLaugh'))}",
  "surprised": "@{length(body('filterSurprised'))}",
  "sad": "@{length(body('filterSad'))}",
  "angry": "@{length(body('filterAngry'))}"
}

 

I've exported the flow and uploaded to my blog so you can download and change to your requirement.

https://www.tachytelic.net/wp-content/uploads/TeamsReactions_20210210094805.zip

Hopefully the output should make it easy for you to load directly into your SharePoint list.

 

View solution in original post

2 REPLIES 2
tom_riha
Super User
Super User

Hello @burgett94 ,

I'd do it probably the brute force way. 🙂

Initialize 6 integer variables for each of the reactions and set them to 0, then loop through the messages and for each message loop through the reactions.

Inside the reactions loop, a Switch based on the reactionType that would increment the corresponding variable, e.g. reactionType = like -> increment variable with likes.

At the end of the reactions loop each variable will contain a number that you can update in the SharePoint list for the message ID. Then set the variables back to 0, and repeat with the next message.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
Paulie78
Super User
Super User

This would be my approach, at first I thought it would be quite complex, but you can get it done quite easily:

https://ibb.co/dcsgq3q

TeamsReactions.jpg

Explanation:

  1. Get messages
  2. Go into an apply each loop for each message.
  3. The reactions array associated with each message is filtered to match every type of reaction.
  4. A compose action outputs the message ID along with the length of each reaction array (the count of each reaction type).
  5. The final array of results is produced outside of the apply-each loop.

Results look like this:

[
  {
    "messageID": "1612948631606",
    "like": "4",
    "heart": "0",
    "laugh": "0",
    "surprised": "2",
    "sad": "0",
    "angry": "1"
  },
  {
    "messageID": "1612948620934",
    "like": "0",
    "heart": "0",
    "laugh": "2",
    "surprised": "1",
    "sad": "0",
    "angry": "0"
  },
  {
    "messageID": "1612948608713",
    "like": "6",
    "heart": "4",
    "laugh": "0",
    "surprised": "0",
    "sad": "0",
    "angry": "0"
  }
]

What is nice about this solution is that because no variables are being used. You can change the concurrency control on the apply-each loop to make it run much faster. 

 

The code in the messageReaction compose action is:

{
  "messageID": "@{items('Apply_to_each')?['id']}",
  "like": "@{length(body('filterLike'))}",
  "heart": "@{length(body('filterHeart'))}",
  "laugh": "@{length(body('filterLaugh'))}",
  "surprised": "@{length(body('filterSurprised'))}",
  "sad": "@{length(body('filterSad'))}",
  "angry": "@{length(body('filterAngry'))}"
}

 

I've exported the flow and uploaded to my blog so you can download and change to your requirement.

https://www.tachytelic.net/wp-content/uploads/TeamsReactions_20210210094805.zip

Hopefully the output should make it easy for you to load directly into your SharePoint list.

 

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,458)