bkper-js 1.31.0 → 1.32.1
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 +17 -3
- package/lib/model/App.js +10 -4
- package/lib/model/Conversation.js +51 -11
- package/lib/service/conversation-service.js +24 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -381,6 +381,10 @@ export declare class App {
|
|
|
381
381
|
* @return The events bound to this App
|
|
382
382
|
*/
|
|
383
383
|
getEvents(): EventType[] | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* @return True if this App is conversational
|
|
386
|
+
*/
|
|
387
|
+
isConversational(): boolean;
|
|
384
388
|
/**
|
|
385
389
|
* @return The logo url of this App
|
|
386
390
|
*/
|
|
@@ -1441,7 +1445,7 @@ export declare class Connection {
|
|
|
1441
1445
|
export declare class Conversation {
|
|
1442
1446
|
payload: bkper.Conversation;
|
|
1443
1447
|
|
|
1444
|
-
constructor(payload?: bkper.Conversation);
|
|
1448
|
+
constructor(payload?: bkper.Conversation, agent?: bkper.Agent);
|
|
1445
1449
|
/**
|
|
1446
1450
|
* @returns The wrapped plain json object
|
|
1447
1451
|
*/
|
|
@@ -1473,9 +1477,19 @@ export declare class Conversation {
|
|
|
1473
1477
|
getUpdatedAt(): Date | undefined;
|
|
1474
1478
|
/**
|
|
1475
1479
|
*
|
|
1476
|
-
* @returns The Messages
|
|
1480
|
+
* @returns The Messages in this Conversation
|
|
1481
|
+
*/
|
|
1482
|
+
getMessages(): Promise<Message[]>;
|
|
1483
|
+
/**
|
|
1484
|
+
*
|
|
1485
|
+
* @param message The Message to add to this Conversation
|
|
1486
|
+
* @returns This Conversation, for chaining
|
|
1487
|
+
*/
|
|
1488
|
+
addMessage(message: Message): Conversation;
|
|
1489
|
+
/**
|
|
1490
|
+
* @return The conversation url of this App
|
|
1477
1491
|
*/
|
|
1478
|
-
|
|
1492
|
+
send(): Promise<Conversation>;
|
|
1479
1493
|
}
|
|
1480
1494
|
|
|
1481
1495
|
/**
|
package/lib/model/App.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
10
|
+
import * as AppService from '../service/app-service.js';
|
|
11
11
|
/**
|
|
12
12
|
* Defines an App on Bkper.
|
|
13
13
|
*
|
|
@@ -71,6 +71,12 @@ export class App {
|
|
|
71
71
|
getEvents() {
|
|
72
72
|
return this.payload.events;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @return True if this App is conversational
|
|
76
|
+
*/
|
|
77
|
+
isConversational() {
|
|
78
|
+
return this.payload.conversational || false;
|
|
79
|
+
}
|
|
74
80
|
/**
|
|
75
81
|
* @return The logo url of this App
|
|
76
82
|
*/
|
|
@@ -132,7 +138,7 @@ export class App {
|
|
|
132
138
|
*/
|
|
133
139
|
create() {
|
|
134
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
yield createApp(this.payload);
|
|
141
|
+
yield AppService.createApp(this.payload);
|
|
136
142
|
return this;
|
|
137
143
|
});
|
|
138
144
|
}
|
|
@@ -141,7 +147,7 @@ export class App {
|
|
|
141
147
|
*/
|
|
142
148
|
patch() {
|
|
143
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
yield patchApp(this.payload);
|
|
150
|
+
yield AppService.patchApp(this.payload);
|
|
145
151
|
return this;
|
|
146
152
|
});
|
|
147
153
|
}
|
|
@@ -150,7 +156,7 @@ export class App {
|
|
|
150
156
|
*/
|
|
151
157
|
update() {
|
|
152
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
yield updateApp(this.payload);
|
|
159
|
+
yield AppService.updateApp(this.payload);
|
|
154
160
|
return this;
|
|
155
161
|
});
|
|
156
162
|
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import * as ConversationService from "../service/conversation-service.js";
|
|
1
11
|
import { Agent } from "./Agent.js";
|
|
2
12
|
import { Message } from "./Message.js";
|
|
3
13
|
/**
|
|
@@ -8,8 +18,11 @@ import { Message } from "./Message.js";
|
|
|
8
18
|
* @public
|
|
9
19
|
*/
|
|
10
20
|
export class Conversation {
|
|
11
|
-
constructor(payload) {
|
|
21
|
+
constructor(payload, agent) {
|
|
12
22
|
this.payload = payload || {};
|
|
23
|
+
if (agent) {
|
|
24
|
+
this.payload.agent = agent;
|
|
25
|
+
}
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
* @returns The wrapped plain json object
|
|
@@ -54,20 +67,47 @@ export class Conversation {
|
|
|
54
67
|
}
|
|
55
68
|
/**
|
|
56
69
|
*
|
|
57
|
-
* @returns The Messages
|
|
70
|
+
* @returns The Messages in this Conversation
|
|
58
71
|
*/
|
|
59
72
|
getMessages() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
if (this.messages != null) {
|
|
75
|
+
return this.messages;
|
|
76
|
+
}
|
|
77
|
+
const conversationId = this.getId();
|
|
78
|
+
if (conversationId) {
|
|
79
|
+
const messagePayloads = yield ConversationService.getMessages(conversationId);
|
|
80
|
+
this.payload.messages = messagePayloads;
|
|
81
|
+
this.messages = messagePayloads.map(message => new Message(this, message));
|
|
67
82
|
}
|
|
83
|
+
return this.messages || [];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param message The Message to add to this Conversation
|
|
89
|
+
* @returns This Conversation, for chaining
|
|
90
|
+
*/
|
|
91
|
+
addMessage(message) {
|
|
92
|
+
if (!this.messages) {
|
|
93
|
+
this.messages = [];
|
|
68
94
|
}
|
|
69
|
-
this.messages
|
|
70
|
-
|
|
95
|
+
this.messages.push(message);
|
|
96
|
+
this.payload.messages = this.messages.map(message => message.json());
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @return The conversation url of this App
|
|
101
|
+
*/
|
|
102
|
+
send() {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
var _a;
|
|
105
|
+
const agentId = (_a = this.getAgent()) === null || _a === void 0 ? void 0 : _a.getId();
|
|
106
|
+
if (agentId) {
|
|
107
|
+
this.payload = yield ConversationService.send(agentId, this.payload);
|
|
108
|
+
}
|
|
109
|
+
return this;
|
|
110
|
+
});
|
|
71
111
|
}
|
|
72
112
|
}
|
|
73
113
|
//# sourceMappingURL=Conversation.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { HttpApiRequest } from "./http-api-request.js";
|
|
11
|
+
export function getMessages(conversationId) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a;
|
|
14
|
+
const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`).setMethod('GET').fetch();
|
|
15
|
+
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function send(agentId, conversation) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const response = yield new HttpApiRequest(`v5/apps/${agentId}/conversations`).setMethod('POST').setPayload(conversation).fetch();
|
|
21
|
+
return response.data;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=conversation-service.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.1",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@bkper/bkper-api-types": "^5.15.
|
|
37
|
+
"@bkper/bkper-api-types": "^5.15.3"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@google-cloud/local-auth": "^3.0.1",
|