bkper-js 1.32.0 → 1.32.2

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 CHANGED
@@ -385,10 +385,6 @@ export declare class App {
385
385
  * @return True if this App is conversational
386
386
  */
387
387
  isConversational(): boolean;
388
- /**
389
- * @return The conversation url of this App
390
- */
391
- chat(conversation: Conversation): Promise<Conversation | undefined>;
392
388
  /**
393
389
  * @return The logo url of this App
394
390
  */
@@ -1449,7 +1445,7 @@ export declare class Connection {
1449
1445
  export declare class Conversation {
1450
1446
  payload: bkper.Conversation;
1451
1447
 
1452
- constructor(payload?: bkper.Conversation);
1448
+ constructor(payload?: bkper.Conversation, agent?: bkper.Agent);
1453
1449
  /**
1454
1450
  * @returns The wrapped plain json object
1455
1451
  */
@@ -1481,9 +1477,20 @@ export declare class Conversation {
1481
1477
  getUpdatedAt(): Date | undefined;
1482
1478
  /**
1483
1479
  *
1484
- * @returns The Messages associated to this Conversation
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
+ *
1487
+ * @returns This Conversation, for chaining
1485
1488
  */
1486
- getMessages(): Message[];
1489
+ addMessage(message: Message): Conversation;
1490
+ /**
1491
+ * @return The updated Conversation object
1492
+ */
1493
+ send(): Promise<Conversation>;
1487
1494
  }
1488
1495
 
1489
1496
  /**
@@ -2029,9 +2036,16 @@ export declare class Message {
2029
2036
  getCreatedAt(): Date | undefined;
2030
2037
  /**
2031
2038
  *
2032
- * @returns The content text of the Message
2039
+ * @returns The text content of the Message
2033
2040
  */
2034
2041
  getContent(): string | undefined;
2042
+ /**
2043
+ *
2044
+ * @param content The text content of the Message
2045
+ *
2046
+ * @returns This Message, for chaining
2047
+ */
2048
+ setContent(content: string): Message;
2035
2049
  }
2036
2050
 
2037
2051
  /**
package/lib/model/App.js CHANGED
@@ -8,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import * as AppService from '../service/app-service.js';
11
- import { Conversation } from "./Conversation.js";
12
11
  /**
13
12
  * Defines an App on Bkper.
14
13
  *
@@ -78,24 +77,6 @@ export class App {
78
77
  isConversational() {
79
78
  return this.payload.conversational || false;
80
79
  }
81
- /**
82
- * @return The conversation url of this App
83
- */
84
- chat(conversation) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- if (!this.isConversational()) {
87
- throw new Error(`App ${this.getName()} is not conversational`);
88
- }
89
- const appId = this.getId();
90
- if (appId) {
91
- const response = yield AppService.chat(appId, conversation.json());
92
- if (response) {
93
- return new Conversation(response);
94
- }
95
- }
96
- return undefined;
97
- });
98
- }
99
80
  /**
100
81
  * @return The logo url of this App
101
82
  */
@@ -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,48 @@ export class Conversation {
54
67
  }
55
68
  /**
56
69
  *
57
- * @returns The Messages associated to this Conversation
70
+ * @returns The Messages in this Conversation
58
71
  */
59
72
  getMessages() {
60
- if (this.messages !== undefined) {
61
- return this.messages;
62
- }
63
- let messages = [];
64
- if (this.payload.messages) {
65
- for (const message of this.payload.messages) {
66
- messages.push(new Message(this, message));
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
+ *
90
+ * @returns This Conversation, for chaining
91
+ */
92
+ addMessage(message) {
93
+ if (!this.messages) {
94
+ this.messages = [];
68
95
  }
69
- this.messages = messages;
70
- return this.messages;
96
+ this.messages.push(message);
97
+ this.payload.messages = this.messages.map(message => message.json());
98
+ return this;
99
+ }
100
+ /**
101
+ * @return The updated Conversation object
102
+ */
103
+ send() {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ var _a;
106
+ const agentId = (_a = this.getAgent()) === null || _a === void 0 ? void 0 : _a.getId();
107
+ if (agentId) {
108
+ this.payload = yield ConversationService.send(agentId, this.payload);
109
+ }
110
+ return this;
111
+ });
71
112
  }
72
113
  }
73
114
  //# sourceMappingURL=Conversation.js.map
@@ -48,10 +48,20 @@ export class Message {
48
48
  }
49
49
  /**
50
50
  *
51
- * @returns The content text of the Message
51
+ * @returns The text content of the Message
52
52
  */
53
53
  getContent() {
54
54
  return this.payload.content;
55
55
  }
56
+ /**
57
+ *
58
+ * @param content The text content of the Message
59
+ *
60
+ * @returns This Message, for chaining
61
+ */
62
+ setContent(content) {
63
+ this.payload.content = content;
64
+ return this;
65
+ }
56
66
  }
57
67
  //# sourceMappingURL=Message.js.map
@@ -29,12 +29,6 @@ export function getConversations() {
29
29
  return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
30
30
  });
31
31
  }
32
- export function chat(appId, conversation) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const response = yield new HttpApiRequest(`v5/apps/${appId}/conversations`).setMethod('POST').setPayload(conversation).fetch();
35
- return response.data;
36
- });
37
- }
38
32
  export function createApp(app) {
39
33
  return __awaiter(this, void 0, void 0, function* () {
40
34
  var response = yield new HttpApiRequest(`v5/apps`).setMethod('POST').setPayload(app).fetch();
@@ -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.32.0",
3
+ "version": "1.32.2",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",