@botonic/react
Version:
Build Chatbots using React
61 lines • 3.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFullMimeWhitelist = exports.getMediaType = exports.isAllowedSize = exports.readDataURL = exports.isMedia = exports.INPUT_MEDIA_TYPES = exports.isButtonMessage = exports.isCustom = exports.isCarousel = exports.isContact = exports.isLocation = exports.isDocument = exports.isVideo = exports.isImage = exports.isAudio = exports.isPostback = exports.isText = exports.isOfType = void 0;
const core_1 = require("@botonic/core");
const constants_1 = require("./constants");
const isOfType = (msgType, type) => msgType === type;
exports.isOfType = isOfType;
const isText = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.TEXT);
exports.isText = isText;
const isPostback = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.POSTBACK);
exports.isPostback = isPostback;
const isAudio = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.AUDIO);
exports.isAudio = isAudio;
const isImage = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.IMAGE);
exports.isImage = isImage;
const isVideo = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.VIDEO);
exports.isVideo = isVideo;
const isDocument = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.DOCUMENT);
exports.isDocument = isDocument;
const isLocation = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.LOCATION);
exports.isLocation = isLocation;
const isContact = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.CONTACT);
exports.isContact = isContact;
const isCarousel = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.CAROUSEL);
exports.isCarousel = isCarousel;
const isCustom = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.CUSTOM);
exports.isCustom = isCustom;
const isButtonMessage = msg => (0, exports.isOfType)(msg.type, core_1.INPUT.BUTTON_MESSAGE);
exports.isButtonMessage = isButtonMessage;
exports.INPUT_MEDIA_TYPES = [
core_1.INPUT.AUDIO,
core_1.INPUT.IMAGE,
core_1.INPUT.VIDEO,
core_1.INPUT.DOCUMENT,
];
const isMedia = message => exports.INPUT_MEDIA_TYPES.some(type => (0, exports.isOfType)(message.type, type));
exports.isMedia = isMedia;
// TODO: Centralize handling attachments in class
const readDataURL = file => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
exports.readDataURL = readDataURL;
const isAllowedSize = fileSize => {
const maxAllowedBytesSize = constants_1.MAX_ALLOWED_SIZE_MB * 1024 * 1024;
if (fileSize > maxAllowedBytesSize)
return false;
return true;
};
exports.isAllowedSize = isAllowedSize;
const getMediaType = fileType => {
return Object.entries(constants_1.MIME_WHITELIST)
.filter(([_, formatsForType]) => formatsForType.includes(fileType))
.map(([type, _]) => type)[0];
};
exports.getMediaType = getMediaType;
const getFullMimeWhitelist = () => Object.values(constants_1.MIME_WHITELIST).map(acceptedFormatsForType => acceptedFormatsForType.join(','));
exports.getFullMimeWhitelist = getFullMimeWhitelist;
//# sourceMappingURL=message-utils.js.map
;