Edit in GitHubLog an issue

Tutorial Step 7 - Sending Notifications

Congratulations! You've reached the end of the tutorial. This last step actually has nothing to do with Cloud Manager or Adobe I/O. In this step, we're going to take the data retrieved and send a message to either Microsoft Teams or Slack. Or you could do both if you are feeling adventurous.

Setting up a Notification Webhook

For both Microsoft Teams and Slack, notifications can be sent via an Incoming Webhook integration. The details are slightly different, but both follow the same basic concept -- when you want to post a message to a channel, you can make an HTTP POST request to a special URL generated specifically for this purpose.

Documentation to create a webhook URL for Microsoft Teams can be found here

Documentation to create a webhook URL for Slack can be found here.

Notifying Slack

Sending a Slack notification can be done with just a simple JSON object containing a text property. Let's create a new function which sends such an object to the webhook. To make the webhook easy to chnage, add a new variable to your .env file named SLACK_WEBHOOK and create this function:

Copied to your clipboard
1function notifySlack (message) {
2 fetch(process.env.SLACK_WEBHOOK, {
3 'method': 'POST',
4 'headers': { 'Content-Type': 'application/json' },
5 'body': JSON.stringify({
6 'text': message
7 })
8 })
9}

And the invoke this function instead of logging:

Copied to your clipboard
1if (STARTED === event['@type'] &&
2 EXECUTION === event['xdmEventEnvelope:objectType']) {
3 console.log('received execution start event')
4
5 const executionUrl = event['activitystreams:object']['@id']
6
7 getExecution(executionUrl).then(execution => {
8 notifySlack(`Execution for ${execution.program.name} started`)
9 })
10}

This will produce a Slack message which looks like this:

Slack Notification

Remix in Glitch

Notifying Microsoft Teams

Sending a Microsoft Teams notification can be as simple as Slack -- just a single text property. But Teams also supports some slightly fancier formatting options -- notifications can have a title and banner color, among other options. As with the Slack webhook, you should put the webhook URL in your .env file in a variable named TEAMS_WEBHOOK.

Copied to your clipboard
1function notifyTeams (message) {
2 fetch(process.env.TEAMS_WEBHOOK, {
3 'method': 'POST',
4 'headers': { 'Content-Type': 'application/json' },
5 'body': JSON.stringify({
6 '@context': 'https://schema.org/extensions',
7 '@type': 'MessageCard',
8 'themeColor': '0072C6',
9 'title': 'Update from Cloud Manager',
10 'text': message
11 })
12 })
13}

And then invoke this function:

Copied to your clipboard
1if (STARTED === event['@type'] &&
2 EXECUTION === event['xdmEventEnvelope:objectType']) {
3 console.log('received execution start event')
4
5 const executionUrl = event['activitystreams:object']['@id']
6
7 getExecution(executionUrl).then(execution => {
8 notifyTeams(`Execution for ${execution.program.name} started`)
9 })
10}

This will produce a Microsoft Teams message which looks like this:

Microsoft Teams Notification

Remix in Glitch
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.