aimpress-chatbot/node_modules/botbuilder/lib/eventFactory.js
“SamoilenkoVadym” 55445dbc86
Some checks failed
Build and deploy Node.js app to Azure Web App - ChatBot2222 / build (push) Has been cancelled
Build and deploy Node.js app to Azure Web App - ChatBot2222 / deploy (push) Has been cancelled
Deploy bot to Azure
2025-04-27 19:55:19 +01:00

85 lines
No EOL
3.5 KiB
JavaScript

"use strict";
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventFactory = void 0;
const uuid_1 = require("uuid");
const botbuilder_core_1 = require("botbuilder-core");
const dayjs_1 = __importDefault(require("dayjs"));
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
dayjs_1.default.extend(timezone_1.default);
const handoffEventNames_1 = require("./handoffEventNames");
/**
* Contains utility methods for creating various event types.
*/
class EventFactory {
/**
* Create handoff initiation event.
*
* @param context The context object for the turn.
* @param handoffContext Agent hub-specific context.
* @param transcript Transcript of the conversation.
* @returns The handoff event activity.
*/
static createHandoffInitiation(context, handoffContext, transcript) {
if (!context) {
throw new TypeError('EventFactory.createHandoffInitiation(): Missing context.');
}
const handoffEvent = this.createHandoffEvent(handoffEventNames_1.HandoffEventNames.InitiateHandoff, handoffContext, context.activity.conversation);
handoffEvent.from = context.activity.from;
handoffEvent.relatesTo = botbuilder_core_1.TurnContext.getConversationReference(context.activity);
handoffEvent.replyToId = context.activity.id;
handoffEvent.serviceUrl = context.activity.serviceUrl;
handoffEvent.channelId = context.activity.channelId;
if (transcript) {
const attachment = {
content: transcript,
contentType: 'application/json',
name: 'Transcript',
};
handoffEvent.attachments.push(attachment);
}
return handoffEvent;
}
/**
* Create handoff status event.
*
* @param conversation Conversation being handed over.
* @param state State, possible values are: "accepted", "failed", "completed".
* @param message Additional message for failed handoff.
* @returns The handoff event activity.
*/
static createHandoffStatus(conversation, state, message) {
if (!conversation) {
throw new TypeError('EventFactory.createHandoffStatus(): missing conversation.');
}
if (!state) {
throw new TypeError('EventFactory.createHandoffStatus(): missing state.');
}
return this.createHandoffEvent(handoffEventNames_1.HandoffEventNames.HandoffStatus, { state, message }, conversation);
}
/**
* @private
*/
static createHandoffEvent(name, value, conversation) {
const handoffEvent = { type: botbuilder_core_1.ActivityTypes.Event };
handoffEvent.name = name;
handoffEvent.value = value;
handoffEvent.id = (0, uuid_1.v4)();
handoffEvent.timestamp = new Date(Date.now());
// The timestamp does not contain the local offset which is a known limitation of Date objects in JavaScript.
// Therefore, the localTimezone is included in the handoffEvent.
handoffEvent.localTimezone = dayjs_1.default.tz.guess();
handoffEvent.conversation = conversation;
handoffEvent.attachments = [];
handoffEvent.entities = [];
return handoffEvent;
}
}
exports.EventFactory = EventFactory;
//# sourceMappingURL=eventFactory.js.map