bkper-js 1.32.2 → 1.32.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +8 -6
- package/lib/model/Bkper.js +9 -2
- package/lib/model/Conversation.js +25 -14
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1445,11 +1445,17 @@ export declare class Connection {
|
|
|
1445
1445
|
export declare class Conversation {
|
|
1446
1446
|
payload: bkper.Conversation;
|
|
1447
1447
|
|
|
1448
|
-
|
|
1448
|
+
|
|
1449
|
+
constructor(agent: Agent, payload?: bkper.Conversation);
|
|
1449
1450
|
/**
|
|
1450
1451
|
* @returns The wrapped plain json object
|
|
1451
1452
|
*/
|
|
1452
1453
|
json(): bkper.Conversation;
|
|
1454
|
+
/**
|
|
1455
|
+
*
|
|
1456
|
+
* @returns The Agent associated to this Conversation
|
|
1457
|
+
*/
|
|
1458
|
+
getAgent(): Agent;
|
|
1453
1459
|
/**
|
|
1454
1460
|
*
|
|
1455
1461
|
* @returns The Conversation universal identifier
|
|
@@ -1460,11 +1466,6 @@ export declare class Conversation {
|
|
|
1460
1466
|
* @returns The title of the Conversation
|
|
1461
1467
|
*/
|
|
1462
1468
|
getTitle(): string | undefined;
|
|
1463
|
-
/**
|
|
1464
|
-
*
|
|
1465
|
-
* @returns The Agent associated to this Conversation
|
|
1466
|
-
*/
|
|
1467
|
-
getAgent(): Agent | undefined;
|
|
1468
1469
|
/**
|
|
1469
1470
|
*
|
|
1470
1471
|
* @returns The Date the Conversation was created
|
|
@@ -1488,6 +1489,7 @@ export declare class Conversation {
|
|
|
1488
1489
|
*/
|
|
1489
1490
|
addMessage(message: Message): Conversation;
|
|
1490
1491
|
/**
|
|
1492
|
+
*
|
|
1491
1493
|
* @return The updated Conversation object
|
|
1492
1494
|
*/
|
|
1493
1495
|
send(): Promise<Conversation>;
|
package/lib/model/Bkper.js
CHANGED
|
@@ -19,6 +19,7 @@ import { User } from "./User.js";
|
|
|
19
19
|
import { Template } from "./Template.js";
|
|
20
20
|
import { Collection } from "./Collection.js";
|
|
21
21
|
import { Conversation } from "./Conversation.js";
|
|
22
|
+
import { Agent } from "./Agent.js";
|
|
22
23
|
/**
|
|
23
24
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
24
25
|
*
|
|
@@ -92,8 +93,14 @@ export class Bkper {
|
|
|
92
93
|
*/
|
|
93
94
|
static getConversations() {
|
|
94
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const conversationPayloads = yield AppService.getConversations();
|
|
97
|
+
let conversations = [];
|
|
98
|
+
for (const payload of conversationPayloads) {
|
|
99
|
+
const agent = new Agent(payload.agent);
|
|
100
|
+
const conversation = new Conversation(agent, payload);
|
|
101
|
+
conversations.push(conversation);
|
|
102
|
+
}
|
|
103
|
+
return conversations;
|
|
97
104
|
});
|
|
98
105
|
}
|
|
99
106
|
/**
|
|
@@ -18,11 +18,9 @@ import { Message } from "./Message.js";
|
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
20
|
export class Conversation {
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(agent, payload) {
|
|
22
|
+
this.agent = agent;
|
|
22
23
|
this.payload = payload || {};
|
|
23
|
-
if (agent) {
|
|
24
|
-
this.payload.agent = agent;
|
|
25
|
-
}
|
|
26
24
|
}
|
|
27
25
|
/**
|
|
28
26
|
* @returns The wrapped plain json object
|
|
@@ -30,6 +28,13 @@ export class Conversation {
|
|
|
30
28
|
json() {
|
|
31
29
|
return Object.assign({}, this.payload);
|
|
32
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @returns The Agent associated to this Conversation
|
|
34
|
+
*/
|
|
35
|
+
getAgent() {
|
|
36
|
+
return this.agent;
|
|
37
|
+
}
|
|
33
38
|
/**
|
|
34
39
|
*
|
|
35
40
|
* @returns The Conversation universal identifier
|
|
@@ -44,13 +49,6 @@ export class Conversation {
|
|
|
44
49
|
getTitle() {
|
|
45
50
|
return this.payload.title;
|
|
46
51
|
}
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @returns The Agent associated to this Conversation
|
|
50
|
-
*/
|
|
51
|
-
getAgent() {
|
|
52
|
-
return this.payload.agent ? new Agent(this.payload.agent) : undefined;
|
|
53
|
-
}
|
|
54
52
|
/**
|
|
55
53
|
*
|
|
56
54
|
* @returns The Date the Conversation was created
|
|
@@ -98,14 +96,27 @@ export class Conversation {
|
|
|
98
96
|
return this;
|
|
99
97
|
}
|
|
100
98
|
/**
|
|
99
|
+
*
|
|
101
100
|
* @return The updated Conversation object
|
|
102
101
|
*/
|
|
103
102
|
send() {
|
|
104
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
|
|
106
|
-
const agentId = (_a = this.getAgent()) === null || _a === void 0 ? void 0 : _a.getId();
|
|
104
|
+
const agentId = this.agent.getId();
|
|
107
105
|
if (agentId) {
|
|
108
|
-
|
|
106
|
+
const updatedPayload = yield ConversationService.send(agentId, this.payload);
|
|
107
|
+
this.payload = updatedPayload;
|
|
108
|
+
if (updatedPayload.agent) {
|
|
109
|
+
this.agent = new Agent(updatedPayload.agent);
|
|
110
|
+
}
|
|
111
|
+
if (updatedPayload.messages) {
|
|
112
|
+
if (!this.messages) {
|
|
113
|
+
this.messages = [];
|
|
114
|
+
}
|
|
115
|
+
for (const messagePayload of updatedPayload.messages) {
|
|
116
|
+
this.messages.push(new Message(this, messagePayload));
|
|
117
|
+
}
|
|
118
|
+
this.payload.messages = this.messages.map(message => message.json());
|
|
119
|
+
}
|
|
109
120
|
}
|
|
110
121
|
return this;
|
|
111
122
|
});
|