Skip to content

Commit 78e8672

Browse files
[Microsoft Teams] Add Support for sending notifications through Workflows in Microsoft Teams (#4234)
* Add ms-teams-workflows * Update Docs
1 parent f719459 commit 78e8672

3 files changed

Lines changed: 312 additions & 0 deletions

File tree

contrib/ms-teams-workflows.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
/*
3+
## Installing
4+
5+
Microsoft is retiring the legacy "Incoming Webhook" connector. New
6+
integrations must use the **Workflows** app (Power Automate). This
7+
recipe targets the Workflows "Post to a channel when a webhook request
8+
is received" template.
9+
10+
Setup:
11+
1. Open MS Teams
12+
2. Navigate to Teams section
13+
3. Select existing or create new team
14+
4. Select existing or create new channel
15+
5. Click the three dots on the channel, choose "Workflows"
16+
6. Pick the template **Post to a channel when a webhook request is received**
17+
7. Follow the wizard, then copy the generated HTTPS POST URL
18+
8. Setup deploy.php
19+
Add in header:
20+
```php
21+
require 'contrib/ms-teams-workflows.php';
22+
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
23+
```
24+
Add in content:
25+
```php
26+
before('deploy', 'teams-workflows:notify');
27+
after('deploy:success', 'teams-workflows:notify:success');
28+
after('deploy:failed', 'teams-workflows:notify:failure');
29+
```
30+
9.) Sip your coffee
31+
32+
## Configuration
33+
34+
- `teams_workflows_webhook` – workflow HTTPS POST URL, **required**
35+
```
36+
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
37+
```
38+
- `teams_workflows_title` – the title of application, default `{{application}}`
39+
- `teams_workflows_text` – notification message template
40+
```
41+
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
42+
```
43+
- `teams_workflows_success_text` – success template, default:
44+
```
45+
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
46+
```
47+
- `teams_workflows_failure_text` – failure template, default:
48+
```
49+
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');
50+
```
51+
- `teams_workflows_failure_continue` – if `true`, errors talking to the
52+
workflow endpoint are downgraded to warnings instead of aborting the
53+
deploy. Default `false`.
54+
55+
## Usage
56+
57+
If you want to notify only about beginning of deployment add this line only:
58+
59+
```php
60+
before('deploy', 'teams-workflows:notify');
61+
```
62+
63+
If you want to notify about successful end of deployment add this too:
64+
65+
```php
66+
after('deploy:success', 'teams-workflows:notify:success');
67+
```
68+
69+
If you want to notify about failed deployment add this too:
70+
71+
```php
72+
after('deploy:failed', 'teams-workflows:notify:failure');
73+
```
74+
*/
75+
76+
namespace Deployer;
77+
78+
use Deployer\Utility\Httpie;
79+
80+
// Title of project
81+
set('teams_workflows_title', function () {
82+
return get('application', 'Project');
83+
});
84+
85+
// Allow Continue on Failure
86+
set('teams_workflows_failure_continue', false);
87+
88+
// Deploy message
89+
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
90+
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
91+
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');
92+
93+
desc('Notifies Teams (Workflows)');
94+
task('teams-workflows:notify', function () {
95+
if (!get('teams_workflows_webhook', false)) {
96+
warning('No MS Teams Workflows webhook configured');
97+
return;
98+
}
99+
100+
try {
101+
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
102+
'text' => get('teams_workflows_text'),
103+
])->send();
104+
} catch (\Exception $e) {
105+
if (get('teams_workflows_failure_continue', false)) {
106+
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
107+
} else {
108+
throw $e;
109+
}
110+
}
111+
})
112+
->once()
113+
->hidden();
114+
115+
desc('Notifies Teams (Workflows) about deploy finish');
116+
task('teams-workflows:notify:success', function () {
117+
if (!get('teams_workflows_webhook', false)) {
118+
warning('No MS Teams Workflows webhook configured');
119+
return;
120+
}
121+
122+
try {
123+
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
124+
'text' => get('teams_workflows_success_text'),
125+
])->send();
126+
} catch (\Exception $e) {
127+
if (get('teams_workflows_failure_continue', false)) {
128+
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
129+
} else {
130+
throw $e;
131+
}
132+
}
133+
})
134+
->once()
135+
->hidden();
136+
137+
desc('Notifies Teams (Workflows) about deploy failure');
138+
task('teams-workflows:notify:failure', function () {
139+
if (!get('teams_workflows_webhook', false)) {
140+
warning('No MS Teams Workflows webhook configured');
141+
return;
142+
}
143+
144+
try {
145+
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
146+
'text' => get('teams_workflows_failure_text'),
147+
])->send();
148+
} catch (\Exception $e) {
149+
if (get('teams_workflows_failure_continue', false)) {
150+
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
151+
} else {
152+
throw $e;
153+
}
154+
}
155+
})
156+
->once()
157+
->hidden();

docs/contrib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [Ispmanager Recipe](/docs/contrib/ispmanager.md)
1616
* [Mattermost Recipe](/docs/contrib/mattermost.md)
1717
* [Ms-teams Recipe](/docs/contrib/ms-teams.md)
18+
* [Ms-teams-workflows Recipe](/docs/contrib/ms-teams-workflows.md)
1819
* [Newrelic Recipe](/docs/contrib/newrelic.md)
1920
* [Npm Recipe](/docs/contrib/npm.md)
2021
* [Ntfy Recipe](/docs/contrib/ntfy.md)

docs/contrib/ms-teams-workflows.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<!-- DO NOT EDIT THIS FILE! -->
2+
<!-- Instead edit contrib/ms-teams-workflows.php -->
3+
<!-- Then run bin/docgen -->
4+
5+
# Ms-teams-workflows Recipe
6+
7+
```php
8+
require 'contrib/ms-teams-workflows.php';
9+
```
10+
11+
[Source](/contrib/ms-teams-workflows.php)
12+
13+
14+
15+
## Installing
16+
Microsoft is retiring the legacy "Incoming Webhook" connector. New
17+
integrations must use the **Workflows** app (Power Automate). This
18+
recipe targets the Workflows "Post to a channel when a webhook request
19+
is received" template.
20+
Setup:
21+
1. Open MS Teams
22+
2. Navigate to Teams section
23+
3. Select existing or create new team
24+
4. Select existing or create new channel
25+
5. Click the three dots on the channel, choose "Workflows"
26+
6. Pick the template **Post to a channel when a webhook request is received**
27+
7. Follow the wizard, then copy the generated HTTPS POST URL
28+
8. Setup deploy.php
29+
Add in header:
30+
```php
31+
require 'contrib/ms-teams-workflows.php';
32+
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
33+
```
34+
Add in content:
35+
```php
36+
before('deploy', 'teams-workflows:notify');
37+
after('deploy:success', 'teams-workflows:notify:success');
38+
after('deploy:failed', 'teams-workflows:notify:failure');
39+
```
40+
9.) Sip your coffee
41+
## Configuration
42+
- `teams_workflows_webhook` – workflow HTTPS POST URL, **required**
43+
```
44+
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
45+
```
46+
- `teams_workflows_title` – the title of application, default `{{application}}`
47+
- `teams_workflows_text` – notification message template
48+
```
49+
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
50+
```
51+
- `teams_workflows_success_text` – success template, default:
52+
```
53+
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
54+
```
55+
- `teams_workflows_failure_text` – failure template, default:
56+
```
57+
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');
58+
```
59+
- `teams_workflows_failure_continue` – if `true`, errors talking to the
60+
workflow endpoint are downgraded to warnings instead of aborting the
61+
deploy. Default `false`.
62+
## Usage
63+
If you want to notify only about beginning of deployment add this line only:
64+
```php
65+
before('deploy', 'teams-workflows:notify');
66+
```
67+
If you want to notify about successful end of deployment add this too:
68+
```php
69+
after('deploy:success', 'teams-workflows:notify:success');
70+
```
71+
If you want to notify about failed deployment add this too:
72+
```php
73+
after('deploy:failed', 'teams-workflows:notify:failure');
74+
```
75+
76+
77+
## Configuration
78+
### teams_workflows_title
79+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L81)
80+
81+
Title of project
82+
83+
```php title="Default value"
84+
return get('application', 'Project');
85+
```
86+
87+
88+
### teams_workflows_failure_continue
89+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L86)
90+
91+
Allow Continue on Failure
92+
93+
```php title="Default value"
94+
false
95+
```
96+
97+
98+
### teams_workflows_text
99+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L89)
100+
101+
Deploy message
102+
103+
```php title="Default value"
104+
'_{{user}}_ deploying `{{what}}` to *{{where}}*'
105+
```
106+
107+
108+
### teams_workflows_success_text
109+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L90)
110+
111+
112+
113+
```php title="Default value"
114+
'Deploy to *{{where}}* successful'
115+
```
116+
117+
118+
### teams_workflows_failure_text
119+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L91)
120+
121+
122+
123+
```php title="Default value"
124+
'Deploy to *{{where}}* failed'
125+
```
126+
127+
128+
129+
## Tasks
130+
131+
### teams-workflows\:notify {#teams-workflows-notify}
132+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L94)
133+
134+
Notifies Teams (Workflows).
135+
136+
137+
138+
139+
### teams-workflows\:notify\:success {#teams-workflows-notify-success}
140+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L116)
141+
142+
Notifies Teams (Workflows) about deploy finish.
143+
144+
145+
146+
147+
### teams-workflows\:notify\:failure {#teams-workflows-notify-failure}
148+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L138)
149+
150+
Notifies Teams (Workflows) about deploy failure.
151+
152+
153+
154+

0 commit comments

Comments
 (0)