File tree Expand file tree Collapse file tree 4 files changed +138
-54
lines changed Expand file tree Collapse file tree 4 files changed +138
-54
lines changed Original file line number Diff line number Diff line change 1
1
export interface TeamsPayload {
2
- '@type' : string ;
3
- '@context' : string ;
4
- themeColor : string ;
5
- title : string ;
6
- summary : string ;
7
- text ?: string ;
8
- sections ?: Section [ ] ;
9
- potentialAction ?: Action [ ] ;
2
+ type : string ;
3
+ attachments : Attachment [ ] ;
10
4
}
11
5
12
- interface Section {
13
- facts : Fact [ ] ;
6
+ interface Attachment {
7
+ contentType : string ;
8
+ contentUrl : unknown ;
9
+ content : AdaptiveCard ;
10
+ }
11
+
12
+ interface AdaptiveCard {
13
+ $schema : string ;
14
+ type : string ;
15
+ version : string ;
16
+ body : Element [ ] ;
17
+ actions : Action [ ] ;
18
+ backgroundImage : BackgroundImage ;
19
+ msteams : MSTeams ;
20
+ }
21
+
22
+ type Element = TextBlock | FactSet | ActionSet | ColumnSet | Column ;
23
+
24
+ interface TextBlock {
25
+ type : 'TextBlock' ;
26
+ text : string ;
27
+ weight ?: 'default' | 'lighter' | 'bolder' ;
28
+ size ?: 'default' | 'small' | 'medium' | 'large' | 'extraLarge' ;
14
29
}
15
30
16
31
interface Fact {
17
- name : string ;
32
+ title : string ;
18
33
value : string ;
19
34
}
20
35
36
+ interface FactSet {
37
+ type : 'FactSet' ;
38
+ facts : Fact [ ] ;
39
+ }
40
+
41
+ interface ActionSet {
42
+ type : 'ActionSet' ;
43
+ actions : Action [ ] ;
44
+ }
45
+
46
+ interface ColumnSet {
47
+ type : 'ColumnSet' ;
48
+ columns : Column [ ] ;
49
+ }
50
+
51
+ interface Column {
52
+ type : 'ColumnSet' ;
53
+ items : Element [ ] ;
54
+ }
55
+
21
56
interface Action {
22
- '@type' : string ;
23
- name : string ;
24
- targets : Target [ ] ;
57
+ type : string ;
58
+ title : string ;
59
+ url : string ;
60
+ }
61
+
62
+ interface BackgroundImage {
63
+ url : string ;
64
+ fillMode : 'RepeatHorizontally' ;
25
65
}
26
66
27
- interface Target {
28
- os : string ;
29
- uri : string ;
67
+ interface MSTeams {
68
+ width : 'Full' ;
30
69
}
Original file line number Diff line number Diff line change @@ -9,26 +9,49 @@ export const normalizeTeamsPayload = (
9
9
buttons : Button [ ] ,
10
10
) : TeamsPayload => {
11
11
return {
12
- '@type' : 'MessageCard' ,
13
- '@context' : 'https://schema.org/extensions' ,
14
- themeColor : color ,
15
- summary : title ,
16
- title,
17
- text,
18
- sections : [
12
+ type : 'message' ,
13
+ attachments : [
19
14
{
20
- facts : fields ,
15
+ contentType : 'application/vnd.microsoft.card.adaptive' ,
16
+ contentUrl : null ,
17
+ content : {
18
+ $schema :
19
+ 'http://adaptivecards.io/schemas/adaptive-card.json' ,
20
+ type : 'AdaptiveCard' ,
21
+ version : '1.5' ,
22
+ body : [
23
+ {
24
+ type : 'TextBlock' ,
25
+ text : title ,
26
+ size : 'large' ,
27
+ } ,
28
+ {
29
+ type : 'TextBlock' ,
30
+ text : text ,
31
+ } ,
32
+ {
33
+ type : 'FactSet' ,
34
+ facts : fields . map ( ( { name, value } ) => ( {
35
+ title : name ,
36
+ value,
37
+ } ) ) ,
38
+ } ,
39
+ ] ,
40
+ actions : buttons . map ( ( { label, url } ) => ( {
41
+ type : 'Action.OpenUrl' ,
42
+ title : label ,
43
+ url : url ,
44
+ } ) ) ,
45
+ msteams : {
46
+ width : 'Full' ,
47
+ } ,
48
+ backgroundImage : {
49
+ // TODO: Replace with base64 template, but no idea how that works...
50
+ url : `https://singlecolorimage.com/get/${ color } /1x3` ,
51
+ fillMode : 'RepeatHorizontally' ,
52
+ } ,
53
+ } ,
21
54
} ,
22
55
] ,
23
- potentialAction : buttons . map ( ( button ) => ( {
24
- '@type' : 'OpenUri' ,
25
- name : button . label ,
26
- targets : [
27
- {
28
- os : 'default' ,
29
- uri : button . url ,
30
- } ,
31
- ] ,
32
- } ) ) ,
33
56
} ;
34
57
} ;
You can’t perform that action at this time.
0 commit comments