bkper-js 2.9.1 → 2.10.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.
@@ -1,200 +0,0 @@
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";
11
- import { Agent } from "./Agent.js";
12
- import { User } from "./User.js";
13
- import { Resource } from "./Resource.js";
14
- /**
15
- * Defines a Message on Bkper.
16
- *
17
- * A Message is a building block of a [[Conversation]].
18
- *
19
- * @public
20
- */
21
- export class Message extends Resource {
22
- constructor(conversation, payload, config) {
23
- super(payload || {});
24
- this.conversation = conversation;
25
- }
26
- /** @internal */
27
- getConfig() {
28
- return this.conversation.getConfig();
29
- }
30
- /**
31
- * Gets the Message universal identifier.
32
- *
33
- * @returns The Message universal identifier
34
- */
35
- getId() {
36
- return this.payload.id;
37
- }
38
- /**
39
- * Gets the Agent associated with the Message.
40
- *
41
- * @returns The Agent associated with the Message, if any
42
- */
43
- getAgent() {
44
- return this.payload.agent ? new Agent(this.payload.agent) : undefined;
45
- }
46
- /**
47
- * Gets the Conversation of the Message.
48
- *
49
- * @returns The Conversation of the Message
50
- */
51
- getConversation() {
52
- return this.conversation;
53
- }
54
- /**
55
- * Gets the User associated with the Message.
56
- *
57
- * @returns The User associated with the Message
58
- */
59
- getUser() {
60
- return this.payload.user ? new User(this.payload.user) : undefined;
61
- }
62
- /**
63
- * Gets the Date the Message was created.
64
- *
65
- * @returns The Date the Message was created
66
- */
67
- getCreatedAt() {
68
- return this.payload.createdAt
69
- ? new Date(new Number(this.payload.createdAt).valueOf())
70
- : undefined;
71
- }
72
- /**
73
- * Gets the text content of the Message.
74
- *
75
- * @returns The text content of the Message
76
- */
77
- getContent() {
78
- return this.payload.content;
79
- }
80
- /**
81
- * Sets the text content of the Message.
82
- *
83
- * @param content - The text content of the Message
84
- *
85
- * @returns This Message, for chaining
86
- */
87
- setContent(content) {
88
- this.payload.content = content;
89
- return this;
90
- }
91
- /**
92
- * Gets the custom properties stored in this Message.
93
- *
94
- * @returns The custom properties stored in this Message
95
- */
96
- getProperties() {
97
- return this.payload.properties != null
98
- ? Object.assign({}, this.payload.properties) : {};
99
- }
100
- /**
101
- * Sets the custom properties of the Message
102
- *
103
- * @param properties - Object with key/value pair properties
104
- *
105
- * @returns This Message, for chaining
106
- */
107
- setProperties(properties) {
108
- this.payload.properties = Object.assign({}, properties);
109
- return this;
110
- }
111
- /**
112
- * Gets the property value for given keys. First property found will be retrieved.
113
- *
114
- * @param keys - The property key
115
- *
116
- * @returns The retrieved property value
117
- */
118
- getProperty(...keys) {
119
- for (let index = 0; index < keys.length; index++) {
120
- const key = keys[index];
121
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
122
- if (value != null && value.trim() != "") {
123
- return value;
124
- }
125
- }
126
- return undefined;
127
- }
128
- /**
129
- * Sets a custom property in the Message.
130
- *
131
- * @param key - The property key
132
- * @param value - The property value
133
- *
134
- * @returns This Message, for chaining
135
- */
136
- setProperty(key, value) {
137
- if (key == null || key.trim() == "") {
138
- return this;
139
- }
140
- if (this.payload.properties == null) {
141
- this.payload.properties = {};
142
- }
143
- if (!value) {
144
- value = "";
145
- }
146
- this.payload.properties[key] = value;
147
- return this;
148
- }
149
- /**
150
- * Deletes a custom property from the Message.
151
- *
152
- * @param key - The property key
153
- *
154
- * @returns This Message, for chaining
155
- */
156
- deleteProperty(key) {
157
- this.setProperty(key, null);
158
- return this;
159
- }
160
- /**
161
- * Creates the Message and receives the synchronous Agent response.
162
- *
163
- * @returns The Agent response Message, with the created Message as its parent
164
- */
165
- create() {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- const conversationId = this.conversation.getId();
168
- if (!conversationId) {
169
- throw new Error("Conversation id null!");
170
- }
171
- const responsePayload = yield ConversationService.createMessage(conversationId, this.payload, this.getConfig());
172
- if (responsePayload.parent) {
173
- this.payload = responsePayload.parent;
174
- }
175
- const responseMessage = new Message(this.conversation, responsePayload);
176
- this.conversation.updateMessagesCache(this);
177
- this.conversation.updateMessagesCache(responseMessage);
178
- // Set conversation updatedAt
179
- if (responsePayload.createdAt) {
180
- this.conversation.setUpdatedAt(responsePayload.createdAt);
181
- }
182
- return this;
183
- });
184
- }
185
- /**
186
- * Streams the Message to the Bkper API.
187
- *
188
- * @returns A Promise that resolves when the streaming is complete
189
- */
190
- stream() {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- const conversationId = this.conversation.getId();
193
- if (!conversationId) {
194
- throw new Error("Conversation id null!");
195
- }
196
- ConversationService.streamMessage(conversationId, this.payload, this.getConfig());
197
- });
198
- }
199
- }
200
- //# sourceMappingURL=Message.js.map
@@ -1,42 +0,0 @@
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 getConversations(config) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- var _a;
14
- const response = yield new HttpApiRequest(`v5/apps/conversations`, config).setMethod('GET').fetch();
15
- return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
16
- });
17
- }
18
- export function createConversation(agentId, conversation, config) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const response = yield new HttpApiRequest(`v5/apps/${agentId}/conversations`, config).setMethod('POST').setPayload(conversation).fetch();
21
- return response.data;
22
- });
23
- }
24
- export function getMessages(conversationId, config) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- var _a;
27
- const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`, config).setMethod('GET').fetch();
28
- return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
29
- });
30
- }
31
- export function createMessage(conversationId, message, config) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`, config).setMethod('POST').setPayload(message).fetch();
34
- return response.data;
35
- });
36
- }
37
- export function streamMessage(conversationId, message, config) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- new HttpApiRequest(`v5/apps/conversations/${conversationId}/stream`, config).setMethod('POST').setPayload(message).fetch();
40
- });
41
- }
42
- //# sourceMappingURL=conversation-service.js.map