es2015/LineTemplates/index.js
- import { TemplateAction } from '../LineActions';
- export var LineTemplateType;
- (function (LineTemplateType) {
- LineTemplateType.BUTTONS = 'buttons';
- LineTemplateType.CONFIRM = 'confirm';
- LineTemplateType.CAROUSEL = 'carousel';
- })(LineTemplateType || (LineTemplateType = {}));
- /* eslint-enable no-unused-vars, space-infix-ops */
- /**
- * @see https://devdocs.line.me/en/#template-messages
- */
- export class TemplateComponent {
- /* eslint-enable no-undef */
- /** @ignore */
- constructor({ type }) {
- /**
- * Identifier for the type of template.
- * @type {string}
- */
- this.type = type;
- }
- /** @ignore */
- static createFromObject(params) {
- switch (params.type) {
- case LineTemplateType.BUTTONS: {
- return new TemplateButtons(params);
- }
- case LineTemplateType.CONFIRM: {
- return new TemplateConfirm(params);
- }
- case LineTemplateType.CAROUSEL: {
- return new TemplateCarousel(params);
- }
- default: {
- return new TemplateComponent({ type: params.type });
- }
- }
- }
- }
- /**
- * @see https://devdocs.line.me/en/#buttons
- */
- export class TemplateButtons extends TemplateComponent {
- /* eslint-enable no-undef */
- /**
- * @param {Object} params
- * @param {string} [params.thumbnailImageUrl] Image URL (JPEG or PNG / HTTPS / 1:1.51)
- * @param {string} [params.title] Title (Max: 40 chars)
- * @param {string} params.text Message text (Max: 160 chars (no image, no title) / 60 chars)
- * @param {TemplateAction[] | any[]} params.actions Action when tapped (Max: 4)
- */
- constructor({ thumbnailImageUrl, title, text, actions }) {
- super({ type: LineTemplateType.BUTTONS });
- /**
- * Image URL (JPEG or PNG / HTTPS / 1:1.51)
- * @type {string}
- */
- this.thumbnailImageUrl = thumbnailImageUrl;
- /**
- * Title (Max: 40 chars)
- * @type {string}
- */
- this.title = title;
- /**
- * Message text (Max: 160 chars (no image, no title) / 60 chars)
- * @type {string}
- */
- this.text = text;
- /**
- * Action when tapped (Max: 4)
- * @type {TemplateAction[]}
- */
- this.actions = actions.map(action => TemplateAction.createFromObject(action));
- }
- }
- /**
- * @see https://devdocs.line.me/en/#confirm
- */
- export class TemplateConfirm extends TemplateComponent {
- /* eslint-enable no-undef */
- /**
- * @param {Object} params
- * @param {string} params.text Message text (Max: 240 chars)
- * @param {TemplateAction[] | any[]} params.actions Action when tapped (Max: 2)
- */
- constructor({ text, actions }) {
- super({ type: LineTemplateType.CONFIRM });
- /**
- * Message text (Max: 240 chars)
- * @type {string}
- */
- this.text = text;
- /**
- * Action when tapped (Max: 2)
- * @type {TemplateAction[]}
- */
- this.actions = actions.map(action => TemplateAction.createFromObject(action));
- }
- }
- /**
- * @see https://devdocs.line.me/en/#carousel
- */
- export class TemplateCarousel extends TemplateComponent {
- /* eslint-enable no-undef */
- /**
- * @param {Object} params
- * @param {TemplateColumn[] | any[]} params.columns Array of columns (Max: 5)
- */
- constructor({ columns }) {
- super({ type: LineTemplateType.CAROUSEL });
- /**
- * Array of columns (Max: 5)
- * @type {TemplateColumn[]}
- */
- this.columns = columns.map(column => TemplateColumn.createFromObject(column));
- }
- }
- /**
- * @see https://devdocs.line.me/en/#column-object
- */
- export class TemplateColumn {
- /* eslint-enable no-undef */
- /**
- * @param {Object} params
- * @param {string} [params.thumbnailImageUrl] Image URL (JPEG or PNG / HTTPS / 1:1.51)
- * @param {string} [params.title] Title (Max: 40 chars)
- * @param {string} params.text Message text (Max: 160 chars (no image, no title) / 60 chars)
- * @param {TemplateAction[] | any[]} params.actions Action when tapped (Max: 3)
- */
- constructor({ thumbnailImageUrl, title, text, actions }) {
- /**
- * Image URL (JPEG or PNG / HTTPS / 1:1.51)
- * @type {string}
- */
- this.thumbnailImageUrl = thumbnailImageUrl;
- /**
- * Title (Max: 40 chars)
- * @type {string}
- */
- this.title = title;
- /**
- * Message text (Max: 160 chars (no image, no title) / 60 chars)
- * @type {string}
- */
- this.text = text;
- /**
- * Action when tapped (Max: 3)
- * @type {TemplateAction[]}
- */
- this.actions = actions.map(action => TemplateAction.createFromObject(action));
- }
- /** @ignore */
- static createFromObject(params) {
- return new TemplateColumn(params);
- }
- }