1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.EventFactory = void 0;
|
8 | const uuid_1 = require("uuid");
|
9 | const botbuilder_core_1 = require("botbuilder-core");
|
10 | const dayjs = require("dayjs");
|
11 | const timezone = require("dayjs/plugin/timezone");
|
12 | dayjs.extend(timezone);
|
13 | const handoffEventNames_1 = require("./handoffEventNames");
|
14 |
|
15 |
|
16 |
|
17 | class EventFactory {
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | static createHandoffInitiation(context, handoffContext, transcript) {
|
25 | if (!context) {
|
26 | throw new TypeError('EventFactory.createHandoffInitiation(): Missing context.');
|
27 | }
|
28 | const handoffEvent = this.createHandoffEvent(handoffEventNames_1.HandoffEventNames.InitiateHandoff, handoffContext, context.activity.conversation);
|
29 | handoffEvent.from = context.activity.from;
|
30 | handoffEvent.relatesTo = botbuilder_core_1.TurnContext.getConversationReference(context.activity);
|
31 | handoffEvent.replyToId = context.activity.id;
|
32 | handoffEvent.serviceUrl = context.activity.serviceUrl;
|
33 | handoffEvent.channelId = context.activity.channelId;
|
34 | if (transcript) {
|
35 | const attachment = {
|
36 | content: transcript,
|
37 | contentType: 'application/json',
|
38 | name: 'Transcript',
|
39 | };
|
40 | handoffEvent.attachments.push(attachment);
|
41 | }
|
42 | return handoffEvent;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | static createHandoffStatus(conversation, state, message) {
|
51 | if (!conversation) {
|
52 | throw new TypeError('EventFactory.createHandoffStatus(): missing conversation.');
|
53 | }
|
54 | if (!state) {
|
55 | throw new TypeError('EventFactory.createHandoffStatus(): missing state.');
|
56 | }
|
57 | return this.createHandoffEvent(handoffEventNames_1.HandoffEventNames.HandoffStatus, { state, message }, conversation);
|
58 | }
|
59 | |
60 |
|
61 |
|
62 | static createHandoffEvent(name, value, conversation) {
|
63 | const handoffEvent = { type: botbuilder_core_1.ActivityTypes.Event };
|
64 | handoffEvent.name = name;
|
65 | handoffEvent.value = value;
|
66 | handoffEvent.id = uuid_1.v4();
|
67 | handoffEvent.timestamp = new Date(Date.now());
|
68 |
|
69 |
|
70 | handoffEvent.localTimezone = dayjs.tz.guess();
|
71 | handoffEvent.conversation = conversation;
|
72 | handoffEvent.attachments = [];
|
73 | handoffEvent.entities = [];
|
74 | return handoffEvent;
|
75 | }
|
76 | }
|
77 | exports.EventFactory = EventFactory;
|
78 |
|
\ | No newline at end of file |