import {Channel, QuickReplyButton} from "./channel"; export class KikExtension extends Channel { text(text: String, quickReplies?: QuickReplyButton[]){ const template: any = { type : "text", body : text }; this.appendQuickReplyTemplate(template, quickReplies); return template; } image(url, quickReplies?: QuickReplyButton[]){ const template = { type : "picture", payload: { picUrl : url } } this.appendQuickReplyTemplate(template, quickReplies); return template; } genericTemplate(templates){ return templates.reduce ((a, b) =>{ return a.concat(b); }); } genericItem(title, subtitle, assetId, imageUrl, actionUrl, buttons){ let body = []; body.push(this.text(title)); if (subtitle) body.push(this.text(subtitle)); if (actionUrl) body.push(this.url(actionUrl)); if (imageUrl) body.push(this.image(imageUrl, buttons)); return body; } url(url){ return { type : "link", url : url }; } private appendQuickReplyTemplate(template, quickReplies: QuickReplyButton[]){ if (quickReplies){ template.keyboards = []; for (var button of quickReplies){ template.keyboards.push([{ type : "suggested", text : button.title }]); } } } }