Sending notifications and updates via Microsoft Teams will keep you and your co-workers informed on-time. To configure this events from your Ubidots App does require a small integration using the “Incoming Webhooks” app, which is powered by Microsoft and is a simple way to post messages from Ubidots into Teams.
Requirements
Ubidots account (trial or licensed)
A Microsoft Teams account with the “Incoming Webhooks” connector enabled. See "Create Incoming Webhooks".
1. Set up an incoming webhook in Microsoft Teams
To configure the Incoming Webhooks Connector correctly in your Microsoft Teams app, follow these steps:
Open the channel in which you want to add the webhook and select ••• on the upper-right corner.
Select Connectors from the dropdown menu.
Search for Incoming Webhook and select Add.
Select Configure, provide a name and upload an image for your webhook.
Copy and save the unique webhook URL present in the dialog. The URL maps to the channel and you can use it to send information to Teams.
2. Create a new event in Ubidots
After setting up an incoming webhook in your Teams app, go to your Ubidots account, head to the “data” tab → "Events" and hover over the “+” button, located at the upper-right corner of the screen. Here you can create a common event just clicking on the button or create a global event/scheduled event depending on your needs.
Next, configure the event’s triggers with an AND/OR logic. For additional details on how to configure these triggers, head to their own guides: value based, inactivity, geofence.
3. Configure the Trigger Webhook action
To configure a Trigger Webhook action in your Ubidots account, please follow these steps:
Fill all the following fields:
Select a POST HTTP Method.
Enter the URL you saved from the last step of the "Section 1. Setup an Incoming Webhook in Microsoft Teams".
Enter the Content-type header with application/json
Customize the “active trigger” and the “back to normal” (optional) messages that will be sent to Teams. Look at some examples at the fourth section of this guide, "JSON examples for Microsoft Teams messages".
By using the tag icon at the upper right corner of the “payload” field you can easily add information such as device ID, timestamp, variable name, etc.
Optionally, enable the “repeat action” option if you want to set the variable multiple times while the event is triggered. You can choose how often and up to how many times the action will be repeated. There’s a limit of 50 action repetitions.
Click on “save” once you finish configuring the action and on “next”, unless you want to set up multiple actions.
After completing the action configuration you’ will proceed to the final step, the “settings” tab. There, you’ll name the event and give it a description (optional).
Another optional step is to use a tag on the event. This is a great tool to control what your end users see in your app. In this case, for instance, you could decide that your end user sees one event, but not another, using tags. Learn more about tags here.
Finally (unless the event you created is a scheduled event), determine the activity window in which the events should be executed. An event can have multiple active windows by clicking on the “+ add window button” and configuring them correspondingly. After finishing this, click on “save” and your event will be deployed.
4. JSON examples for Microsoft Teams messages
After configuring the Trigger Webhook action in your event, here are some JSON examples you can add to your payload with its respective result in the app.
"type": "message", with a single text.
{
"type": "message",
"text": "Hello, this is a test of Microsoft Teams Incoming Webhook"
}
"type": "message", without text and attaching an image in a Hero Card.
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "Sample Hero Card",
"subtitle": "This is a subtitle",
"text": "This is the main content of the card.",
"images": [
{
"url": "https://example.com/sample-image.png"
}
],
"buttons": [
{
"type": "openUrl",
"title": "Learn More",
"value": "https://example.com/learn-more"
},
{
"type": "imBack",
"title": "Ask a Question",
"value": "How can I help you?" }
],
"additionalKey": "Additional Value"
}
}
]
}
"type": "", with text required and adding different keys
{
"type": "",
"text": "Hello, this is a test of Microsoft Teams Incoming Webhook",
"title": "Ubidots",
"themeColor": "#6d77b3",
"sections": [
{
"title": "Section 1",
"text": "This is the content of section 1."
},
{
"title": "Section 2",
"text": "This is the content of section 2."
}
],
"potentialAction": [
{
"@context": "http://schema.org",
"@type": "ActionCard",
"name": "Open Link",
"inputs": [
{
"@type": "TextInput",
"id": "linkUrl",
"isMultiline": False,
"title": "Enter URL"
}
],
"actions": [
{
"@type": "HttpPOST",
"name": "Open",
"target": "linkUrl"
}
]
},
{
"@type": "OpenUri",
"name": "Visit Website",
"targets": [
{
"os": "default",
"uri": "https://example.com"
}
]
}
]
}