How to send messages to Microsoft Teams
Hi community,
The aim of this article is to explain how to create messaging between IRIS and Microsoft Teams.
In my company, we wanted to monitor error messages, and we used the Ens.Alert class to redirect those error messages through a Business Operation that sent an email.
The problem was that we sent those error messages to a support account where there were many emails. We wanted something specific for a specific team.
So we investigated how to make these messages reach the development team directly and they could have, in real time, a notification of an error in our production.
In our company we use Microsoft Teams as a corporate tool, so we asked ourselves: How could we make these messages reach the IRIS development team?
Previous steps
Please, expand to know how to configure your teams with the app Incoming Webhook.
Previous steps
Note: Webhook link is divided in two parts. Server and URL, remember this when you going to configure the component.
https://YOURCOMPANY.webhook.office.com/webhookb2/40cc6704-1bc5-4f87-xxxx-xxxxxxxxf@5xxxxxa-643b-47a3-xxxxx-fc962cc7cdb2/IncomingWebhook/6f272d796f1844b8b0b57b61365f8961/2ff46079-ee4a-442b-a642-dc418f6c67eeServer: YOURCOMPANY.webhook.office.comURL: /webhookb2/40cc6704-1bc5-4f87-xxxx-xxxxxxxxf@5xxxxxa-643b-47a3-xxxxx-fc962cc7cdb2/IncomingWebhook/6f272d796f1844b8b0b57b61365f8961/2ff46079-ee4a-442b-a642-dc418f6c67eeCalling to webhook API
The Incoming Webhook app admits the Office 360 connector cards. You can create your card using the adaptivecard designer.
So, I've designed a card to display a error message (Ens.AlertRequest).
.png)
AdaptiveCard for Ens.AlertRequest
Using this schema, You can create the message using the messages of St.Teams like this
setclass=##class(St.Teams.Msg.Adaptive.Request).%New()
setclass.Type = "message"set attach = ##class(St.Teams.Msg.Adaptive.Attachment).%New()
set content = ##class(St.Teams.Msg.Adaptive.Content).%New()
set container = ##class(St.Teams.Msg.Common.Item).%New()
set container.Type = "Container"set item1=##class(St.Teams.Msg.Common.Item).%New()
set item1.Type = "TextBlock"set item1.Text = "Unhandled error"set item1.Weight = "bolder"set item1.Size = "Medium"set item2=##class(St.Teams.Msg.Common.Item).%New()
set item2.Type = "TextBlock"set item2.Text = "St.Teams.BO.MainProcess"set item2.Weight = "bolder"set item2.Size = "small"set item2.IsSubtitle = 1set item3=##class(St.Teams.Msg.Common.Item).%New()
set item3.Type = "TextBlock"set item3.Text = "ERROR <Ens>ErrFTPListFailed: 'Unable to open data connection to 127.0.0. on port 8080',código=425)"set item3.Wrap = 1set factSet=##class(St.Teams.Msg.Common.Item).%New()
set factSet.Type = "FactSet"set factItem1 =##class(St.Teams.Msg.Common.FactItem).%New()
set factItem1.Title = "SessionId"set factItem1.Value = "111"set factItem2 =##class(St.Teams.Msg.Common.FactItem).%New()
set factItem2.Title = "Time"set factItem2.Value = "2024-02-28 11:00:15"do factSet.Facts.Insert(factItem1)
do factSet.Facts.Insert(factItem2)
do container.Items.Insert(item1)
do container.Items.Insert(item2)
do container.Items.Insert(item3)
do container.Items.Insert(factSet)
do content.Body.Insert(container)
set attach.Content = content
doclass.Attachments.Insert(attach)it creates the Json to call to the Webhook. But we want to create the message from a Ens.AlertRequest message, the best way is using a Data Transformer.
.png)
Then, the rule of your Ens.Alert should be like this:
.png)
It transform the Ens.AlertRequest using the St.Teams.DT.EnsAlertToAdpativeRequest and send it to St.Teams.BO.Api.Teams.
Then you recive the message directly into your Teams group.

I hope it is as useful to you as it has been to us.
Comments
Having groups in Teams dedicated to different projects and being able to address errors independently is very practical. Thanks for the info!
My Review - before being approved by OEX admins
- This is a really excellent example on
- How to publish in OEX
- a clear to understand description of the target
- a clean-to-install IPM package
- a Docker setup easy to follow without any dirty tricks undercover
- a fast and effective build and install that was tested in practice
- so you can keep your working environment free of polluting code fragments
- and a detailed understandable description of how to handle it
- Big THANKS to @Kurro Lopez
Thanks @Robert Cemper, your words are an inspiration to me
Thank you for taking the time to research and write this up!!
If you want to know how it works... check the following video
This is great Kurro!
But this is the kind of things I would definetely take advantage of embeded python to speed up the development. To send a message using python, few lines of code are needed:
import pymsteams
myTeamsMessage = pymsteams.connectorcard(url) # Initialize the connector card with webhook URL
myTeamsMessage.text("This message will end up in team") # Message content
myTeamsMessage.send() # Send the message
@David.Satorres6134 - that is a TREMENDOUS example of leveraging embedded python to avoid reinventing the wheel in ObjectScript! This very nicely demonstrates the value to people like me, who prefer to work in ObjectScript whenever possible, of having embedded python as a bridge to thousands and thousand of reusable libraries. Thank you for weighing in :)
Thanks for your replay.
Indeed, there is a package using pyhton, but not all of us can have access to use Python on client servers. The idea of using only objectscript arose from the need to not be able to implement Python on those servers.
Hi Kurro,
Your video is available on InterSystems Developers YouTube:
Updated OEX. Version 1.1.0 with URL for images in your cards.
Thanks Kurro! Because it looks like an outstanding effort, time, and dedication explaining IRIS to Teams integration, sincerely. Thank you.
Great contribution!!, thank you for providing us with this utility, I also believe that using this type of messaging can facilitate the filtering of messages to the teams in a more direct way.
I just have a personal Teams, How can I create the Webhook? I can't find that option
I'm afraid you need a Office 365 subscription, because it is a functionality for full version. Sorry.
The webhook is associated with an account and is managed by the Microsoft server, a personal account does not have a service that is "listening" for external requests.
💡 This article is considered InterSystems Data Platform Best Practice.
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)