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