Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static getCardAttachment(type: string, input: any): Attachment {
const card: any = {};
for (const key of Object.keys(input)) {
const property: string = key.trim().toLowerCase();
const value: any = input[key];
switch (property) {
case 'tap':
card[property] = this.getCardAction(value);
break;
case 'image':
case 'images':
if (type === CardFactory.contentTypes.heroCard || type === CardFactory.contentTypes.thumbnailCard) {
if (!('images' in card)) {
card['images'] = [];
}
const imageList: string[] = this.normalizedToList(value).map((u): string => u.toString());
imageList.forEach( (u): any => card['images'].push({url : u}));
} else {
card['image'] = {url: value.toString()};
}
break;
case 'media':
if (!('media' in card)) {
card['media'] = [];
}
const mediaList: string[] = this.normalizedToList(value).map((u): string => u.toString());
const cards: Attachment[] = msg.attachments.filter((a: Attachment) => a.contentType === CardFactory.contentTypes.oauthCard);
if (cards.length === 0) {
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { Activity, SuggestedActions, Attachment, ActivityTypes, ActionTypes, CardAction } from 'botframework-schema';
import { MessageFactory, CardFactory } from 'botbuilder-core';
import { Diagnostic, DiagnosticSeverity } from './diagnostic';
import { ActivityChecker } from './activityChecker';
import { Evaluator } from './evaluator';
/**
* The ActivityFactory
* to generate text and then uses simple markdown semantics like chatdown to create Activity.
*/
export class ActivityFactory {
private static adaptiveCardType: string = CardFactory.contentTypes.adaptiveCard;
/**
* Generate the activity.
* @param lgResult string result from languageGenerator.
*/
public static createActivity(lgResult: any): Partial {
const diagnostics: Diagnostic[] = ActivityChecker.check(lgResult);
const errors: Diagnostic[] = diagnostics.filter((u: Diagnostic): boolean => u.severity === DiagnosticSeverity.Error);
if (errors !== undefined && errors.length > 0) {
throw new Error(`${ errors.join('\n') }`);
}
if (typeof lgResult === 'string') {
const structuredLGResult: any = this.parseStructuredLGResult(lgResult.trim());
return structuredLGResult === undefined ?
this.buildActivityFromText(lgResult.trim())