-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
295 lines (267 loc) · 7.44 KB
/
index.d.ts
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
declare module '@smpx/notify' {
/**
* Taken from @slack/client
*/
interface MessageAttachment {
fallback?: string;
color?: 'good' | 'warning' | 'danger' | string;
pretext?: string;
author_name?: string;
author_link?: string;
author_icon?: string;
title?: string;
title_link?: string;
text?: string;
fields?: {
title: string;
value: string;
short?: boolean;
}[];
image_url?: string;
thumb_url?: string;
footer?: string;
footer_icon?: string;
ts?: number;
actions?: AttachmentAction[];
callback_id?: string;
mrkdwn_in?: ('pretext' | 'text' | 'fields')[];
}
interface AttachmentAction {
id?: string;
confirm?: Confirmation;
data_source?: string;
min_query_length?: number;
name?: string;
options?: OptionField[];
option_groups?: {
text: string;
options: OptionField[];
}[];
selected_options?: OptionField[];
style?: string;
text: string;
type: string;
value?: string;
url?: string;
}
interface OptionField {
description?: string;
text: string;
value: string;
}
interface Confirmation {
dismiss_text?: string;
ok_text?: string;
text: string;
title?: string;
}
class Notify {
static bold(text: string): string;
static italics(text: string): string;
static pre(text: string): string;
static strikeThrough(text: string): string;
/**
* Format function for message building, default formatting is Bold
* @param text
* @param opts If no options object is provided then bold is set as true
* @returns formatted txt
*/
static format(text: string, opts?: {
pre?: boolean,
code?: boolean;
bold?: boolean;
italics?: boolean;
strikethrough?: boolean;
}): string;
static formatUrl(url: string, text: string): string;
/**
* Webhook is given priority over legacy tokens
* @param webhook
*/
}
class Slack extends Notify {
/**
* Overwrite this function to skip slack message sending in some cnditions
* and log the message instead. By default skips in test environment
*/
static logCondition: () => boolean;
/**
* Username to send message with, default: 'slackbot'
*/
static username: string;
constructor(init?: {text?: string, channel?: string});
/** Sets fallback for the first attachment */
summary(fallback: string): this;
text(text: string): this;
channel(channelName: string): this;
attachment(attachments: MessageAttachment | MessageAttachment[]): this;
action(actions: AttachmentAction | AttachmentAction[]): this;
/**
* Add an attachment with stats as fields
* By default: ignores undefined values
*/
stats(
title: string,
statsKeyValue: {[statTitle: string]: string | number | boolean | object},
opts?: {extraProps?: Partial<MessageAttachment>, ignoreUndefined?: boolean}
): this;
/**
* Add an error as an attachement to the slack message
* Also automatically adds a button to create issue on github
* if a `bugs.url` property exists in package.json
*/
error(err: Error, opts?: {label?: string, title?: string}): this;
/**
* @param linkOrEmoji Url of image to use as icon or string for emoji
*/
icon(linkOrEmoji: string): this;
username(name: string): this;
button(text: string, url: string, opts?: {style?: string}): this;
send(opts?: {defaultAttachment?: boolean, extraProps?: object}): Promise<void>;
static postMessage(text: string, opts?: {
channel?: string;
attachments?: MessageAttachment[],
/**
* Will overwrite properties, use carefully
*/
extraProps?: object,
/**
* default true
*/
defaultAttachment?: boolean,
}): Promise<void>;
/**
* Webhook is given priority over legacy tokens
* @param webhook
*/
static setWebhook(webhook: string): void;
static setToken(token: string): void;
}
namespace TeamsTypes {
interface Image {
/** URL of the image */
image?: string;
title?: string;
}
interface commonInputFields {
id?: string;
isRequired?: boolean;
title?: string;
value?: string;
}
interface TextInput extends commonInputFields {
"@type": 'TextInput';
isMultiline?: boolean;
maxLength?: number;
}
interface DateInput extends commonInputFields {
"@type": 'DateInput';
includeTime?: boolean;
}
interface MultichoiceInput extends commonInputFields {
"@type": 'MultichoiceInput';
choices?: Array<{display: string, value: string}>;
isMultiSelect?: boolean;
style?: 'normal' | 'expanded';
}
/** To use input value `{{<id of input>.value}}` */
type Input = TextInput | DateInput | MultichoiceInput;
type OS = 'default' | 'windows' | 'iOS' | 'Android';
interface OpenUriAction {
"@type": 'OpenUri';
name: string;
targets: Array<{os: OS, uri: string}>;
}
interface HttpPOSTAction {
"@type": 'HttpPOST';
name: string;
target: string;
headers?: Array<{name: string, value: string}>;
body: string;
/** default: `application/json` */
bodyContentType?: string;
}
interface ActionCardAction {
"@type": 'ActionCard';
name: string;
inputs: Input[];
actions: Array<OpenUriAction | HttpPOSTAction>;
}
type Action = OpenUriAction | HttpPOSTAction | ActionCardAction;
interface Section {
title?: string;
/** When set to `true`, the `startGroup` property marks the start of a logical group of information. */
startGroup?: boolean;
activityImage?: string;
activityTitle?: string;
activitySubtitle?: string;
activityText?: string;
/** Use `heroImage` to make an image the centerpiece of your card. */
heroImage?: Image;
text?: string;
facts?: Array<{name: string, value: string}>;
images?: Image[];
potentialAction?: Action[];
}
interface MessageCard {
summary?: string;
themeColor?: string;
title?: string;
text?: string;
sections?: Section[];
potentialAction?: Action[];
}
}
class Teams extends Notify {
/**
* Overwrite this function to skip slack message sending in some cnditions
* and log the message instead. By default skips in test environment
*/
static logCondition: () => boolean;
/** default channel to use, (default: 'default') */
static defaultChannel: string;
constructor(init?: {text?: string, channel?: string});
username(name: string): this;
icon(linkOrEmoji: string): this;
channel(channel: string): this;
summary(summary: string): this;
/** @param color Hex Code */
color(color: string): this;
title(title: string): this;
text(text: string): this;
attachment(sections: TeamsTypes.Section | TeamsTypes.Section[]): this;
action(actions: TeamsTypes.Action | TeamsTypes.Action[]): this;
/**
* Add a section with facts
* By default: ignores undefined values
*/
stats(
title: string,
statsKeyValue: {[statTitle: string]: string | number | boolean | object},
opts?: {ignoreUndefined?: boolean}
): this;
/**
* Creates an error as MessageCard
* Also automatically adds a button to create issue,
* if a `bugs.url` property exists in package.json
*/
error(err: Error, opts?: {label?: string, title?: string}): this;
button(text: string, url: string): this;
send(opts?: {defaultAttachment?: boolean}): Promise<void>;
static postMessage(message: TeamsTypes.MessageCard, opts?: {
channel?: string;
/** default `true` */
defaultAttachment?: boolean,
}): Promise<void>;
/** @param channel default: `Teams.defaultChannel` */
static setWebhook(webhook: string, channel?: string): void;
}
export default Slack;
export {
MessageAttachment,
AttachmentAction,
Slack,
TeamsTypes,
Teams,
};
}