UNPKG

@botonic/react

Version:

Build Chatbots using React

47 lines 2.12 kB
import { __awaiter } from "tslib"; import { useContext } from 'react'; import { v7 as uuidv7 } from 'uuid'; import { WebchatContext } from './context'; export var EventAction; (function (EventAction) { EventAction["FeedbackKnowledgebase"] = "feedback_knowledgebase"; })(EventAction || (EventAction = {})); export var FeedbackOption; (function (FeedbackOption) { FeedbackOption["ThumbsUp"] = "thumbsUp"; FeedbackOption["ThumbsDown"] = "thumbsDown"; })(FeedbackOption || (FeedbackOption = {})); export function useTracking() { const { webchatState, trackEvent } = useContext(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, }) => __awaiter(this, void 0, void 0, function* () { if (!trackEvent) { return; } const args = { knowledgebaseInferenceId: inferenceId, feedbackBotInteractionId: botInteractionId, feedbackTargetId: messageId, feedbackGroupId: uuidv7(), 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 }; } //# sourceMappingURL=tracking.js.map