bkper-js 1.30.0 → 1.32.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
@@ -381,6 +381,14 @@ export declare class App {
381
381
  * @return The events bound to this App
382
382
  */
383
383
  getEvents(): EventType[] | undefined;
384
+ /**
385
+ * @return True if this App is conversational
386
+ */
387
+ isConversational(): boolean;
388
+ /**
389
+ * @return The conversation url of this App
390
+ */
391
+ chat(conversation: Conversation): Promise<Conversation | undefined>;
384
392
  /**
385
393
  * @return The logo url of this App
386
394
  */
@@ -634,6 +642,12 @@ export declare class Bkper {
634
642
  * @returns The retrieved list of Apps
635
643
  */
636
644
  static getApps(): Promise<App[]>;
645
+ /**
646
+ * Gets all [[Conversations]] available for the user.
647
+ *
648
+ * @returns The retrieved list of Conversations
649
+ */
650
+ static getConversations(): Promise<Conversation[]>;
637
651
  /**
638
652
  * Gets all [[Templates]] available for the user.
639
653
  *
@@ -1425,6 +1439,53 @@ export declare class Connection {
1425
1439
  remove(): Promise<Connection>;
1426
1440
  }
1427
1441
 
1442
+ /**
1443
+ * Defines a Conversation on Bkper.
1444
+ *
1445
+ * A Conversation represents an interaction between [[Users]] and [[Apps]].
1446
+ *
1447
+ * @public
1448
+ */
1449
+ export declare class Conversation {
1450
+ payload: bkper.Conversation;
1451
+
1452
+ constructor(payload?: bkper.Conversation);
1453
+ /**
1454
+ * @returns The wrapped plain json object
1455
+ */
1456
+ json(): bkper.Conversation;
1457
+ /**
1458
+ *
1459
+ * @returns The Conversation universal identifier
1460
+ */
1461
+ getId(): string | undefined;
1462
+ /**
1463
+ *
1464
+ * @returns The title of the Conversation
1465
+ */
1466
+ getTitle(): string | undefined;
1467
+ /**
1468
+ *
1469
+ * @returns The Agent associated to this Conversation
1470
+ */
1471
+ getAgent(): Agent | undefined;
1472
+ /**
1473
+ *
1474
+ * @returns The Date the Conversation was created
1475
+ */
1476
+ getCreatedAt(): Date | undefined;
1477
+ /**
1478
+ *
1479
+ * @returns The Date the Conversation was last updated
1480
+ */
1481
+ getUpdatedAt(): Date | undefined;
1482
+ /**
1483
+ *
1484
+ * @returns The Messages associated to this Conversation
1485
+ */
1486
+ getMessages(): Message[];
1487
+ }
1488
+
1428
1489
  /**
1429
1490
  * Decimal separator of numbers on book
1430
1491
  *
@@ -1471,7 +1532,7 @@ export declare class Event {
1471
1532
  */
1472
1533
  getUser(): User | undefined;
1473
1534
  /**
1474
- * @returns The user who performed the Event
1535
+ * @returns The Agent who performed the Event
1475
1536
  */
1476
1537
  getAgent(): Agent | undefined;
1477
1538
  /**
@@ -1931,6 +1992,48 @@ export declare class Integration {
1931
1992
  remove(): Promise<Integration>;
1932
1993
  }
1933
1994
 
1995
+ /**
1996
+ * Defines a Message on Bkper.
1997
+ *
1998
+ * A Message is a building block of a [[Conversation]].
1999
+ *
2000
+ * @public
2001
+ */
2002
+ export declare class Message {
2003
+ payload: bkper.Message;
2004
+
2005
+ constructor(conversation: Conversation, payload?: bkper.Message);
2006
+ /**
2007
+ * @returns The wrapped plain json object
2008
+ */
2009
+ json(): bkper.Message;
2010
+ /**
2011
+ *
2012
+ * @returns The Message universal identifier
2013
+ */
2014
+ getId(): string | undefined;
2015
+ /**
2016
+ *
2017
+ * @returns The Agent who created the Message, if any
2018
+ */
2019
+ getAgent(): Agent | undefined;
2020
+ /**
2021
+ *
2022
+ * @returns The User who created the Message, if any
2023
+ */
2024
+ getUser(): User | undefined;
2025
+ /**
2026
+ *
2027
+ * @returns The Date the Message was created
2028
+ */
2029
+ getCreatedAt(): Date | undefined;
2030
+ /**
2031
+ *
2032
+ * @returns The content text of the Message
2033
+ */
2034
+ getContent(): string | undefined;
2035
+ }
2036
+
1934
2037
  /**
1935
2038
  * Enum that represents a Month.
1936
2039
  *
package/lib/index.js CHANGED
@@ -14,9 +14,11 @@ export { Bkper } from './model/Bkper.js';
14
14
  export { Book } from './model/Book.js';
15
15
  export { Collection } from './model/Collection.js';
16
16
  export { Connection } from './model/Connection.js';
17
+ export { Conversation } from './model/Conversation.js';
17
18
  export { File } from './model/File.js';
18
19
  export { Group } from './model/Group.js';
19
20
  export { Integration } from './model/Integration.js';
21
+ export { Message } from './model/Message.js';
20
22
  export { Template } from './model/Template.js';
21
23
  export { Transaction } from './model/Transaction.js';
22
24
  export { TransactionList } from './model/TransactionList.js';
package/lib/model/App.js CHANGED
@@ -7,7 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { createApp, patchApp, updateApp } from "../service/app-service.js";
10
+ import * as AppService from '../service/app-service.js';
11
+ import { Conversation } from "./Conversation.js";
11
12
  /**
12
13
  * Defines an App on Bkper.
13
14
  *
@@ -71,6 +72,30 @@ export class App {
71
72
  getEvents() {
72
73
  return this.payload.events;
73
74
  }
75
+ /**
76
+ * @return True if this App is conversational
77
+ */
78
+ isConversational() {
79
+ return this.payload.conversational || false;
80
+ }
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
+ }
74
99
  /**
75
100
  * @return The logo url of this App
76
101
  */
@@ -132,7 +157,7 @@ export class App {
132
157
  */
133
158
  create() {
134
159
  return __awaiter(this, void 0, void 0, function* () {
135
- yield createApp(this.payload);
160
+ yield AppService.createApp(this.payload);
136
161
  return this;
137
162
  });
138
163
  }
@@ -141,7 +166,7 @@ export class App {
141
166
  */
142
167
  patch() {
143
168
  return __awaiter(this, void 0, void 0, function* () {
144
- yield patchApp(this.payload);
169
+ yield AppService.patchApp(this.payload);
145
170
  return this;
146
171
  });
147
172
  }
@@ -150,7 +175,7 @@ export class App {
150
175
  */
151
176
  update() {
152
177
  return __awaiter(this, void 0, void 0, function* () {
153
- yield updateApp(this.payload);
178
+ yield AppService.updateApp(this.payload);
154
179
  return this;
155
180
  });
156
181
  }
@@ -18,6 +18,7 @@ import { HttpApiRequest } from '../service/http-api-request.js';
18
18
  import { User } from "./User.js";
19
19
  import { Template } from "./Template.js";
20
20
  import { Collection } from "./Collection.js";
21
+ import { Conversation } from "./Conversation.js";
21
22
  /**
22
23
  * This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
23
24
  *
@@ -84,6 +85,17 @@ export class Bkper {
84
85
  return apps.map(app => new App(app));
85
86
  });
86
87
  }
88
+ /**
89
+ * Gets all [[Conversations]] available for the user.
90
+ *
91
+ * @returns The retrieved list of Conversations
92
+ */
93
+ static getConversations() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ let conversations = yield AppService.getConversations();
96
+ return conversations.map(c => new Conversation(c));
97
+ });
98
+ }
87
99
  /**
88
100
  * Gets all [[Templates]] available for the user.
89
101
  *
@@ -0,0 +1,73 @@
1
+ import { Agent } from "./Agent.js";
2
+ import { Message } from "./Message.js";
3
+ /**
4
+ * Defines a Conversation on Bkper.
5
+ *
6
+ * A Conversation represents an interaction between [[Users]] and [[Apps]].
7
+ *
8
+ * @public
9
+ */
10
+ export class Conversation {
11
+ constructor(payload) {
12
+ this.payload = payload || {};
13
+ }
14
+ /**
15
+ * @returns The wrapped plain json object
16
+ */
17
+ json() {
18
+ return Object.assign({}, this.payload);
19
+ }
20
+ /**
21
+ *
22
+ * @returns The Conversation universal identifier
23
+ */
24
+ getId() {
25
+ return this.payload.id;
26
+ }
27
+ /**
28
+ *
29
+ * @returns The title of the Conversation
30
+ */
31
+ getTitle() {
32
+ return this.payload.title;
33
+ }
34
+ /**
35
+ *
36
+ * @returns The Agent associated to this Conversation
37
+ */
38
+ getAgent() {
39
+ return this.payload.agent ? new Agent(this.payload.agent) : undefined;
40
+ }
41
+ /**
42
+ *
43
+ * @returns The Date the Conversation was created
44
+ */
45
+ getCreatedAt() {
46
+ return this.payload.createdAt ? new Date(this.payload.createdAt) : undefined;
47
+ }
48
+ /**
49
+ *
50
+ * @returns The Date the Conversation was last updated
51
+ */
52
+ getUpdatedAt() {
53
+ return this.payload.updatedAt ? new Date(this.payload.updatedAt) : undefined;
54
+ }
55
+ /**
56
+ *
57
+ * @returns The Messages associated to this Conversation
58
+ */
59
+ 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));
67
+ }
68
+ }
69
+ this.messages = messages;
70
+ return this.messages;
71
+ }
72
+ }
73
+ //# sourceMappingURL=Conversation.js.map
@@ -40,7 +40,7 @@ export class Event {
40
40
  return this.payload.user ? new User(this.payload.user) : undefined;
41
41
  }
42
42
  /**
43
- * @returns The user who performed the Event
43
+ * @returns The Agent who performed the Event
44
44
  */
45
45
  getAgent() {
46
46
  return this.payload.agent ? new Agent(this.payload.agent) : undefined;
@@ -0,0 +1,57 @@
1
+ import { Agent } from "./Agent.js";
2
+ import { User } from "./User.js";
3
+ /**
4
+ * Defines a Message on Bkper.
5
+ *
6
+ * A Message is a building block of a [[Conversation]].
7
+ *
8
+ * @public
9
+ */
10
+ export class Message {
11
+ constructor(conversation, payload) {
12
+ this.conversation = conversation;
13
+ this.payload = payload || {};
14
+ }
15
+ /**
16
+ * @returns The wrapped plain json object
17
+ */
18
+ json() {
19
+ return Object.assign({}, this.payload);
20
+ }
21
+ /**
22
+ *
23
+ * @returns The Message universal identifier
24
+ */
25
+ getId() {
26
+ return this.payload.id;
27
+ }
28
+ /**
29
+ *
30
+ * @returns The Agent who created the Message, if any
31
+ */
32
+ getAgent() {
33
+ return this.payload.agent ? new Agent(this.payload.agent) : undefined;
34
+ }
35
+ /**
36
+ *
37
+ * @returns The User who created the Message, if any
38
+ */
39
+ getUser() {
40
+ return this.payload.user ? new User(this.payload.user) : undefined;
41
+ }
42
+ /**
43
+ *
44
+ * @returns The Date the Message was created
45
+ */
46
+ getCreatedAt() {
47
+ return this.payload.createdAt ? new Date(this.payload.createdAt) : undefined;
48
+ }
49
+ /**
50
+ *
51
+ * @returns The content text of the Message
52
+ */
53
+ getContent() {
54
+ return this.payload.content;
55
+ }
56
+ }
57
+ //# sourceMappingURL=Message.js.map
@@ -22,6 +22,19 @@ export function getApps() {
22
22
  return appsJson;
23
23
  });
24
24
  }
25
+ export function getConversations() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ var _a;
28
+ const response = yield new HttpApiRequest(`v5/apps/conversations`).setMethod('GET').fetch();
29
+ return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
30
+ });
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
+ }
25
38
  export function createApp(app) {
26
39
  return __awaiter(this, void 0, void 0, function* () {
27
40
  var response = yield new HttpApiRequest(`v5/apps`).setMethod('POST').setPayload(app).fetch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.30.0",
3
+ "version": "1.32.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.1"
37
+ "@bkper/bkper-api-types": "^5.15.3"
38
38
  },
39
39
  "dependencies": {
40
40
  "@google-cloud/local-auth": "^3.0.1",