bkper-js 1.33.0 → 1.33.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
@@ -1482,17 +1482,11 @@ export declare class Conversation {
1482
1482
  */
1483
1483
  getMessages(): Promise<Message[]>;
1484
1484
  /**
1485
+ * @param message The Message to send to the Conversation
1485
1486
  *
1486
- * @param message The Message to add to this Conversation
1487
- *
1488
- * @returns This Conversation, for chaining
1489
- */
1490
- addMessage(message: Message): Conversation;
1491
- /**
1492
- *
1493
- * @return The updated Conversation object
1487
+ * @returns The updated Conversation object
1494
1488
  */
1495
- send(): Promise<Conversation>;
1489
+ send(message: Message): Promise<Conversation>;
1496
1490
  }
1497
1491
 
1498
1492
  /**
@@ -82,41 +82,36 @@ export class Conversation {
82
82
  });
83
83
  }
84
84
  /**
85
+ * @param message The Message to send to the Conversation
85
86
  *
86
- * @param message The Message to add to this Conversation
87
- *
88
- * @returns This Conversation, for chaining
89
- */
90
- addMessage(message) {
91
- if (!this.messages) {
92
- this.messages = [];
93
- }
94
- this.messages.push(message);
95
- this.payload.messages = this.messages.map(message => message.json());
96
- return this;
97
- }
98
- /**
99
- *
100
- * @return The updated Conversation object
87
+ * @returns The updated Conversation object
101
88
  */
102
- send() {
89
+ send(message) {
103
90
  return __awaiter(this, void 0, void 0, function* () {
104
91
  const agentId = this.agent.getId();
105
- if (agentId) {
106
- const updatedPayload = yield ConversationService.send(agentId, this.payload);
107
- this.payload = updatedPayload;
108
- if (updatedPayload.agent) {
109
- this.agent = new Agent(updatedPayload.agent);
92
+ if (!agentId) {
93
+ throw new Error('Agent id null!');
94
+ }
95
+ // Add message to payload
96
+ if (!this.payload.messages) {
97
+ this.payload.messages = [];
98
+ }
99
+ this.payload.messages.push(message.json());
100
+ // Send conversation
101
+ const updatedPayload = yield ConversationService.send(agentId, this.payload);
102
+ this.payload = updatedPayload;
103
+ // Update agent and messages
104
+ if (updatedPayload.agent) {
105
+ this.agent = new Agent(updatedPayload.agent);
106
+ }
107
+ if (updatedPayload.messages) {
108
+ if (!this.messages) {
109
+ this.messages = [];
110
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());
111
+ for (const messagePayload of updatedPayload.messages) {
112
+ this.messages.push(new Message(this, messagePayload));
119
113
  }
114
+ this.payload.messages = this.messages.map(m => m.json());
120
115
  }
121
116
  return this;
122
117
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.33.0",
3
+ "version": "1.33.1",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",