bkper-js 1.32.4 → 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
1487
+ * @returns The updated Conversation object
1489
1488
  */
1490
- addMessage(message: Message): Conversation;
1491
- /**
1492
- *
1493
- * @return The updated Conversation object
1494
- */
1495
- send(): Promise<Conversation>;
1489
+ send(message: Message): Promise<Conversation>;
1496
1490
  }
1497
1491
 
1498
1492
  /**
@@ -2048,6 +2042,47 @@ export declare class Message {
2048
2042
  * @returns This Message, for chaining
2049
2043
  */
2050
2044
  setContent(content: string): Message;
2045
+ /**
2046
+ * @returns The custom properties stored in this Message
2047
+ */
2048
+ getProperties(): {
2049
+ [key: string]: string;
2050
+ };
2051
+ /**
2052
+ * Sets the custom properties of the Message
2053
+ *
2054
+ * @param properties - Object with key/value pair properties
2055
+ *
2056
+ * @returns This Message, for chainning.
2057
+ */
2058
+ setProperties(properties: {
2059
+ [key: string]: string;
2060
+ }): Message;
2061
+ /**
2062
+ * Gets the property value for given keys. First property found will be retrieved.
2063
+ *
2064
+ * @param keys - The property key
2065
+ *
2066
+ * @returns The retrieved property value
2067
+ */
2068
+ getProperty(...keys: string[]): string | undefined;
2069
+ /**
2070
+ * Sets a custom property in the Message.
2071
+ *
2072
+ * @param key - The property key
2073
+ * @param value - The property value
2074
+ *
2075
+ * @returns This Message, for chainning.
2076
+ */
2077
+ setProperty(key: string, value: string | null): Message;
2078
+ /**
2079
+ * Deletes a custom property from the Message.
2080
+ *
2081
+ * @param key - The property key
2082
+ *
2083
+ * @returns This Message, for chainning.
2084
+ */
2085
+ deleteProperty(key: string): Message;
2051
2086
  }
2052
2087
 
2053
2088
  /**
@@ -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
  });
@@ -63,5 +63,71 @@ export class Message {
63
63
  this.payload.content = content;
64
64
  return this;
65
65
  }
66
+ /**
67
+ * @returns The custom properties stored in this Message
68
+ */
69
+ getProperties() {
70
+ return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
71
+ }
72
+ /**
73
+ * Sets the custom properties of the Message
74
+ *
75
+ * @param properties - Object with key/value pair properties
76
+ *
77
+ * @returns This Message, for chainning.
78
+ */
79
+ setProperties(properties) {
80
+ this.payload.properties = Object.assign({}, properties);
81
+ return this;
82
+ }
83
+ /**
84
+ * Gets the property value for given keys. First property found will be retrieved.
85
+ *
86
+ * @param keys - The property key
87
+ *
88
+ * @returns The retrieved property value
89
+ */
90
+ getProperty(...keys) {
91
+ for (let index = 0; index < keys.length; index++) {
92
+ const key = keys[index];
93
+ let value = this.payload.properties != null ? this.payload.properties[key] : null;
94
+ if (value != null && value.trim() != '') {
95
+ return value;
96
+ }
97
+ }
98
+ return undefined;
99
+ }
100
+ /**
101
+ * Sets a custom property in the Message.
102
+ *
103
+ * @param key - The property key
104
+ * @param value - The property value
105
+ *
106
+ * @returns This Message, for chainning.
107
+ */
108
+ setProperty(key, value) {
109
+ if (key == null || key.trim() == '') {
110
+ return this;
111
+ }
112
+ if (this.payload.properties == null) {
113
+ this.payload.properties = {};
114
+ }
115
+ if (!value) {
116
+ value = '';
117
+ }
118
+ this.payload.properties[key] = value;
119
+ return this;
120
+ }
121
+ /**
122
+ * Deletes a custom property from the Message.
123
+ *
124
+ * @param key - The property key
125
+ *
126
+ * @returns This Message, for chainning.
127
+ */
128
+ deleteProperty(key) {
129
+ this.setProperty(key, null);
130
+ return this;
131
+ }
66
132
  }
67
133
  //# sourceMappingURL=Message.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.32.4",
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",
@@ -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.3"
37
+ "@bkper/bkper-api-types": "^5.16.0"
38
38
  },
39
39
  "dependencies": {
40
40
  "@google-cloud/local-auth": "^3.0.1",