@green-api/greenapi-integration 0.6.2 → 0.7.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.
@@ -56,18 +56,22 @@ class BaseGreenApiAuthGuard {
56
56
  async validateRequest(request) {
57
57
  const token = request.headers["authorization"];
58
58
  if (!token) {
59
+ this.gaLogger.warn("Authentication header is missing", { body: request.body, headers: request.headers });
59
60
  throw new errors_1.AuthenticationError("Authentication header is missing");
60
61
  }
61
62
  this.gaLogger.info("Request from GREEN-API", { body: request.body });
62
63
  const idInstance = request.body?.instanceData?.idInstance;
63
64
  if (!idInstance) {
65
+ this.gaLogger.warn("Invalid webhook format", { body: request.body, headers: request.headers });
64
66
  throw new errors_1.AuthenticationError("Invalid webhook format");
65
67
  }
66
68
  const instance = await this.storage.getInstance(idInstance);
67
69
  if (!instance) {
70
+ this.gaLogger.warn(`No instance with such ID ${idInstance}`, { body: request.body, headers: request.headers });
68
71
  throw new errors_1.AuthenticationError(`No instance with such ID ${idInstance}`);
69
72
  }
70
73
  if (instance.settings?.webhookUrlToken !== token.split(" ")[1]) {
74
+ this.gaLogger.warn("Invalid token", { body: request.body, headers: request.headers });
71
75
  throw new errors_1.AuthenticationError("Invalid token");
72
76
  }
73
77
  return true;
@@ -5,8 +5,8 @@
5
5
  export interface BaseInstance {
6
6
  idInstance: number | bigint;
7
7
  apiTokenInstance: string;
8
- stateInstance?: InstanceState;
9
- settings?: Settings | Record<string, any>;
8
+ stateInstance?: InstanceState | null;
9
+ settings?: Settings | Record<string, any> | null;
10
10
  }
11
11
  /**
12
12
  * Extended instance interface that allows for additional platform-specific properties.
@@ -16,40 +16,43 @@ export interface Instance extends BaseInstance {
16
16
  [key: string]: any;
17
17
  }
18
18
  /**
19
- * Union type representing all possible message formats that can be sent through GREEN-API.
20
- * Each message type has its own specific structure and required fields.
19
+ * Common properties shared by all message types.
21
20
  */
22
- export type Message = ({
23
- type: "text";
21
+ export interface BaseMessage {
22
+ chatId: string;
23
+ quotedMessageId?: string;
24
+ }
25
+ export interface ForwardMessagesResponse {
26
+ messages: string[];
27
+ }
28
+ export interface PollOption {
29
+ optionName: string;
30
+ }
31
+ export interface SendMessage extends BaseMessage {
24
32
  message: string;
25
33
  linkPreview?: boolean;
26
- } & BaseMessage) | ({
27
- type: "upload-file";
34
+ }
35
+ export interface SendFileByUpload extends BaseMessage {
28
36
  caption?: string;
29
37
  file: {
30
38
  data: Blob | File;
31
39
  fileName: string;
32
40
  };
33
- } & BaseMessage) | ({
34
- type: "url-file";
41
+ }
42
+ export interface SendFileByUrl extends BaseMessage {
35
43
  caption?: string;
36
44
  file: {
37
45
  url: string;
38
46
  fileName: string;
39
47
  };
40
- } & BaseMessage) | ({
41
- type: "poll";
42
- message: string;
43
- options: PollOption[];
44
- multipleAnswers?: boolean;
45
- } & BaseMessage) | ({
46
- type: "location";
48
+ }
49
+ export interface SendLocation extends BaseMessage {
47
50
  nameLocation?: string;
48
51
  address?: string;
49
52
  latitude: number;
50
53
  longitude: number;
51
- } & BaseMessage) | ({
52
- type: "contact";
54
+ }
55
+ export interface SendContact extends BaseMessage {
53
56
  contact: {
54
57
  phoneContact: number;
55
58
  firstName?: string;
@@ -57,47 +60,32 @@ export type Message = ({
57
60
  lastName?: string;
58
61
  company?: string;
59
62
  };
60
- } & BaseMessage) | {
61
- type: "forward";
63
+ }
64
+ export interface SendPoll extends BaseMessage {
65
+ message: string;
66
+ options: PollOption[];
67
+ multipleAnswers?: boolean;
68
+ }
69
+ export interface ForwardMessages {
62
70
  chatId: string;
63
71
  chatIdFrom: string;
64
72
  messages: string[];
65
- };
66
- /**
67
- * Common properties shared by all message types.
68
- */
69
- export interface BaseMessage {
70
- chatId: string;
71
- quotedMessageId?: string;
72
- }
73
- export type SendMessageType = "text" | "upload-file" | "url-file" | "poll" | "location" | "contact" | "forward";
74
- export interface ForwardMessagesResponse {
75
- messages: string[];
76
73
  }
77
- export interface PollOption {
78
- optionName: string;
79
- }
80
- export type SendMessage = Extract<Message, {
74
+ export type Message = (SendMessage & {
81
75
  type: "text";
82
- }>;
83
- export type SendFileByUpload = Extract<Message, {
76
+ }) | (SendFileByUpload & {
84
77
  type: "upload-file";
85
- }>;
86
- export type SendFileByUrl = Extract<Message, {
78
+ }) | (SendFileByUrl & {
87
79
  type: "url-file";
88
- }>;
89
- export type SendLocation = Extract<Message, {
80
+ }) | (SendPoll & {
81
+ type: "poll";
82
+ }) | (SendLocation & {
90
83
  type: "location";
91
- }>;
92
- export type SendContact = Extract<Message, {
84
+ }) | (SendContact & {
93
85
  type: "contact";
94
- }>;
95
- export type SendPoll = Extract<Message, {
96
- type: "poll";
97
- }>;
98
- export type ForwardMessages = Extract<Message, {
86
+ }) | (ForwardMessages & {
99
87
  type: "forward";
100
- }>;
88
+ });
101
89
  export type QueueMessageType = "sendMessage" | "sendPoll" | "sendFileByUrl" | "sendLocation" | "sendContact" | "ForwardMessages";
102
90
  export type QueueMessageBody = SendMessage | SendPoll | SendFileByUrl | SendLocation | SendContact | ForwardMessages;
103
91
  export interface QueueMessage {
@@ -694,6 +682,6 @@ export interface BaseRequest {
694
682
  body: any;
695
683
  }
696
684
  export interface BaseUser {
697
- id: number | bigint;
685
+ id: number | bigint | string;
698
686
  [key: string]: any;
699
687
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@green-api/greenapi-integration",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "description": "GREEN-API Integration library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,6 +37,6 @@
37
37
  "typescript": "^5.7.2"
38
38
  },
39
39
  "dependencies": {
40
- "axios": "^1.7.9"
40
+ "axios": "^1.9.0"
41
41
  }
42
42
  }