Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
EmailAlertChannel,
SlackAlertChannel,
WebhookAlertChannel,
MSTeamsAlertChannel,
TelegramAlertChannel,
} from 'checkly/constructs'

const sendDefaults = {
Expand All @@ -30,6 +32,17 @@ export const slackChannel = new SlackAlertChannel('slack-channel-1', {
...sendDefaults,
})

export const msTeamsChannel = new MSTeamsAlertChannel('msteams-channel-1', {
name: 'MS Teams Channel',
url: 'INSERT_WEBHOOK_HERE',
})

export const telegramChannel = new TelegramAlertChannel('telegram-channel-1', {
name: 'Telegram Channel',
apiKey: 'API_TOKEN_HERE',
chatId: 'CHAT_ID_HERE',
})

export const webhookChannel = new WebhookAlertChannel('webhook-channel-1', {
name: 'Pushover webhook',
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/constructs/incidentio-alert-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface IncidentioAlertChannelProps extends AlertChannelProps {
url: URL|string
/**
* The API key created by installing the Checkly integration in Incident.io.
* {@link {@link https://www.checklyhq.com/docs/integrations/incidentio/}}
* {@link https://www.checklyhq.com/docs/integrations/incidentio/}
*/
apiKey: string
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/constructs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export * from './multi-step-check'
export * from './alert-escalation-policy'
export * from './tcp-check'
export * from './incidentio-alert-channel'
export * from './msteams-alert-channel'
export * from './telegram-alert-channel'
127 changes: 127 additions & 0 deletions packages/cli/src/constructs/msteams-alert-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { WebhookAlertChannel } from './webhook-alert-channel'
import { AlertChannelProps } from './alert-channel'

export interface MSTeamsAlertChannelProps extends AlertChannelProps {
/**
* Friendly name to recognise the integration.
* */
name: string
/**
* The unique URL created by creating an integration in Microsoft Teams.
* {@link https://www.checklyhq.com/docs/integrations/msteams/}
*/
url: string
}

/**
* Creates a Microsoft Teams Alert Channel
*
* @remarks
*
* This class make use of the Alert Channel endpoints.
*/
export class MSTeamsAlertChannel extends WebhookAlertChannel {
/**
* Constructs the Microsoft Teams Alert Channel instance
*
* @param logicalId unique project-scoped resource name identification
* @param props MSTeams alert channel configuration properties
*
* {@link https://checklyhq.com/docs/cli/constructs/#msteamsalertchannel Read more in the docs}
*/
constructor (logicalId: string, props: MSTeamsAlertChannelProps) {
super(logicalId, props)
this.webhookType = 'WEBHOOK_MSTEAMS'
this.method = 'POST'
this.template = `{
"type":"message",
"attachments":[
{
"contentType":"application/vnd.microsoft.card.adaptive",
"contentUrl":null,
"content":{
"$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
"type":"AdaptiveCard",
"version":"1.2",
"body":[
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "{{ALERT_TITLE}}",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Response time: {{RESPONSE_TIME}}ms",
"wrap": true
},
{
"type": "TextBlock",
"text": "Location: {{RUN_LOCATION}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Timestamp: {{STARTED_AT}}",
"wrap": true
},
{{#if GROUP_NAME}}
{
"type": "TextBlock",
"text": "Group: {{GROUP_NAME}}",
"wrap": true
},
{{/if}}
{
"type": "TextBlock",
"text": "Tags: {{#each TAGS}} {{this}} {{#unless @last}},{{/unless}} {{/each}}",
"wrap": true
}
]
}
]
}
]
}
],
"actions":[
{
"type":"Action.OpenUrl",
"title":"View in Checkly",
"url":"{{RESULT_LINK}}"
}
]
}
}
]
}
`
}

synthesize () {
return {
...super.synthesize(),
type: 'WEBHOOK',
config: {
name: this.name,
webhookType: this.webhookType,
url: this.url,
template: this.template,
method: this.method,
headers: this.headers,
queryParameters: this.queryParameters,
webhookSecret: this.webhookSecret,
},
}
}
}
65 changes: 65 additions & 0 deletions packages/cli/src/constructs/telegram-alert-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { WebhookAlertChannel } from './webhook-alert-channel'
import { AlertChannelProps } from './alert-channel'

export interface TelegramAlertChannelProps extends AlertChannelProps {
/**
* Friendly name to recognise the integration.
*/
name: string
/**
* The chat ID of your Telegram bot.
* {@link https://www.checklyhq.com/docs/integrations/telegram/}
*/
chatId: string
/**
* The API key for your Telegram bot.
* {@link https://www.checklyhq.com/docs/integrations/telegram/}
*/
apiKey: string
}

/**
* Creates a Telegram Alert Channel
*
* @remarks
*
* This class make use of the Alert Channel endpoints.
*/
export class TelegramAlertChannel extends WebhookAlertChannel {
/**
* Constructs the Telegram Alert Channel instance
*
* @param logicalId unique project-scoped resource name identification
* @param props Telegram alert channel configuration properties
* Fix following url:
* {@link https://checklyhq.com/docs/cli/constructs/#telegramalertchannel Read more in the docs}
*/
constructor (logicalId: string, props: TelegramAlertChannelProps) {
// @ts-ignore
super(logicalId, props)
this.webhookType = 'WEBHOOK_TELEGRAM'
this.method = 'POST'
this.template = `chat_id=${props.chatId}&parse_mode=HTML&text=<b>{{ALERT_TITLE}}</b> at {{STARTED_AT}} in {{RUN_LOCATION}} ({{RESPONSE_TIME}}ms)
Tags: {{#each TAGS}} <i><b>{{this}}</b></i> {{#unless @last}},{{/unless}} {{/each}}
<a href="{{RESULT_LINK}}">View check result</a>
`
this.url = `https://api.telegram.org/bot${props.apiKey}/sendMessage`
}

synthesize () {
return {
...super.synthesize(),
type: 'WEBHOOK',
config: {
name: this.name,
webhookType: this.webhookType,
url: this.url,
template: this.template,
method: this.method,
headers: this.headers,
queryParameters: this.queryParameters,
webhookSecret: this.webhookSecret,
},
}
}
}
Loading