UNPKG

@botonic/react

Version:

Build Chatbots using React

51 lines 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useTracking = exports.FeedbackOption = exports.EventAction = void 0; const tslib_1 = require("tslib"); const react_1 = require("react"); const uuid_1 = require("uuid"); const context_1 = require("./context"); var EventAction; (function (EventAction) { EventAction["FeedbackKnowledgebase"] = "feedback_knowledgebase"; })(EventAction = exports.EventAction || (exports.EventAction = {})); var FeedbackOption; (function (FeedbackOption) { FeedbackOption["ThumbsUp"] = "thumbsUp"; FeedbackOption["ThumbsDown"] = "thumbsDown"; })(FeedbackOption = exports.FeedbackOption || (exports.FeedbackOption = {})); function useTracking() { const { webchatState, trackEvent } = (0, react_1.useContext)(context_1.WebchatContext); const getRequest = () => { const request = { session: Object.assign({}, webchatState.session), getUserCountry: () => { var _a; return ((_a = webchatState.session.user) === null || _a === void 0 ? void 0 : _a.country) || ''; }, getUserLocale: () => { var _a; return ((_a = webchatState.session.user) === null || _a === void 0 ? void 0 : _a.locale) || ''; }, getSystemLocale: () => { var _a; return ((_a = webchatState.session.user) === null || _a === void 0 ? void 0 : _a.system_locale) || ''; }, }; return request; }; const trackKnowledgebaseFeedback = ({ messageId, isUseful, botInteractionId, inferenceId, }) => tslib_1.__awaiter(this, void 0, void 0, function* () { if (!trackEvent) { return; } const args = { knowledgebaseInferenceId: inferenceId, feedbackBotInteractionId: botInteractionId, feedbackTargetId: messageId, feedbackGroupId: (0, uuid_1.v7)(), possibleOptions: [FeedbackOption.ThumbsDown, FeedbackOption.ThumbsUp], possibleValues: [0, 1], option: isUseful ? FeedbackOption.ThumbsUp : FeedbackOption.ThumbsDown, value: isUseful ? 1 : 0, }; const request = getRequest(); yield trackEvent(request, EventAction.FeedbackKnowledgebase, args); }); return { trackKnowledgebaseFeedback }; } exports.useTracking = useTracking; //# sourceMappingURL=tracking.js.map