-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtelegram-alert-channel.ts
More file actions
79 lines (74 loc) · 2.37 KB
/
telegram-alert-channel.ts
File metadata and controls
79 lines (74 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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/alerts/telegram/}
*/
chatId: string
/**
* The API key for your Telegram bot.
* {@link https://www.checklyhq.com/docs/integrations/alerts/telegram/}
*/
apiKey: string
/**
* An optional custom payload. If not given,
* `TelegramAlertChannel.DEFAULT_PAYLOAD` will be used.
*/
payload?: string
}
/**
* Creates a Telegram Alert Channel
*
* @remarks
*
* This class make use of the Alert Channel endpoints.
*/
export class TelegramAlertChannel extends WebhookAlertChannel {
static DEFAULT_PAYLOAD = `<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>
`
/**
* 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'
const payload = props.payload ?? TelegramAlertChannel.DEFAULT_PAYLOAD
// For historical reasons the payload is not escaped even though it
// should be.
this.template = `chat_id=${props.chatId}&parse_mode=HTML&text=${payload}`
this.url = `https://api.telegram.org/bot${props.apiKey}/sendMessage`
}
describe (): string {
return `TelegramAlertChannel:${this.logicalId}`
}
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,
},
}
}
}