Skip to content

Commit 4fe6093

Browse files
committed
feat: adds MS teams and Telegram alert channels
1 parent 98f3396 commit 4fe6093

File tree

3 files changed

+71
-66
lines changed

3 files changed

+71
-66
lines changed

packages/cli/src/constructs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ export * from './phone-call-alert-channel'
2525
export * from './retry-strategy'
2626
export * from './multi-step-check'
2727
export * from './alert-escalation-policy'
28+
export * from './tcp-check'
29+
export * from './incidentio-alert-channel'
2830
export * from './msteams-alert-channel'
2931
export * from './telegram-alert-channel'

packages/cli/src/constructs/msteams-alert-channel.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
1-
import { Session } from './project'
2-
import { WebhookAlertChannel, WebhookAlertChannelProps } from './webhook-alert-channel'
1+
import { WebhookAlertChannel } from './webhook-alert-channel'
2+
import { AlertChannelProps } from './alert-channel'
33

4-
export interface MSTeamsAlertChannelProps extends WebhookAlertChannelProps {
4+
export interface MSTeamsAlertChannelProps extends AlertChannelProps {
55
/**
6-
* The name of your MSTeams alert
7-
*/
6+
* Friendly name to recognise the integration.
7+
* */
88
name: string
99
/**
10-
* The URL webhook to which to send updates.
10+
* The unique URL created by creating an integration in Microsoft Teams.
11+
* {@link https://www.checklyhq.com/docs/integrations/msteams/}
1112
*/
1213
url: string
1314
}
1415

1516
/**
16-
* Creates an MSTeams Alert Channel
17+
* Creates a Microsoft Teams Alert Channel
1718
*
1819
* @remarks
1920
*
2021
* This class make use of the Alert Channel endpoints.
2122
*/
2223
export class MSTeamsAlertChannel extends WebhookAlertChannel {
23-
name: string
24-
url: string
25-
2624
/**
27-
* Constructs the MSTeams Alert Channel instance
25+
* Constructs the Microsoft Teams Alert Channel instance
2826
*
2927
* @param logicalId unique project-scoped resource name identification
3028
* @param props MSTeams alert channel configuration properties
31-
* Fix following url:
32-
* {@link https://checklyhq.com/docs/cli/constructs/#MSTeamsalertchannel Read more in the docs}
29+
*
30+
* {@link https://checklyhq.com/docs/cli/constructs/#msteamsalertchannel Read more in the docs}
3331
*/
3432
constructor (logicalId: string, props: MSTeamsAlertChannelProps) {
3533
super(logicalId, props)
36-
this.name = props.name
37-
this.url = props.url
38-
this.template = props.template || `{
39-
"type": "message",
40-
"attachments": [
34+
this.webhookType = 'WEBHOOK_MSTEAMS'
35+
this.method = 'POST'
36+
this.template = `{
37+
"type":"message",
38+
"attachments":[
4139
{
42-
"contentType": "application/vnd.microsoft.card.adaptive",
43-
"contentUrl": null,
44-
"content": {
45-
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
46-
"type": "AdaptiveCard",
47-
"version": "1.2",
48-
"body": [
40+
"contentType":"application/vnd.microsoft.card.adaptive",
41+
"contentUrl":null,
42+
"content":{
43+
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
44+
"type":"AdaptiveCard",
45+
"version":"1.2",
46+
"body":[
4947
{
5048
"type": "Container",
5149
"items": [
@@ -96,27 +94,33 @@ export class MSTeamsAlertChannel extends WebhookAlertChannel {
9694
]
9795
}
9896
],
99-
"actions": [
97+
"actions":[
10098
{
101-
"type": "Action.OpenUrl",
102-
"title": "View in Checkly",
103-
"url": "{{RESULT_LINK}}"
99+
"type":"Action.OpenUrl",
100+
"title":"View in Checkly",
101+
"url":"{{RESULT_LINK}}"
104102
}
105103
]
106104
}
107105
}
108106
]
109-
}`
110-
Session.registerConstruct(this)
107+
}
108+
`
111109
}
112110

113111
synthesize () {
114112
return {
115113
...super.synthesize(),
116-
type: 'WEBHOOK_MSTEAMS',
114+
type: 'WEBHOOK',
117115
config: {
118116
name: this.name,
117+
webhookType: this.webhookType,
119118
url: this.url,
119+
template: this.template,
120+
method: this.method,
121+
headers: this.headers,
122+
queryParameters: this.queryParameters,
123+
webhookSecret: this.webhookSecret,
120124
},
121125
}
122126
}

packages/cli/src/constructs/telegram-alert-channel.ts

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
1-
import { HttpRequestMethod } from './api-check'
2-
import { Session } from './project'
3-
import { WebhookAlertChannel, WebhookAlertChannelProps } from './webhook-alert-channel'
1+
import { WebhookAlertChannel } from './webhook-alert-channel'
2+
import { AlertChannelProps } from './alert-channel'
43

5-
export interface TelegramAlertChannelProps extends WebhookAlertChannelProps {
6-
/**
7-
* The name of your Telegram alert
8-
*/
9-
name: string
10-
/**
11-
* The chat id of your Telegram bot.
12-
*/
13-
chatId: string
14-
/**
15-
* API token for your telegram bot.
16-
*/
17-
apiToken: string
4+
export interface TelegramAlertChannelProps extends AlertChannelProps {
5+
/**
6+
* Friendly name to recognise the integration.
7+
*/
8+
name: string
9+
/**
10+
* The chat ID of your Telegram bot.
11+
* {@link https://www.checklyhq.com/docs/integrations/telegram/}
12+
*/
13+
chatId: string
14+
/**
15+
* The API key for your Telegram bot.
16+
* {@link https://www.checklyhq.com/docs/integrations/telegram/}
17+
*/
18+
apiKey: string
1819
}
1920

2021
/**
21-
* Creates an Telegram Alert Channel
22+
* Creates a Telegram Alert Channel
2223
*
2324
* @remarks
2425
*
25-
* This class make use of the Webhook Alert Channel endpoints.
26+
* This class make use of the Alert Channel endpoints.
2627
*/
2728
export class TelegramAlertChannel extends WebhookAlertChannel {
28-
name: string
29-
chatId: string
30-
apiToken: string
31-
url: string
32-
method: HttpRequestMethod
33-
3429
/**
3530
* Constructs the Telegram Alert Channel instance
3631
*
3732
* @param logicalId unique project-scoped resource name identification
3833
* @param props Telegram alert channel configuration properties
3934
* Fix following url:
40-
* {@link https://checklyhq.com/docs/cli/constructs/#Telegramalertchannel Read more in the docs}
35+
* {@link https://checklyhq.com/docs/cli/constructs/#telegramalertchannel Read more in the docs}
4136
*/
4237
constructor (logicalId: string, props: TelegramAlertChannelProps) {
38+
// @ts-ignore
4339
super(logicalId, props)
44-
this.name = props.name
45-
this.chatId = props.chatId
46-
this.apiToken = props.apiToken
47-
this.template = props.template || `chat_id=${props.chatId}&parse_mode=HTML&text=<b>{{ALERT_TITLE}}</b> at {{STARTED_AT}} in {{RUN_LOCATION}} ({{RESPONSE_TIME}}ms)\nTags: {{#each TAGS}} <i><b>{{this}}</b></i> {{#unless @last}},{{/unless}} {{/each}}\n<a href=\"{{RESULT_LINK}}\">View check result</a>\n`
48-
this.url = `https://api.telegram.org/bot${props.apiToken}/sendMessage?chat_id=${props.chatId}&text=${this.template}`
40+
this.webhookType = 'WEBHOOK_TELEGRAM'
4941
this.method = 'POST'
50-
Session.registerConstruct(this)
42+
this.template = `chat_id=${props.chatId}&parse_mode=HTML&text=<b>{{ALERT_TITLE}}</b> at {{STARTED_AT}} in {{RUN_LOCATION}} ({{RESPONSE_TIME}}ms)
43+
Tags: {{#each TAGS}} <i><b>{{this}}</b></i> {{#unless @last}},{{/unless}} {{/each}}
44+
<a href="{{RESULT_LINK}}">View check result</a>
45+
`
46+
this.url = `https://api.telegram.org/bot${props.apiKey}/sendMessage`
5147
}
5248

5349
synthesize () {
5450
return {
5551
...super.synthesize(),
56-
type: 'WEBHOOK_TELEGRAM',
52+
type: 'WEBHOOK',
5753
config: {
5854
name: this.name,
59-
chatId: this.chatId,
60-
apiToken: this.apiToken,
55+
webhookType: this.webhookType,
6156
url: this.url,
57+
template: this.template,
6258
method: this.method,
59+
headers: this.headers,
60+
queryParameters: this.queryParameters,
61+
webhookSecret: this.webhookSecret,
6362
},
6463
}
6564
}

0 commit comments

Comments
 (0)