...
Note |
---|
Microsoft 365 Connector Retirement With the retirement of Office 365 connectors in Teams, the only supported approach of sending messages in Microsoft teams in through Microsoft Teams Workflows. The following page will cover how to configure FlexDeploy to leverage Teams Workflows to send messages. |
Table of Contents | ||
---|---|---|
|
Adding a Workflow in Teams to receive a webhook message
You will need to add
...
a Workflow in Teams
...
by
...
Search for Incoming Webhook, and click Add.
...
Click Add again.
Give a Name, and if you wish an image that you would like to associate with FlexDeploy Notifications in this Channel. Then click Create.
...
Copy the webhook url. You will need to paste it into FlexDeploy.
...
Click Done.
Additional Resources
See https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook for additional information about what Incoming Webhooks are and how they are used.
You may need to contact your Teams Administrator before adding an Incoming Webhooks Connector. If you don’t see the ability to add Connectors, or don’t find Incoming Webhook in the list, contact your administrator and ask them to enable this connector. They will navigate to https://admin.teams.microsoft.com/policies/manage-apps to configure org-wide settings, and then verify the settings here: https://admin.teams.microsoft.com/policies/manage-apps/203a1e2c-26cc-47ca-83ae-be98f960b6b2/
The settings can take several minutes, or even hours to show up in your Teams Application. You may find that you can add it using the Teams Web Client more quickly.
If you also want to approve tasks through Webhooks integrations, then you must also follow the guide here:
...
clicking the three dot menu and selecting the Workflows application.
...
Once viewing the Workflows page, click the ➕ New Flow button on the top right.
...
You can optionally select a template but for this walkthrough just click the ➕ Create from blank button.
...
The first step should be When a Teams webhook request is received
...
Select Anyone for “Who can trigger the flow?” and click on the ➕ New Step button.
...
The second and final step should be Post card in a chat or channel.
...
Specify which Team, Channel, or Group Chat you want to post the message to. Finally select Body as the Adaptive Card content. Body represents the entire input payload that will be sent to the webhook.
Info |
---|
If you do not see Body as an available option, then try saving your workflow, closing it, and re-editing it. |
...
Save your Workflow and re-open the first step so you can copy the webhook URL.
...
Using the Webhook URL from the Teams Workflow
The Webhook URL copied from the Teams Workflow is what will be used when configuring Plugin Operations and using our MICROSOFTTEAMS
groovy helper.
Posting Messages with MICROSOFTTEAMS helper
The following script creates and posts a message that leverages most of the card features supported by our MicrosoftTeamsMessageCard
helper class.
Code Block | ||
---|---|---|
| ||
import flexagon.ffi.microsoftteams.pojos.MicrosoftTeamsMessageCard;
LOG.info("Running function: ${FUNCTION_NAME}");
def teams_url= "YOUR_WEBHOOK_URL_COPIED_FROM_ABOVE"
MicrosoftTeamsMessageCard card = new MicrosoftTeamsMessageCard()
card.setTitle("Main Title")
card.setActivityTitle("Card Subtitle")
card.setIconUrl("https://png.pngtree.com/element_pic/00/16/09/2057e0eecf792fb.jpg")
card.setSectionText("This is the main body of the card. This is longer form content.")
card.addFact("Fact 1", "This is neat huh")
card.addFact("Fact 2", "I sure think so")
card.addAction("Action.OpenUrl", ["url":"https://google.com", "title":"Open Google"])
card.setTableHeaders(["Project", "Workflow", "Release"])
card.addTableRow(["Samples", "BuildGit", "Weekly Release"])
card.addTableRow(["Natours", "BuildGit", "Monthly Release"])
MICROSOFTTEAMS.sendTeamsWebhookMessage(teams_url, card) |
The final result looks like the following:
...
Info |
---|
More Advanced Messages Note that you can also pass a json string to the Microsoft also provides a playground where you can design your own messages in realtime. |
Setting up Certificates
You may need to install the certificate for https://graph.microsoft.com/.default into your Java keystore. If this is the case, you will get an error about building a certificate path.