@microsoft/omnichannel-chat-sdk
Version:
Microsoft Omnichannel Chat SDK
52 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isJsonObject = exports.getRuntimeId = exports.isNotEmpty = exports.isClientIdNotFoundErrorMessage = exports.isCustomerMessage = exports.isSystemMessage = void 0;
var ACSParticipantDisplayName_1 = require("../core/messaging/ACSParticipantDisplayName");
var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
var ocsdk_1 = require("@microsoft/ocsdk");
var isSystemMessage = function (message) {
var messageType = message.messageType, properties = message.properties;
var conditionV1 = messageType === MessageType_1.default.UserMessage
&& properties
&& properties.tags
&& properties.tags.includes("system");
var conditionV2 = message.tags && message.tags.includes("system");
return conditionV1 || conditionV2 || false;
};
exports.isSystemMessage = isSystemMessage;
var isCustomerMessage = function (message) {
var sender = message.sender;
var conditionV1 = sender && sender.id && sender.id.includes('contacts/8:');
var conditionV2 = sender && sender.displayName && sender.displayName === ACSParticipantDisplayName_1.default.Customer;
return conditionV1 || conditionV2 || false;
};
exports.isCustomerMessage = isCustomerMessage;
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
var isClientIdNotFoundErrorMessage = function (e) {
var _a, _b, _c;
return ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status) === 401
&& ((_c = (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.message) === "UserId not found";
};
exports.isClientIdNotFoundErrorMessage = isClientIdNotFoundErrorMessage;
var isNotEmpty = function (value) {
return value !== null && value !== undefined && value.trim() !== '';
};
exports.isNotEmpty = isNotEmpty;
var getRuntimeId = function (externalRuntimeId) {
if (externalRuntimeId !== null && (0, exports.isNotEmpty)(externalRuntimeId)) {
return externalRuntimeId;
}
return (0, ocsdk_1.uuidv4)();
};
exports.getRuntimeId = getRuntimeId;
var isJsonObject = function (input) {
try {
JSON.parse(input);
return true;
}
catch (_a) {
return false;
}
};
exports.isJsonObject = isJsonObject;
//# sourceMappingURL=utilities.js.map