Home Manual Reference Source Repository

es2015/LineMessages/index.js

import { ImagemapAction } from '../LineActions';
import { TemplateComponent } from '../LineTemplates';
export var LineMessageType;
(function (LineMessageType) {
    LineMessageType.TEXT = 'text';
    LineMessageType.IMAGE = 'image';
    LineMessageType.VIDEO = 'video';
    LineMessageType.AUDIO = 'audio';
    LineMessageType.LOCATION = 'location';
    LineMessageType.STICKER = 'sticker';
    LineMessageType.IMAGEMAP = 'imagemap';
    LineMessageType.TEMPLATE = 'template';
})(LineMessageType || (LineMessageType = {}));
/* eslint-enable no-unused-vars, space-infix-ops */
/**
 * Line Message
 * @see https://devdocs.line.me/en/#send-message-object
 */
export class LineMessage {
    /* eslint-enable no-undef */
    /** @ignore */
    constructor({ id = undefined, type, }) {
        /**
        * Message ID.
        * @type {string}
        */
        this.id = id;
        /**
         * Identifier for the type of source.
         * @type {string}
         */
        this.type = type;
    }
    /** @ignore */
    static createFromObject(params) {
        switch (params.type) {
            case LineMessageType.TEXT: {
                return TextMessage.createFromObject(params);
            }
            case LineMessageType.IMAGE: {
                return ImageMessage.createFromObject(params);
            }
            case LineMessageType.VIDEO: {
                return VideoMessage.createFromObject(params);
            }
            case LineMessageType.AUDIO: {
                return AudioMessage.createFromObject(params);
            }
            case LineMessageType.LOCATION: {
                return LocationMessage.createFromObject(params);
            }
            case LineMessageType.STICKER: {
                return StickerMessage.createFromObject(params);
            }
            case LineMessageType.IMAGEMAP: {
                return ImagemapMessage.createFromObject(params);
            }
            case LineMessageType.TEMPLATE: {
                return TemplateMessage.createFromObject(params);
            }
            default: {
                return new LineMessage({ id: params.id, type: params.type });
            }
        }
    }
}
/**
 * @see https://devdocs.line.me/en/#text-message
 */
export class TextMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.text  Message text.
     */
    constructor({ text }) {
        super({ type: LineMessageType.TEXT });
        /**
        * Message text.
        * @type {string}
        */
        this.text = text;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new TextMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#image-message
 */
export class ImageMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.originalContentUrl  Image URL. (JPEG / HTTPS)
     * @param {string} params.previewImageUrl     Preview image URL. (JPEG / HTTPS)
     */
    constructor({ originalContentUrl, previewImageUrl, }) {
        super({ type: LineMessageType.IMAGE });
        /**
         * Image URL. (JPEG / HTTPS)
         * @type {string}
         */
        this.originalContentUrl = originalContentUrl;
        /**
         * Preview image URL. (JPEG / HTTPS)
         * @type {string}
         */
        this.previewImageUrl = previewImageUrl;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new ImageMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#video-message
 */
export class VideoMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.originalContentUrl  URL of video file. (MP4 / HTTPS)
     * @param {string} params.previewImageUrl     Preview image URL. (JPEG / HTTPS)
     */
    constructor({ originalContentUrl, previewImageUrl, }) {
        super({ type: LineMessageType.VIDEO });
        /**
         * URL of video file. (MP4 / HTTPS)
         * @type {string}
         */
        this.originalContentUrl = originalContentUrl;
        /**
         * Preview image URL. (JPEG / HTTPS)
         * @type {string}
         */
        this.previewImageUrl = previewImageUrl;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new VideoMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#audio-message
 */
export class AudioMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.originalContentUrl  URL of audio file. (M4A / HTTPS)
     * @param {number} params.duration            Length of audio file (milliseconds)
     */
    constructor({ originalContentUrl, duration, }) {
        super({ type: LineMessageType.AUDIO });
        /**
         * URL of audio file. (M4A / HTTPS)
         * @type {string}
         */
        this.originalContentUrl = originalContentUrl;
        /**
         * Length of audio file (milliseconds)
         * @type {number}
         */
        this.duration = duration;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new AudioMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#location-message
 */
export class LocationMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.title              Title.
     * @param {string} params.address            Address.
     * @param {number} params.latitude           Latitude.
     * @param {number} params.longitude          Longitude.
     */
    constructor({ title, address, latitude, longitude, }) {
        super({ type: LineMessageType.LOCATION });
        /**
        * Title.
        * @type {string}
        */
        this.title = title;
        /**
         * Address.
         * @type {string}
         */
        this.address = address;
        /**
         * Latitude.
         * @type {number}
         */
        this.latitude = latitude;
        /**
         * Longitude.
         * @type {number}
         */
        this.longitude = longitude;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new LocationMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#sticker-message
 */
export class StickerMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.packageId         Package ID.
     * @param {string} params.stickerId         Sticker ID.
     */
    constructor({ packageId, stickerId, }) {
        super({ type: LineMessageType.STICKER });
        /**
        * Package ID.
        * @type {string}
        */
        this.packageId = packageId;
        /**
         * Sticker ID.
         * @type {string}
         */
        this.stickerId = stickerId;
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new StickerMessage(params);
        instance.id = params.id;
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#imagemap-message
 */
export class ImagemapMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.baseUrl                        Base URL (HTTPS)
     * @param {string} params.altText                        Alternative text
     * @param {Size} params.baseSize                         Base image size.
     * @param {ImagemapAction[] | Object[]}  params.actions  Action when tapped
     */
    constructor({ baseUrl, altText, baseSize, actions, }) {
        super({ type: LineMessageType.IMAGEMAP });
        /**
         * Base URL (HTTPS)
         * @type {string}
         */
        this.baseUrl = baseUrl;
        /**
         * Alternative text
         * @type {string}
         */
        this.altText = altText;
        /**
         * Base image size.
         * @type {Size}
         */
        this.baseSize = baseSize;
        /**
         * Action when tapped
         * @type {ImagemapAction[]}
         */
        this.actions = actions.map(action => ImagemapAction.createFromObject(action));
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new ImagemapMessage(params);
        return instance;
    }
}
/**
 * @see https://devdocs.line.me/en/#template-messages
 */
export class TemplateMessage extends LineMessage {
    /* eslint-enable no-undef */
    /**
     * Constructor
     * @param {Object} params
     * @param {string} params.altText                       Alternative text
     * @param {TemplateComponent | Object} params.template  Object with the contents of the template.
     */
    constructor({ altText, template, }) {
        super({ type: LineMessageType.TEMPLATE });
        /**
         * Alternative text
         * @type {string}
         */
        this.altText = altText;
        /**
         * Object with the contents of the template.
         * @type {TemplateComponent}
         */
        this.template = TemplateComponent.createFromObject(template);
    }
    /** @ignore */
    static createFromObject(params) {
        const instance = new TemplateMessage(params);
        return instance;
    }
}