Monday
How to integrate Microsoft teams with Blue prism and send message to teams via blue prism
Monday
Hello @Bhavithra you can use Graph API connector of teams. below is the DX asset links.
https://digitalexchange.blueprism.com/cardDetails?id=113965
Tuesday
Hi Bhavirthra
If you want a fuller integration and have other actions you want to do with Teams the Graph integration suggested is the way to go. However not sure if you know, if you just want Blue Prism to post a message in the teams Channel chat - it is simple to do by email. Each teams channel has it's own email address and you just send to that like a normal email - however you do that with Blue Prism. Just look in the 3 dots alongside the channel you want to post in.
Kirk
Tuesday
In a previous role I utilised webhooks to allow channels to receive messages via an external source, i.e. Blue Prism
Reading up now it seems its to near deprecation and replaced with workflow/power automate going forward.
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet
an hour ago - last edited 57m ago
@Bhavithra What the others have mentioned is also worth considering especially Graph API though that will not be a quick setup most likely, but I would suggest first trying what @ChrisRPA suggested which is to use Workflows inside of Teams with the trigger 'When a Teams webhook request is received' which is created when you use the template 'Send webhook alerts to a channel'. It creates a Power Automate flow. It is actually pretty easy to do. As Chris said, it has changed a bit so that the instructions he linked to will only work for another couple of months, but it is still almost just as easy as it was before.
I use this method to send literally thousands of messages into Teams channels each day, though there are rate limits so eventually it does fail, but you gotta send a lot of messages for that to happen. I'll describe the method I used below, though I'm sure you could determine your own design instead.
Here are Microsoft's steps for what I'm going to show below in case you'd rather look at their instructions, though their screenshots and wording of some stuff looks slightly outdated but almost right. Create incoming webhooks with Workflows for Microsoft Teams - Microsoft Support
1. Pick a channel (not a group chat) within a Team, and right click on the Channel and go to 'Workflows'.
2. Go to 'Send webhook alerts to a channel'. Should already be in the list without searching but you could search for it instead if it doesn't show up by default in the future.
3. Give the workflow a good, clear name. I like to include the environment it is associated with, such as dev, uat, prod, etc. I also like to include the phrase 'by Webhook URL' at the end so I know based on the name of it what the trigger is. The reason this is helpful is that this will show up in your Power Automate flows when you look at cloud flows too so it could get rather confusing if you don't have a specific name.
4. Next check on and handle the connection in the same window as above. If it has a green checkmark, then you're good to go. If it doesn't, then you may need to do more to fix it. First try clicking whatever looks clickable. Microsoft changes this kind of thing now and then so in the future it may look different. One of the things is the three dots on the right. I don't have a good screenshot right now if what that looks like when it's not handled already.
Here's what it'll look like when clicking the three dots and the connection is resolved correctly. This screenshot is sanitized, but it shows my work email address, so it is actually going to be authenticated as me. You can also use a Service Account, but that takes more effort and isn't really worth it when you first are trying this out so I'd figure that part out later or never worry about it at all.
If you can't seem to resolve the connection in that screen, what you may need to do is go into Power Automate in the browser at https://make.powerautomate.com and go to Connections.
At this point in Connections, you should see a connection where the Status is something other than 'Connected'. Fix any that aren't working. Specifically we're looking for the one labeled Microsoft Teams of course. It should be as simple as clicking on whatever looks like they want you to click on it and then sign in which may require entering your password.
If for some reason you don't see a connection that needs fixing and Teams indicated there was something wrong with your connection when creating the flow, then you may be in the wrong Power Automate environment. Look at the top right of the webpage and click 'Environments' and look through each Environment you have access to in case the environment it brought you to isn't the general/default environment that Teams is connected to.
By now, I'll assume the connection has been resolved in Teams. Go back to check on it and verify it looks right and click 'Next'.
5. Now you have the opportunity (apparently) to change the Team and/or Channel that will be posted to. If you started by right clicking on the right Channel, then there's no need to change anything here. Click 'Add workflow'.
6. On the last screen, you're given the Webhook URL that you'll call/post to from in Blue Prism or wherever. Copy the URL out and save that in an Environment Variable that you'll use in an automation. Definitely do not hard code this in an automation. The URL can and will change whenever Microsoft decides to change it. For example, literally TODAY two of mine changed, but the way Microsoft does it is to make the new and old URL both active for a period of a couple of months. So, it's nothing to worry about. Once you've saved that URL somewhere, you can click 'Done'.
7. If/when the URL changes in the future, I wanted to show where you go to the get the URL again in order to update your Blue Prism environment variable etc.
I just noticed you can use the Workflows addon in Teams. I don't know if it's there for everyone, but looks to be an option. If you have it, you'll see it on the left side of Teams in the same list where you see 'Activity', 'Chat', and 'Calendar. Click Workflows. If you don't have this or it is running too slow (classic Microsoft), then you can do the same steps by going to https://make.powerautomate.com and going to 'My Flows' and then 'Cloud Flows'.
If you click 'Workflows', you should then see the flow listed. Click the flow name (it's a link).
Click 'Edit'.
Then you can copy the URL out of the HTTP POST URL blank, and this should always give you the most recent/up-to-date URL even if there is technically still an old URL that still works for the same workflow.
Just to point out, it looks a little different in the browser, and you have to click the card/connector 'When Teams webhook request is received' in order to see a slide out properties pane on the left where you can copy the URL out of 'HTTP URL'.
I'm not going to explain the full details of everything I've done with this as I think that would be overkill, and I think I'm already going excessive here. I also can't directly shared the object I created for multiple reasons, but I believe there's no problem showing the design of the base object so you can create something like it.
I named the object 'DLLib - MS Teams', which stands for Digital Labor Library - MS Teams, and the action is named 'Post Basic Message to Channel'.
Here's the basic action I created, with plans to create more complicated actions in the future if we need it.
The action appears to not work if the machine is not logged in. I don't know why that is since it's just calling an API. But because of that, I have a check to see if the currently-logged-in user is SYSTEM or not. If it's SYSTEM, we're not logged in. The GetUserName code stage is just doing this:
username = Environment.UserName;
The Escape Message Text step is calling an action that does this to the text that is being posted. You'll need the external reference Newtonsoft.Json.dll and the import Newtonsoft.Json at least. If this doesn't work for you, just look up any way of escaping a string for things like backspace, form feed, newline, carriage return, tab, double quote, and backslash. A better solution to this would be to use a C# class to convert from or even use a Blue Prism collection that you nest the adaptive card fields in and then convert to JSON. Apologies if this doesn't sound like much help, but I'm thinking this helps get most people further than they would be without this help at least.
result = JsonConvert.ToString(stringToEscape).Trim((char)34);
The Get JSON For Post To Webhook code stage has this hardcoded in it and outputting it as Text into the data item [JSON]:
adaptiveCardJson = @"{
""type"": ""message"",
""attachments"": [
{
""contentType"": ""application/vnd.microsoft.card.adaptive"",
""content"": {
""type"": ""AdaptiveCard"",
""body"": [
{
""type"": ""TextBlock"",
""text"": ""<MessageText>"",
""wrap"": ""true""
}
],
""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"",
""version"": ""1.0""
}
}
]
}";
Then I'm just checking to see if the message is longer than 20k characters as this is close-ish to the message length limitation at the time that I made this action.
Then I am replacing <MessageText> with the actual message text like this with a Blue Prism expression:
Replace([JSON],"<MessageText>",[Message Text])
Then I am calling the Utility - HTTP object action 'Post JSON'. I don't remember how old this action is, but it is in the latest version of that object at least. I may have edited it, but I can't remember. The only inputs needed for this as the webhook URL and the json.
Then I'm just checking whether the Status Code response starts with a "2" indicating success. I have it recovering any exception and just writing to the session log if it fails, and then it outputs Success true/false so the calling process can decide whether an exception needs to be thrown or not.
429 status code -- this is throttling / rate limits. I have not yet determined what limits I am hitting, but every few days I get an email saying this happened. In our case, some messages failing is not a big deal, but you'd want to handle this differently if you have the issue for something important.
Rate limits -- still related to the 429 but a little different perspective. The rate limits are supposedly per person. Maybe that is different depending on the Microsoft plan that you have. But for us, we found we needed to have different people own different flows so we could maximize the number of messages that could be posted. I THINK it is rate limits for who is in the connection authentication and not actually the flow owner though. But anyway this is something I haven't fuly learned yet.
I've toyed around with doing more than simple messages. Here is an example that I tested in the past that contains an @ mention, but we don't currently use this.
//This is just an example of something we could implement. Below is what would go in the Get JSON For Post to Webhook code stage as a hardcoded message format that contains an @mention. In addition to this, the Message Text itself should contain '<at>Some Name</at>' or whatever value is used.
adaptiveCardJson = @"{
""type"": ""message"",
""attachments"": [
{
""contentType"": ""application/vnd.microsoft.card.adaptive"",
""content"": {
""type"": ""AdaptiveCard"",
""body"": [
{
""type"": ""TextBlock"",
""text"": ""<MessageText>"",
""wrap"": ""true""
}
],
""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"",
""version"": ""1.0"",
""msteams"": {
""entities"": [
{
""type"": ""mention"",
""text"": ""<at>Some Name</at>"",
""mentioned"": {
""id"": ""username@companyname.com"",
""name"": ""Some Name""
}
}
]
}
}
}
]
}";
In that text above the <MessageText> is where you'd replace to insert the text.
Hopefully this helps someone now or in the future!