cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tono_Analyst2
Helper I
Helper I

Trigger when a yammer post is created with a specific topic tag

I want to automate the process of pulling the information from a new yammer post with a specific tag and creating a news post in  a SharePoint site.


Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @Tono_Analyst2,

 

Thanks for clarifying that you want to use topics instead of tags. I was looking at tags in the parsed body, I forgot about the topic tags 😁. I will update the code snippet in the answer below.

 

Is this looking for the tagged word in the body of the post (['body/body/parsed']), as opposed to the actual name of the tag?

Yes, that is correct. I was looking for a tag in the parsed body. But we can also use the topics field from the post outputs instead.

 

What does the -1 at the end mean?

I am using a indexOf function. This function searches for a string. If it can't find the string it will output -1. So, if it doesn't equal -1 you have found your tag.


How can I adjust the code when the topic (tag) name appears to be nested as below, essentially I want to only trigger when the topic name is digital. (Note: that there can be more than one topic)

The topics field is collection where the label is stored in the name field. So, you would have to use an index to refer to the name field of the correct item. However, you don't know in which item the topic is stored.

 

A workaround could be to convert the topics field to a string and just look for the word Digital.

 

@not(equals(indexOf(string(triggerOutputs()?['body/topics']), 'Digital'), -1))

 

 

What are all of the fields listed here and which should be changed?

In this example I am only setting the title of the News Post. You only would need to change that field.

 

The rest of the fields are there to make sure the object is created as a draft news post. You could use the same URI/endpoint to make regular pages. That's why we need these additional settings.

 

Is it possible to extract and post the image from the yammer post within the news post?

It is possible, but probably a bit more challenging. Especially when the image in the Yammer post is embedded. What kind of image are we talking about. Hosted in Yammer, SharePoint or just a link from somewhere on the internet?

 

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

8 REPLIES 8
alaabitar
Solution Specialist
Solution Specialist

Hello,

In power automate, you can leverage the trigger when a message is posted in a group like

alaabitar_0-1641898175054.png

Then you can parse the content of the post to see if there is a specific tag and then create an item in the sharepoint list.

 

Best regards,

Alaa

Expiscornovus
Super User
Super User

Hi @Tono_Analyst2,

 

You could use the body/body/parsed field in an expression and check if the new Yammer message contains your specific tag id. You can add that expression to a trigger condition so the flow only triggers when it finds the tag. You could use a Send an HTTP request to SharePoint action to create a draft news post.

 

Below is an example.

Replace the tag id by your specific tag id.

 

@not(equals(indexOf(triggerOutputs()?['body/body/parsed'], '[[tag:5783871489]]'), -1))

 

 

bodybodyparsed.png

 

After that you could use a Send an HTTP request to create a draft news post. 

 

Use the json below for the body. Replace hard coded values by dynamic content fields were needed.

 

 

{"__metadata":{"type":"SP.Publishing.SitePage"},"PageLayoutType":"Article","Title":"Yammer News Post State", "PromotedState":1}

 

 

yammernewspost.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Thank you for the detailed response @Expiscornovus. As a newbie, I have some further questions for the following 2 parts.

1. 

@not(equals(indexOf(triggerOutputs()?['body/body/parsed'], '[[tag:5783871489]]'), -1))
  •  Is this looking for the tagged word in the body of the post (['body/body/parsed']), as opposed to the actual name of the tag?
  • What does the -1 at the end mean?
  • How can I adjust the code when the topic (tag) name appears to be nested as below, essentially I want to only trigger when the topic name is digital. (Note: that there can be more than one topic)
{..."group_created_id":15922850,"topics":[{"id":2036826,"name":"Digital"}]}}

I have attempted the below but not exactly what I am after, as it doesn't specify the 'name' index:

 

@contains(string(triggerOutputs()?['body/topics']),'Digital')

 

2. 

{"__metadata":{"type":"SP.Publishing.SitePage"},"PageLayoutType":"Article","Title":"Yammer News Post State", "PromotedState":1}
  • What are all of the fields listed here and which should be changed?
  • Is it possible to extract and post the image from the yammer post within the news post?

Sorry for the bombardment of questions and thank you in advance. 

Expiscornovus
Super User
Super User

Hi @Tono_Analyst2,

 

Thanks for clarifying that you want to use topics instead of tags. I was looking at tags in the parsed body, I forgot about the topic tags 😁. I will update the code snippet in the answer below.

 

Is this looking for the tagged word in the body of the post (['body/body/parsed']), as opposed to the actual name of the tag?

Yes, that is correct. I was looking for a tag in the parsed body. But we can also use the topics field from the post outputs instead.

 

What does the -1 at the end mean?

I am using a indexOf function. This function searches for a string. If it can't find the string it will output -1. So, if it doesn't equal -1 you have found your tag.


How can I adjust the code when the topic (tag) name appears to be nested as below, essentially I want to only trigger when the topic name is digital. (Note: that there can be more than one topic)

The topics field is collection where the label is stored in the name field. So, you would have to use an index to refer to the name field of the correct item. However, you don't know in which item the topic is stored.

 

A workaround could be to convert the topics field to a string and just look for the word Digital.

 

@not(equals(indexOf(string(triggerOutputs()?['body/topics']), 'Digital'), -1))

 

 

What are all of the fields listed here and which should be changed?

In this example I am only setting the title of the News Post. You only would need to change that field.

 

The rest of the fields are there to make sure the object is created as a draft news post. You could use the same URI/endpoint to make regular pages. That's why we need these additional settings.

 

Is it possible to extract and post the image from the yammer post within the news post?

It is possible, but probably a bit more challenging. Especially when the image in the Yammer post is embedded. What kind of image are we talking about. Hosted in Yammer, SharePoint or just a link from somewhere on the internet?

 

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Thank you so much @Expiscornovus , this has cleared up so much!

 

The rest of the fields are there to make sure the object is created as a draft news post.

When I implemented the flow, I noticed that the news wasn't automatically posted. Is this because of these settings? This is handy as we may want to review before publishing the news, but is it possible to also directly publish rather than saving as a draft?

 

What kind of image are we talking about?

When I copy the image link it starts with - https://www.yammer.com/api/v1/uploaded_files/1219567...

I'm assuming this means it is hosted in yammer? Is it challenging to push an image to the news post or to pull/collect it from the yammer post?

Expiscornovus
Super User
Super User

Hi @Tono_Analyst2,

 

If you want to create a published news post you would some separate actions for that in your flow setup.

 

Publishing could be done via the method below.

 

In the URI we use the ID of the previously created draft news post.

_api/sitepages/pages(@{body('Send_an_HTTP_request_to_SharePoint')['d']['Id']})/Publish

 

second_sendanhttpaction.png

 

Adding content like images can be done via the CheckOut & SavePageAsDraft methods of the SharePoint REST API. However, this is were it is becoming more complicated, because you have to write a lot of json code for the body.

 

Hope this helps a bit?

 

About your image question. Potentially you could re-use the link of the Yammer file. However, it depends if the people who will have access to the news post can also access that same Yammer link. If not, you probably have to recreate the file in a SharePoint location. This can also be done in Power Automate but requires more setup.



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Okay, thank you for your help again.

 

I have tried using BannerImageUrl: "ImgLink" to attach a sample image but have not had any luck. Is there a reason why this would not work?

{"__metadata":{"type":"SP.Publishing.RepostPage"},"PageLayoutType":"Article","Title":"Test on 21st of January","Description" : "Test Body", "PromotedState":1, "BannerImageUrl": "@{variables('ImgURL')}", "IsBannerImageUrlExternal": true, "OriginalSourceUrl": "https://


Sample_Img 

Expiscornovus
Super User
Super User

Hi @Tono_Analyst2,

 

Updating the content of the news post would be done in different Send an HTTP request action. This would be an action between the creation of the page and the publishing of the page.

 

And as far as I am aware you can set the image above the news post by using the imagesource property.


Below is an example.

 

imagesource_banner.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,047)