bkper-js 1.32.3 → 1.33.0

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
@@ -1451,6 +1451,11 @@ export declare class Conversation {
1451
1451
  * @returns The wrapped plain json object
1452
1452
  */
1453
1453
  json(): bkper.Conversation;
1454
+ /**
1455
+ *
1456
+ * @returns The Agent associated to this Conversation
1457
+ */
1458
+ getAgent(): Agent;
1454
1459
  /**
1455
1460
  *
1456
1461
  * @returns The Conversation universal identifier
@@ -1461,11 +1466,6 @@ export declare class Conversation {
1461
1466
  * @returns The title of the Conversation
1462
1467
  */
1463
1468
  getTitle(): string | undefined;
1464
- /**
1465
- *
1466
- * @returns The Agent associated to this Conversation
1467
- */
1468
- getAgent(): Agent | undefined;
1469
1469
  /**
1470
1470
  *
1471
1471
  * @returns The Date the Conversation was created
@@ -1489,6 +1489,7 @@ export declare class Conversation {
1489
1489
  */
1490
1490
  addMessage(message: Message): Conversation;
1491
1491
  /**
1492
+ *
1492
1493
  * @return The updated Conversation object
1493
1494
  */
1494
1495
  send(): Promise<Conversation>;
@@ -2047,6 +2048,47 @@ export declare class Message {
2047
2048
  * @returns This Message, for chaining
2048
2049
  */
2049
2050
  setContent(content: string): Message;
2051
+ /**
2052
+ * @returns The custom properties stored in this Message
2053
+ */
2054
+ getProperties(): {
2055
+ [key: string]: string;
2056
+ };
2057
+ /**
2058
+ * Sets the custom properties of the Message
2059
+ *
2060
+ * @param properties - Object with key/value pair properties
2061
+ *
2062
+ * @returns This Message, for chainning.
2063
+ */
2064
+ setProperties(properties: {
2065
+ [key: string]: string;
2066
+ }): Message;
2067
+ /**
2068
+ * Gets the property value for given keys. First property found will be retrieved.
2069
+ *
2070
+ * @param keys - The property key
2071
+ *
2072
+ * @returns The retrieved property value
2073
+ */
2074
+ getProperty(...keys: string[]): string | undefined;
2075
+ /**
2076
+ * Sets a custom property in the Message.
2077
+ *
2078
+ * @param key - The property key
2079
+ * @param value - The property value
2080
+ *
2081
+ * @returns This Message, for chainning.
2082
+ */
2083
+ setProperty(key: string, value: string | null): Message;
2084
+ /**
2085
+ * Deletes a custom property from the Message.
2086
+ *
2087
+ * @param key - The property key
2088
+ *
2089
+ * @returns This Message, for chainning.
2090
+ */
2091
+ deleteProperty(key: string): Message;
2050
2092
  }
2051
2093
 
2052
2094
  /**
@@ -28,6 +28,13 @@ export class Conversation {
28
28
  json() {
29
29
  return Object.assign({}, this.payload);
30
30
  }
31
+ /**
32
+ *
33
+ * @returns The Agent associated to this Conversation
34
+ */
35
+ getAgent() {
36
+ return this.agent;
37
+ }
31
38
  /**
32
39
  *
33
40
  * @returns The Conversation universal identifier
@@ -42,13 +49,6 @@ export class Conversation {
42
49
  getTitle() {
43
50
  return this.payload.title;
44
51
  }
45
- /**
46
- *
47
- * @returns The Agent associated to this Conversation
48
- */
49
- getAgent() {
50
- return this.payload.agent ? new Agent(this.payload.agent) : undefined;
51
- }
52
52
  /**
53
53
  *
54
54
  * @returns The Date the Conversation was created
@@ -96,13 +96,27 @@ export class Conversation {
96
96
  return this;
97
97
  }
98
98
  /**
99
+ *
99
100
  * @return The updated Conversation object
100
101
  */
101
102
  send() {
102
103
  return __awaiter(this, void 0, void 0, function* () {
103
104
  const agentId = this.agent.getId();
104
105
  if (agentId) {
105
- this.payload = yield ConversationService.send(agentId, this.payload);
106
+ const updatedPayload = yield ConversationService.send(agentId, this.payload);
107
+ this.payload = updatedPayload;
108
+ if (updatedPayload.agent) {
109
+ this.agent = new Agent(updatedPayload.agent);
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());
119
+ }
106
120
  }
107
121
  return this;
108
122
  });
@@ -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.3",
3
+ "version": "1.33.0",
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",