@green-api/greenapi-integration 0.4.0 → 0.5.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.
@@ -120,12 +120,11 @@ export declare abstract class BaseAdapter<TPlatformWebhook, TPlatformMessage, TU
120
120
  * Creates a new instance with specified settings.
121
121
  *
122
122
  * @param instance - The instance configuration
123
- * @param userCred - User credentials
124
123
  * @returns Promise resolving to the created instance
125
124
  * @throws {NotFoundError} If user is not found
126
125
  * @throws {IntegrationError} If instance creation fails
127
126
  */
128
- createInstance(instance: Instance, userCred: any): Promise<TInstance>;
127
+ createInstance(instance: Instance): Promise<TInstance>;
129
128
  /**
130
129
  * Removes an instance by ID.
131
130
  *
@@ -157,8 +156,6 @@ export declare abstract class BaseAdapter<TPlatformWebhook, TPlatformMessage, TU
157
156
  *
158
157
  * @param userCred - User credentials
159
158
  * @param data - User data
160
- * @throws {BadRequestError} If user already exists
161
- * @throws {IntegrationError} If creation fails
162
159
  */
163
160
  createUser(userCred: any, data: any): Promise<TUser>;
164
161
  }
@@ -148,17 +148,12 @@ class BaseAdapter {
148
148
  * Creates a new instance with specified settings.
149
149
  *
150
150
  * @param instance - The instance configuration
151
- * @param userCred - User credentials
152
151
  * @returns Promise resolving to the created instance
153
152
  * @throws {NotFoundError} If user is not found
154
153
  * @throws {IntegrationError} If instance creation fails
155
154
  */
156
- async createInstance(instance, userCred) {
155
+ async createInstance(instance) {
157
156
  try {
158
- const user = await this.storage.findUser(userCred);
159
- if (!user) {
160
- throw new errors_1.NotFoundError("No user with such credentials");
161
- }
162
157
  const client = this.createGreenApiClient(instance);
163
158
  try {
164
159
  await client.getSettings();
@@ -166,7 +161,7 @@ class BaseAdapter {
166
161
  catch (error) {
167
162
  throw new errors_1.IntegrationError(`Failed to get settings for instance ${instance.idInstance}: ${error.message}`, "INTEGRATION_ERROR");
168
163
  }
169
- const createdInstance = await this.storage.createInstance(instance, user.id);
164
+ const createdInstance = await this.storage.createInstance(instance);
170
165
  if (instance.settings) {
171
166
  await client.setSettings(instance.settings);
172
167
  }
@@ -185,10 +180,6 @@ class BaseAdapter {
185
180
  */
186
181
  async removeInstance(idInstance) {
187
182
  try {
188
- const instance = await this.storage.getInstance(idInstance);
189
- if (!instance) {
190
- throw new errors_1.NotFoundError("No instance with such ID");
191
- }
192
183
  return this.storage.removeInstance(idInstance);
193
184
  }
194
185
  catch (error) {
@@ -232,14 +223,8 @@ class BaseAdapter {
232
223
  *
233
224
  * @param userCred - User credentials
234
225
  * @param data - User data
235
- * @throws {BadRequestError} If user already exists
236
- * @throws {IntegrationError} If creation fails
237
226
  */
238
227
  async createUser(userCred, data) {
239
- const existingUser = await this.storage.findUser(userCred);
240
- if (existingUser) {
241
- throw new errors_1.BadRequestError("User already created");
242
- }
243
228
  try {
244
229
  return this.storage.createUser(data);
245
230
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GreenApiClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const errors_1 = require("./errors");
8
9
  /**
9
10
  * Client for direct interaction with GREEN-API's WhatsApp gateway.
10
11
  * Provides methods for sending messages, managing instances, and handling files.
@@ -53,7 +54,7 @@ class GreenApiClient {
53
54
  return response.data;
54
55
  }
55
56
  catch (error) {
56
- throw new Error(`Failed to ${endpoint.replace(/([A-Z])/g, " $1").toLowerCase()}: ${error.message}. ${JSON.stringify(error.response?.data)}`);
57
+ throw new errors_1.IntegrationError(`Failed to ${endpoint.replace(/([A-Z])/g, " $1").toLowerCase()}: ${error.message}. ${JSON.stringify(error.response?.data)}`, "INTEGRATION_ERROR");
57
58
  }
58
59
  }
59
60
  async makeFileUploadRequest(endpoint, formData, headers) {
@@ -25,10 +25,9 @@ export declare abstract class StorageProvider<TUser extends BaseUser = BaseUser,
25
25
  * Creates a new instance in storage.
26
26
  *
27
27
  * @param instance - The instance data to store
28
- * @param userId - ID of the user who owns this instance
29
28
  * @returns Promise resolving to the created instance
30
29
  */
31
- abstract createInstance(instance: Instance, userId: bigint | number): Promise<TInstance>;
30
+ abstract createInstance(instance: Instance): Promise<TInstance>;
32
31
  /**
33
32
  * Retrieves an instance by its ID.
34
33
  *
@@ -180,6 +180,12 @@ export interface ContactMessageData extends ForwardableMessage {
180
180
  displayName: string;
181
181
  vcard: string;
182
182
  }
183
+ export interface ContactsArrayMessageData extends ForwardableMessage {
184
+ contacts: Array<{
185
+ displayName: string;
186
+ vcard: string;
187
+ }>;
188
+ }
183
189
  export interface PollMessageData {
184
190
  name: string;
185
191
  options: PollOption[];
@@ -198,6 +204,12 @@ type QuotedMessage = {
198
204
  displayName: string;
199
205
  vcard: string;
200
206
  };
207
+ } | {
208
+ typeMessage: "contactsArrayMessage";
209
+ contacts: Array<{
210
+ displayName: string;
211
+ vcard: string;
212
+ }>;
201
213
  } | {
202
214
  typeMessage: "locationMessage";
203
215
  location: {
@@ -274,6 +286,9 @@ export type WebhookMessageData = {
274
286
  } | {
275
287
  typeMessage: "pollUpdateMessage";
276
288
  pollMessageData: PollUpdateMessageData;
289
+ } | {
290
+ typeMessage: "contactsArrayMessage";
291
+ messageData: ContactsArrayMessageData;
277
292
  };
278
293
  export interface MessageWebhook {
279
294
  typeWebhook: "incomingMessageReceived" | "outgoingMessageReceived" | "outgoingAPIMessageReceived";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@green-api/greenapi-integration",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "GREEN-API Integration library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",