bkper-js 1.32.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 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,19 @@ 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
+ * @returns This Conversation, for chaining
1487
+ */
1488
+ addMessage(message: Message): Conversation;
1489
+ /**
1490
+ * @return The conversation url of this App
1485
1491
  */
1486
- getMessages(): Message[];
1492
+ send(): Promise<Conversation>;
1487
1493
  }
1488
1494
 
1489
1495
  /**
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,47 @@ 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
+ * @returns This Conversation, for chaining
90
+ */
91
+ addMessage(message) {
92
+ if (!this.messages) {
93
+ this.messages = [];
68
94
  }
69
- this.messages = messages;
70
- return this.messages;
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
@@ -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.1",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",