Skip to content

Commit

Permalink
partial implementation of issue checkly#995
Browse files Browse the repository at this point in the history
  • Loading branch information
RedOctober117 committed Dec 16, 2024
1 parent e99187c commit 85db267
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/constructs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './phone-call-alert-channel'
export * from './retry-strategy'
export * from './multi-step-check'
export * from './alert-escalation-policy'
export * from './msteams-alert-channel'
109 changes: 109 additions & 0 deletions packages/cli/src/constructs/msteams-alert-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { AlertChannel, AlertChannelProps } from './alert-channel'
import { Session } from './project'

export interface MSTeamsAlertChannelProps extends AlertChannelProps {
/**
* The name of your MSTeams alert
*/
name: string
/**
* The name of your MSTeams alert channel.
*/
channel_name: string
/**
* The URL webhook to which to send updates.
*/
url: string
template?: string
}

/**
* Creates an MSTeams Alert Channel
*
* @remarks
*
* This class make use of the Alert Channel endpoints.
*/
export class MSTeamsAlertChannel extends AlertChannel {
name: string
channel_name: string
url: string
template?: string

/**
* Constructs the MSTeams Alert Channel instance
*
* @param logicalId unique project-scoped resource name identification
* @param props MSTeams alert channel configuration properties
* Fix following url:
* {@link https://checklyhq.com/docs/cli/constructs/#MSTeamsalertchannel Read more in the docs}
*/
constructor(logicalId: string, props: MSTeamsAlertChannelProps) {
super(logicalId, props)
this.name = props.name;
this.channel_name = props.channel_name;
this.url = props.url;
this.template = props.template || `{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"size": "large",
"type": "TextBlock",
"text": "{{ALERT_TITLE}} has failed",
"wrap": true
},
{
"type": "TextBlock",
"text": "Response time: {{RESPONSE_TIME}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Location: {{RUN_LOCATION}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Timestamp: {{STARTED_AT}}",
"wrap": true
},
{
"type": "TextBlock",
"text": "Tags: {{TAGS}}",
"wrap": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Learn More",
"url": "https://adaptivecards.io"
}
]
}
}
]
}`;
Session.registerConstruct(this)
}

synthesize() {
return {
...super.synthesize(),
type: 'WEBHOOK',
config: {
name: this.name,
channel_name: this.channel_name,
url: this.url,
template: this.template,
},
}
}
}

0 comments on commit 85db267

Please sign in to comment.