5
5
* Copyright (c) Microsoft Corporation. All rights reserved.
6
6
* Licensed under the MIT License.
7
7
*/
8
- import {
9
- ActionTypes ,
10
- AnimationCard ,
11
- Attachment ,
12
- AudioCard ,
13
- CardAction ,
14
- CardImage ,
15
- HeroCard ,
16
- MediaUrl ,
17
- OAuthCard ,
18
- ReceiptCard ,
19
- SigninCard ,
20
- ThumbnailCard ,
21
- VideoCard
22
- } from 'botframework-schema' ;
8
+ import { ActionTypes , AnimationCard , Attachment , AudioCard , CardAction , CardImage , HeroCard , MediaUrl , OAuthCard , ReceiptCard , SigninCard , ThumbnailCard , VideoCard } from 'botframework-schema' ;
23
9
24
10
/**
25
11
* A set of utility functions designed to assist with the formatting of the various card types a
@@ -105,10 +91,10 @@ export class CardFactory {
105
91
* @param other (Optional) additional properties to include on the card.
106
92
*/
107
93
public static animationCard (
108
- title : string ,
109
- media : ( MediaUrl | string ) [ ] ,
110
- buttons ?: ( CardAction | string ) [ ] ,
111
- other ?: Partial < AnimationCard >
94
+ title : string ,
95
+ media : ( MediaUrl | string ) [ ] ,
96
+ buttons ?: ( CardAction | string ) [ ] ,
97
+ other ?: Partial < AnimationCard >
112
98
) : Attachment {
113
99
return mediaCard ( CardFactory . contentTypes . animationCard , title , media , buttons , other ) ;
114
100
}
@@ -122,8 +108,8 @@ export class CardFactory {
122
108
*/
123
109
public static audioCard (
124
110
title : string ,
125
- media : ( MediaUrl | string ) [ ] ,
126
- buttons ?: ( CardAction | string ) [ ] ,
111
+ media : ( MediaUrl | string ) [ ] ,
112
+ buttons ?: ( CardAction | string ) [ ] ,
127
113
other ?: Partial < AudioCard >
128
114
) : Attachment {
129
115
return mediaCard ( CardFactory . contentTypes . audioCard , title , media , buttons , other ) ;
@@ -151,15 +137,15 @@ export class CardFactory {
151
137
*/
152
138
public static heroCard (
153
139
title : string ,
154
- images ?: ( CardImage | string ) [ ] ,
155
- buttons ?: ( CardAction | string ) [ ] ,
140
+ images ?: ( CardImage | string ) [ ] ,
141
+ buttons ?: ( CardAction | string ) [ ] ,
156
142
other ?: Partial < HeroCard >
157
143
) : Attachment ;
158
144
public static heroCard (
159
145
title : string ,
160
146
text : string ,
161
- images ?: ( CardImage | string ) [ ] ,
162
- buttons ?: ( CardAction | string ) [ ] ,
147
+ images ?: ( CardImage | string ) [ ] ,
148
+ buttons ?: ( CardAction | string ) [ ] ,
163
149
other ?: Partial < HeroCard >
164
150
) : Attachment ;
165
151
public static heroCard (
@@ -185,7 +171,7 @@ export class CardFactory {
185
171
public static oauthCard ( connectionName : string , title : string , text ?: string ) : Attachment {
186
172
const card : Partial < OAuthCard > = {
187
173
buttons : [
188
- { type : ActionTypes . Signin , title : title , value : undefined }
174
+ { type : ActionTypes . Signin , title : title , value : undefined , channelData : undefined }
189
175
] ,
190
176
connectionName : connectionName
191
177
} ;
@@ -213,7 +199,7 @@ export class CardFactory {
213
199
* @param text (Optional) additional text to include on the card.
214
200
*/
215
201
public static signinCard ( title : string , url : string , text ?: string ) : Attachment {
216
- const card : SigninCard = { buttons : [ { type : ActionTypes . Signin , title : title , value : url } ] } ;
202
+ const card : SigninCard = { buttons : [ { type : ActionTypes . Signin , title : title , value : url , channelData : undefined } ] } ;
217
203
if ( text ) { card . text = text ; }
218
204
219
205
return { contentType : CardFactory . contentTypes . signinCard , content : card } ;
@@ -235,15 +221,15 @@ export class CardFactory {
235
221
*/
236
222
public static thumbnailCard (
237
223
title : string ,
238
- images ?: ( CardImage | string ) [ ] ,
239
- buttons ?: ( CardAction | string ) [ ] ,
224
+ images ?: ( CardImage | string ) [ ] ,
225
+ buttons ?: ( CardAction | string ) [ ] ,
240
226
other ?: Partial < ThumbnailCard >
241
227
) : Attachment ;
242
228
public static thumbnailCard (
243
229
title : string ,
244
230
text : string ,
245
- images ?: ( CardImage | string ) [ ] ,
246
- buttons ?: ( CardAction | string ) [ ] ,
231
+ images ?: ( CardImage | string ) [ ] ,
232
+ buttons ?: ( CardAction | string ) [ ] ,
247
233
other ?: Partial < ThumbnailCard >
248
234
) : Attachment ;
249
235
public static thumbnailCard (
@@ -259,7 +245,7 @@ export class CardFactory {
259
245
images = text ;
260
246
text = undefined ;
261
247
}
262
- const card : Partial < ThumbnailCard > = { ...other } ;
248
+ const card : Partial < ThumbnailCard > = { ...other } ;
263
249
if ( title ) { card . title = title ; }
264
250
if ( text ) { card . text = text ; }
265
251
if ( images ) { card . images = CardFactory . images ( images ) ; }
@@ -277,8 +263,8 @@ export class CardFactory {
277
263
*/
278
264
public static videoCard (
279
265
title : string ,
280
- media : ( MediaUrl | string ) [ ] ,
281
- buttons ?: ( CardAction | string ) [ ] ,
266
+ media : ( MediaUrl | string ) [ ] ,
267
+ buttons ?: ( CardAction | string ) [ ] ,
282
268
other ?: Partial < VideoCard >
283
269
) : Attachment {
284
270
return mediaCard ( CardFactory . contentTypes . videoCard , title , media , buttons , other ) ;
@@ -292,13 +278,13 @@ export class CardFactory {
292
278
* 'messageBack' doesn't work properly in emulator.)
293
279
* @param actions Array of card actions or strings. Strings will be converted to `messageBack` actions.
294
280
*/
295
- public static actions ( actions : ( CardAction | string ) [ ] | undefined ) : CardAction [ ] {
281
+ public static actions ( actions : ( CardAction | string ) [ ] | undefined ) : CardAction [ ] {
296
282
const list : CardAction [ ] = [ ] ;
297
- ( actions || [ ] ) . forEach ( ( a : ( CardAction | string ) ) => {
283
+ ( actions || [ ] ) . forEach ( ( a : ( CardAction | string ) ) => {
298
284
if ( typeof a === 'object' ) {
299
285
list . push ( a ) ;
300
286
} else {
301
- list . push ( { type : ActionTypes . ImBack , value : a . toString ( ) , title : a . toString ( ) } ) ;
287
+ list . push ( { type : ActionTypes . ImBack , value : a . toString ( ) , title : a . toString ( ) , channelData : undefined } ) ;
302
288
}
303
289
} ) ;
304
290
@@ -309,9 +295,9 @@ export class CardFactory {
309
295
* Returns a properly formatted array of card images.
310
296
* @param images Array of card images or strings. Strings will be converted to card images.
311
297
*/
312
- public static images ( images : ( CardImage | string ) [ ] | undefined ) : CardImage [ ] {
298
+ public static images ( images : ( CardImage | string ) [ ] | undefined ) : CardImage [ ] {
313
299
const list : CardImage [ ] = [ ] ;
314
- ( images || [ ] ) . forEach ( ( img : ( CardImage | string ) ) => {
300
+ ( images || [ ] ) . forEach ( ( img : ( CardImage | string ) ) => {
315
301
if ( typeof img === 'object' ) {
316
302
list . push ( img ) ;
317
303
} else {
@@ -326,9 +312,9 @@ export class CardFactory {
326
312
* Returns a properly formatted array of media url objects.
327
313
* @param links Array of media url objects or strings. Strings will be converted to a media url object.
328
314
*/
329
- public static media ( links : ( MediaUrl | string ) [ ] | undefined ) : MediaUrl [ ] {
315
+ public static media ( links : ( MediaUrl | string ) [ ] | undefined ) : MediaUrl [ ] {
330
316
const list : MediaUrl [ ] = [ ] ;
331
- ( links || [ ] ) . forEach ( ( lnk : ( MediaUrl | string ) ) => {
317
+ ( links || [ ] ) . forEach ( ( lnk : ( MediaUrl | string ) ) => {
332
318
if ( typeof lnk === 'object' ) {
333
319
list . push ( lnk ) ;
334
320
} else {
@@ -344,11 +330,11 @@ export class CardFactory {
344
330
* @private
345
331
*/
346
332
function mediaCard ( contentType : string ,
347
- title : string ,
348
- media : ( MediaUrl | string ) [ ] ,
349
- buttons ?: ( CardAction | string ) [ ] ,
350
- other ?: any ) : Attachment {
351
- const card : VideoCard = { ...other } ;
333
+ title : string ,
334
+ media : ( MediaUrl | string ) [ ] ,
335
+ buttons ?: ( CardAction | string ) [ ] ,
336
+ other ?: any ) : Attachment {
337
+ const card : VideoCard = { ...other } ;
352
338
if ( title ) { card . title = title ; }
353
339
card . media = CardFactory . media ( media ) ;
354
340
if ( buttons ) { card . buttons = CardFactory . actions ( buttons ) ; }
0 commit comments