typings/lib2/messagev2/common/channelExtensions.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelCustomizable = exports.ChannelExtensions = exports.ChannelType = void 0;
const internal_1 = require("../internal");
var ChannelType;
(function (ChannelType) {
    ChannelType["facebook"] = "facebook";
    ChannelType["webhook"] = "webhook";
    ChannelType["slack"] = "slack";
    ChannelType["msteams"] = "msteams";
    ChannelType["cortana"] = "cortana";
    ChannelType["websdk"] = "websdk";
    ChannelType["androidsdk"] = "androidsdk";
    ChannelType["iossdk"] = "iossdk";
    ChannelType["twilio"] = "twilio";
    ChannelType["test"] = "test";
})(ChannelType = exports.ChannelType || (exports.ChannelType = {}));
/**
 * This represents a set of channel-specific extension properties.
 */
class ChannelExtensions extends Map {
    /**
     * Set a new channel-specific extension property.
     * @param {ChannelType} channelType - The channel type.
     * @param {string} propertyName - The name of the property.
     * @param {any} propertyValue - The value of the property.
     */
    setExtensionProperty(channelType, propertyName, propertyValue) {
        if (!channelType || !propertyName) {
            throw new Error('channelType and propertyName must be provided.');
        }
        let channelSpecificProperties = this[channelType];
        if (!channelSpecificProperties) {
            channelSpecificProperties = new Map();
            this[channelType] = channelSpecificProperties;
        }
        channelSpecificProperties[propertyName] = propertyValue;
    }
    /**
     * Get a channel-specific extension property.
     * @param {ChannelType} channelType - The channel type.
     * @param {string} propertyName - The name of the property.
     * @returns {any} The value of the property.
     */
    getExtensionProperty(channelType, propertyName) {
        if (!channelType || !propertyName) {
            throw new Error('channelType and propertyName must be provided.');
        }
        let channelSpecificProperties = this[channelType];
        return channelSpecificProperties ? channelSpecificProperties[propertyName] : undefined;
    }
    /**
     * Check whether a channel-specific extension property is defined or not.
     * @param {ChannelType} channelType - The channel type.
     * @param {string} propertyName - The name of the property.
     * @returns {boolean} flag that indicates if the property is set
     */
    hasExtensionProperty(channelType, propertyName) {
        if (!channelType || !propertyName) {
            throw new Error('channelType and propertyName must be provided.');
        }
        let channelSpecificProperties = this[channelType];
        return channelSpecificProperties === null || channelSpecificProperties === void 0 ? void 0 : channelSpecificProperties.has(propertyName);
    }
}
exports.ChannelExtensions = ChannelExtensions;
/**
 * Abstract class that can be extended by message objects that support channel extensions
 */
class ChannelCustomizable {
    /**
     * Deserialize nested object properties into corresponding class instances
     */
    deserializeNestedProperties() {
        if (this.channelExtensions) {
            this.channelExtensions = internal_1.MessageUtil.deserializeChannelExtensions(this.channelExtensions);
        }
    }
    /**
     * Gets the channel extensions
     * @returns {ChannelExtensions} The channel extensions
     */
    getChannelExtensions() {
        return this.channelExtensions;
    }
    /**
     * Get the value of a channel extension property
     * @param {ChannelType} channelType - The channel type.
     * @param {string} propertyName - The name of the property.
     * @returns {any} The property value
     */
    getChannelExtensionProperty(channelType, propertyName) {
        var _a;
        return (_a = this.channelExtensions) === null || _a === void 0 ? void 0 : _a.getExtensionProperty(channelType, propertyName);
    }
    /**
     * Sets a channel-specific extension property
     * @param {ChannelType} channelType - The channel type.
     * @param {string} propertyName - The name of the property.
     * @param {any} propertyValue - The value of the property.
     * @returns The current instance of this class.
     */
    setChannelExtensionProperty(channelType, propertyName, propertyValue) {
        if (!this.channelExtensions) {
            this.channelExtensions = new ChannelExtensions();
        }
        this.channelExtensions.setExtensionProperty(channelType, propertyName, propertyValue);
        return this;
    }
}
exports.ChannelCustomizable = ChannelCustomizable;