@builderbot/provider-evolution-api 1.2.8 → 1.2.10-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.
- package/dist/evolution/core.d.ts.map +1 -1
- package/dist/evolution/provider.d.ts +95 -54
- package/dist/evolution/provider.d.ts.map +1 -1
- package/dist/index.cjs +273 -140
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/evolution/core.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,KAAK,MAAM,eAAe,CAAA;AA0BtC;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACjD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;;OAGG;gBACS,MAAM,EAAE,KAAK;IAQzB;;;;OAIG;IACI,SAAS,EAAE,KAAK,CAAC,UAAU,CAQjC;IAED;;;;OAIG;IACI,WAAW,EAAE,KAAK,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/evolution/core.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,KAAK,MAAM,eAAe,CAAA;AA0BtC;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACjD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;;OAGG;gBACS,MAAM,EAAE,KAAK;IAQzB;;;;OAIG;IACI,SAAS,EAAE,KAAK,CAAC,UAAU,CAQjC;IAED;;;;OAIG;IACI,WAAW,EAAE,KAAK,CAAC,UAAU,CAwHnC;IAED;;;OAGG;IACI,cAAc,GAAI,SAAS,GAAG,KAAG,OAAO,CAAC,IAAI,CAAC,CASpD;CACJ"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ProviderClass } from '@builderbot/bot';
|
|
2
2
|
import type { Vendor } from '@builderbot/bot/dist/provider/interface/provider';
|
|
3
|
-
import type { BotContext
|
|
3
|
+
import type { BotContext } from '@builderbot/bot/dist/types';
|
|
4
4
|
import { Middleware } from 'polka';
|
|
5
5
|
import type polka from 'polka';
|
|
6
6
|
import Queue from 'queue-promise';
|
|
7
7
|
|
|
8
8
|
import type { EvolutionInterface } from '../interface/evolution';
|
|
9
|
-
import type { EvolutionGlobalVendorArgs, SaveFileOptions } from '../types';
|
|
9
|
+
import type { EvolutionGlobalVendorArgs, SaveFileOptions, ApiResponse } from '../types';
|
|
10
10
|
/**
|
|
11
11
|
* Evolution API Provider implementation
|
|
12
12
|
* Handles all communication with Evolution API for sending messages, media, etc.
|
|
@@ -17,19 +17,20 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
17
17
|
incomingMsg: polka.Middleware;
|
|
18
18
|
}>;
|
|
19
19
|
queue: Queue;
|
|
20
|
-
incomingMsg: any
|
|
20
|
+
incomingMsg: (req: any, res: any) => void | Promise<void>;
|
|
21
21
|
globalVendorArgs: EvolutionGlobalVendorArgs;
|
|
22
22
|
/**
|
|
23
23
|
* Creates an instance of Evolution Provider
|
|
24
24
|
* @param args Provider configuration
|
|
25
|
+
* @throws Error if required configuration is missing
|
|
25
26
|
*/
|
|
26
27
|
constructor(args: EvolutionGlobalVendorArgs);
|
|
27
|
-
sendMessageMeta: (body: any) => Promise<
|
|
28
|
-
sendImageUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<
|
|
29
|
-
sendVideoUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<
|
|
30
|
-
sendAudioUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<
|
|
31
|
-
sendList: (to: string, list: any) => Promise<
|
|
32
|
-
sendListComplete: (to: string, list: any) => Promise<
|
|
28
|
+
sendMessageMeta: <K = ApiResponse>(body: any) => Promise<K>;
|
|
29
|
+
sendImageUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
30
|
+
sendVideoUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
31
|
+
sendAudioUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
32
|
+
sendList: (to: string, list: any) => Promise<ApiResponse>;
|
|
33
|
+
sendListComplete: (to: string, list: any) => Promise<ApiResponse>;
|
|
33
34
|
indexHome?: Middleware<any, any, any, any>;
|
|
34
35
|
/**
|
|
35
36
|
* Initialize HTTP server middleware
|
|
@@ -37,6 +38,7 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
37
38
|
protected beforeHttpServerInit(): void;
|
|
38
39
|
/**
|
|
39
40
|
* Initialize vendor core
|
|
41
|
+
* @returns Promise resolving to the vendor instance
|
|
40
42
|
*/
|
|
41
43
|
protected initVendor(): Promise<any>;
|
|
42
44
|
/**
|
|
@@ -47,77 +49,116 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
47
49
|
private builderHeader;
|
|
48
50
|
/**
|
|
49
51
|
* Verify connection with Evolution API after HTTP server initialization
|
|
50
|
-
|
|
52
|
+
* @throws Error if connection fails
|
|
53
|
+
*/
|
|
54
|
+
protected afterHttpServerInit(): Promise<void>;
|
|
51
55
|
/**
|
|
52
56
|
* Event bus configuration
|
|
57
|
+
* @returns Array of event handlers
|
|
53
58
|
*/
|
|
54
59
|
protected busEvents(): {
|
|
55
60
|
event: string;
|
|
56
|
-
func: (payload:
|
|
61
|
+
func: (payload: unknown) => void;
|
|
57
62
|
}[];
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
64
|
+
* Entry point for sending media files.
|
|
65
|
+
* Detects file type and routes to appropriate function.
|
|
61
66
|
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
67
|
+
* @param to Destination phone number
|
|
68
|
+
* @param file URL or path to media file
|
|
69
|
+
* @param type Optional media type description (unused but required by interface)
|
|
70
|
+
* @returns Promise resolving to API response
|
|
71
|
+
* @throws Error if file type cannot be determined or exceeds size limit
|
|
72
|
+
*/
|
|
73
|
+
sendMedia: (to: string, file: string, type: string) => Promise<ApiResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Convert file to base64 with size validation
|
|
76
|
+
* @param filePath Path to file
|
|
77
|
+
* @returns Base64 encoded file content
|
|
78
|
+
* @throws Error if file is too large
|
|
65
79
|
*/
|
|
66
|
-
|
|
80
|
+
private fileToBase64;
|
|
67
81
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param number
|
|
70
|
-
* @param filePath
|
|
71
|
-
* @param
|
|
82
|
+
* Prepare media message body
|
|
83
|
+
* @param number Destination number
|
|
84
|
+
* @param filePath Media file path
|
|
85
|
+
* @param mediaType Type of media
|
|
86
|
+
* @param caption Optional caption
|
|
87
|
+
* @returns Prepared message body
|
|
72
88
|
*/
|
|
73
|
-
|
|
89
|
+
private prepareMediaMessageBody;
|
|
74
90
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param number
|
|
77
|
-
* @param filePath
|
|
78
|
-
* @param caption
|
|
91
|
+
* Send an image to the given number
|
|
92
|
+
* @param number Destination number
|
|
93
|
+
* @param filePath Local path to image
|
|
94
|
+
* @param caption Optional text caption
|
|
95
|
+
* @returns Promise resolving to API response
|
|
79
96
|
*/
|
|
80
|
-
|
|
97
|
+
sendImage: (number: string, filePath: string, caption: string) => Promise<ApiResponse>;
|
|
81
98
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
99
|
+
* Send a video to the given number
|
|
100
|
+
* @param to Destination number
|
|
101
|
+
* @param mediaUrl Local path to video
|
|
102
|
+
* @param caption Optional text caption
|
|
103
|
+
* @returns Promise resolving to API response
|
|
85
104
|
*/
|
|
86
|
-
|
|
105
|
+
sendVideo: (to: string, mediaUrl: string, caption?: string) => Promise<ApiResponse>;
|
|
87
106
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
107
|
+
* Send an audio file in compatible format (OPUS)
|
|
108
|
+
* @param to Destination number
|
|
109
|
+
* @param mediaUrl Local path to audio file
|
|
110
|
+
* @param mediaName Optional media name (unused but required by interface)
|
|
111
|
+
* @param caption Optional caption (unused for audio)
|
|
112
|
+
* @returns Promise resolving to API response
|
|
92
113
|
*/
|
|
93
|
-
|
|
114
|
+
sendAudio: (to: string, mediaUrl: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
94
115
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param number
|
|
97
|
-
* @param
|
|
116
|
+
* Send a generic document to the given number
|
|
117
|
+
* @param number Destination number
|
|
118
|
+
* @param filePath Local path to the file
|
|
119
|
+
* @param caption Optional text caption
|
|
120
|
+
* @returns Promise resolving to API response
|
|
98
121
|
*/
|
|
99
|
-
|
|
122
|
+
sendFile: (number: string, filePath: string, caption: string) => Promise<ApiResponse>;
|
|
100
123
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
124
|
+
* Send a plain text message
|
|
125
|
+
* @param number Destination number
|
|
126
|
+
* @param message Message content
|
|
127
|
+
* @returns Promise resolving to API response
|
|
104
128
|
*/
|
|
105
|
-
|
|
129
|
+
sendText: (number: string, message: string) => Promise<ApiResponse>;
|
|
106
130
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @param body
|
|
109
|
-
* @param
|
|
131
|
+
* General function for making POST requests to external API
|
|
132
|
+
* @param body Request body
|
|
133
|
+
* @param endpoint Relative endpoint path (optional)
|
|
134
|
+
* @returns Promise resolving to API response
|
|
135
|
+
* @throws Error if request fails
|
|
110
136
|
*/
|
|
111
|
-
|
|
137
|
+
sendMessageToApi: <K = ApiResponse>(body: any, endpoint?: string) => Promise<K>;
|
|
112
138
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
139
|
+
* Queue a message send to ensure order and avoid conflicts
|
|
140
|
+
* @param body Message body
|
|
141
|
+
* @param endpoint API endpoint
|
|
142
|
+
* @returns Promise resolving to API response
|
|
143
|
+
*/
|
|
144
|
+
sendMessageEvoApi: <K = ApiResponse>(body: any, endpoint: string) => Promise<K>;
|
|
145
|
+
/**
|
|
146
|
+
* General router for sending messages.
|
|
147
|
+
* If it includes media, it's sent as a file. If not, as plain text.
|
|
115
148
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @param message
|
|
118
|
-
* @param
|
|
149
|
+
* @param to Destination number
|
|
150
|
+
* @param message Text message
|
|
151
|
+
* @param args Additional options (media, etc.)
|
|
152
|
+
* @returns Promise resolving to API response
|
|
153
|
+
*/
|
|
154
|
+
sendMessage<K = ApiResponse>(to: string, message: string, args?: any): Promise<K>;
|
|
155
|
+
/**
|
|
156
|
+
* Save a file from context
|
|
157
|
+
* @param ctx Partial bot context
|
|
158
|
+
* @param options Save options
|
|
159
|
+
* @returns Promise resolving to the file path
|
|
160
|
+
* @throws Error if file cannot be saved
|
|
119
161
|
*/
|
|
120
|
-
sendMessage(number: string, message: string, options?: SendOptions): Promise<any>;
|
|
121
162
|
saveFile: (ctx: Partial<BotContext>, options?: SaveFileOptions) => Promise<string>;
|
|
122
163
|
}
|
|
123
164
|
export { EvolutionProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/evolution/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kDAAkD,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/evolution/provider.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AG,OAAO,CAAC,WAAW,CAAC,CAWvF;IAED;;;;;;;OAOG;IACH,SAAS,GAAU,IAAI,MAAM,EAAE,UAAU,MAAM,EAAE,YAAY,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,CAoB3G;IAED;;;;;;OAMG;IACH,QAAQ,GAAU,QAAQ,MAAM,EAAE,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,CASzF;IAED;;;;;OAKG;IACH,QAAQ,GAAU,QAAQ,MAAM,EAAE,SAAS,MAAM,KAAG,OAAO,CAAC,WAAW,CAAC,CAgBvE;IAED;;;;;;OAMG;IACH,gBAAgB,GAAU,CAAC,GAAG,WAAW,EAAE,MAAM,GAAG,EAAE,WAAU,MAAoB,KAAG,OAAO,CAAC,CAAC,CAAC,CAuBhG;IAED;;;;;OAKG;IACH,iBAAiB,GAAI,CAAC,GAAG,WAAW,EAAE,MAAM,GAAG,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,CAAC,CAAC,CAW7E;IAED;;;;;;;;OAQG;IACG,WAAW,CAAC,CAAC,GAAG,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAuBvF;;;;;;OAMG;IACH,QAAQ,GAAU,KAAK,OAAO,CAAC,UAAU,CAAC,EAAE,UAAS,eAAoB,KAAG,OAAO,CAAC,MAAM,CAAC,CAkB1F;CACJ;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
var bot = require('@builderbot/bot');
|
|
4
4
|
var require$$1 = require('util');
|
|
5
5
|
var stream = require('stream');
|
|
6
|
-
var
|
|
6
|
+
var require$$1$1 = require('path');
|
|
7
7
|
var require$$3 = require('http');
|
|
8
8
|
var require$$4 = require('https');
|
|
9
9
|
var require$$0$1 = require('url');
|
|
10
10
|
var fs$1 = require('fs');
|
|
11
11
|
var crypto = require('crypto');
|
|
12
12
|
var require$$4$1 = require('assert');
|
|
13
|
-
var require$$1$
|
|
13
|
+
var require$$1$2 = require('tty');
|
|
14
14
|
var require$$0$2 = require('os');
|
|
15
15
|
var zlib = require('zlib');
|
|
16
16
|
var require$$0$3 = require('events');
|
|
@@ -11961,7 +11961,7 @@ var mimeDb = require$$0;
|
|
|
11961
11961
|
*/
|
|
11962
11962
|
|
|
11963
11963
|
var db = mimeDb;
|
|
11964
|
-
var extname =
|
|
11964
|
+
var extname = require$$1$1.extname;
|
|
11965
11965
|
|
|
11966
11966
|
/**
|
|
11967
11967
|
* Module variables.
|
|
@@ -13431,7 +13431,7 @@ var populate$1 = function(dst, src) {
|
|
|
13431
13431
|
|
|
13432
13432
|
var CombinedStream = combined_stream;
|
|
13433
13433
|
var util = require$$1;
|
|
13434
|
-
var path =
|
|
13434
|
+
var path = require$$1$1;
|
|
13435
13435
|
var http$2 = require$$3;
|
|
13436
13436
|
var https$2 = require$$4;
|
|
13437
13437
|
var parseUrl$2 = require$$0$1.parse;
|
|
@@ -16053,7 +16053,7 @@ function requireSupportsColor () {
|
|
|
16053
16053
|
if (hasRequiredSupportsColor) return supportsColor_1;
|
|
16054
16054
|
hasRequiredSupportsColor = 1;
|
|
16055
16055
|
const os = require$$0$2;
|
|
16056
|
-
const tty = require$$1$
|
|
16056
|
+
const tty = require$$1$2;
|
|
16057
16057
|
const hasFlag = requireHasFlag();
|
|
16058
16058
|
|
|
16059
16059
|
const {env} = process;
|
|
@@ -16199,7 +16199,7 @@ function requireNode () {
|
|
|
16199
16199
|
if (hasRequiredNode) return node.exports;
|
|
16200
16200
|
hasRequiredNode = 1;
|
|
16201
16201
|
(function (module, exports) {
|
|
16202
|
-
const tty = require$$1$
|
|
16202
|
+
const tty = require$$1$2;
|
|
16203
16203
|
const util = require$$1;
|
|
16204
16204
|
|
|
16205
16205
|
/**
|
|
@@ -19901,9 +19901,9 @@ const generalDownload = async (url, pathToSave, headers) => {
|
|
|
19901
19901
|
try {
|
|
19902
19902
|
const checkProtocol = url.startsWith('http');
|
|
19903
19903
|
const handleHttp = checkProtocol ? https : http;
|
|
19904
|
-
const fileName =
|
|
19905
|
-
const name =
|
|
19906
|
-
const fullPath =
|
|
19904
|
+
const fileName = require$$1$1.basename(checkProtocol ? new URL(url).pathname : url);
|
|
19905
|
+
const name = require$$1$1.parse(fileName).name;
|
|
19906
|
+
const fullPath = require$$1$1.join(pathToSave ?? require$$0$2.tmpdir(), name);
|
|
19907
19907
|
const file = fs$1.createWriteStream(fullPath);
|
|
19908
19908
|
if (checkIsLocal) {
|
|
19909
19909
|
/**
|
|
@@ -19912,7 +19912,7 @@ const generalDownload = async (url, pathToSave, headers) => {
|
|
|
19912
19912
|
return new Promise((res) => {
|
|
19913
19913
|
const response = {
|
|
19914
19914
|
headers: {
|
|
19915
|
-
'content-type': mime$1.contentType(
|
|
19915
|
+
'content-type': mime$1.contentType(require$$1$1.extname(url)) || '',
|
|
19916
19916
|
},
|
|
19917
19917
|
};
|
|
19918
19918
|
res({ response, fullPath: url });
|
|
@@ -20024,7 +20024,6 @@ class EvolutionCoreVendor extends EventEmitter {
|
|
|
20024
20024
|
res.end('Missing vendor arguments');
|
|
20025
20025
|
return;
|
|
20026
20026
|
}
|
|
20027
|
-
console.log(' body', JSON.stringify(req.body, null, 2));
|
|
20028
20027
|
const { event, data } = req.body;
|
|
20029
20028
|
if (!req.body) {
|
|
20030
20029
|
res.statusCode = 400;
|
|
@@ -20049,6 +20048,13 @@ class EvolutionCoreVendor extends EventEmitter {
|
|
|
20049
20048
|
base64: message.base64,
|
|
20050
20049
|
};
|
|
20051
20050
|
}
|
|
20051
|
+
else if (message.orderMessage) {
|
|
20052
|
+
responseObj = {
|
|
20053
|
+
from,
|
|
20054
|
+
name,
|
|
20055
|
+
body: generateRefProvider('_event_order_'),
|
|
20056
|
+
};
|
|
20057
|
+
}
|
|
20052
20058
|
else if (message.videoMessage) {
|
|
20053
20059
|
responseObj = {
|
|
20054
20060
|
type: data.messageType,
|
|
@@ -20147,6 +20153,10 @@ class EvolutionCoreVendor extends EventEmitter {
|
|
|
20147
20153
|
}
|
|
20148
20154
|
}
|
|
20149
20155
|
|
|
20156
|
+
// Maximum file size in bytes (10MB)
|
|
20157
|
+
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
20158
|
+
// Default timeout for API requests in ms
|
|
20159
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
20150
20160
|
/**
|
|
20151
20161
|
* Evolution API Provider implementation
|
|
20152
20162
|
* Handles all communication with Evolution API for sending messages, media, etc.
|
|
@@ -20155,6 +20165,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20155
20165
|
/**
|
|
20156
20166
|
* Creates an instance of Evolution Provider
|
|
20157
20167
|
* @param args Provider configuration
|
|
20168
|
+
* @throws Error if required configuration is missing
|
|
20158
20169
|
*/
|
|
20159
20170
|
constructor(args) {
|
|
20160
20171
|
super();
|
|
@@ -20167,163 +20178,225 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20167
20178
|
port: 3000,
|
|
20168
20179
|
};
|
|
20169
20180
|
/**
|
|
20170
|
-
*
|
|
20171
|
-
*
|
|
20181
|
+
* Entry point for sending media files.
|
|
20182
|
+
* Detects file type and routes to appropriate function.
|
|
20172
20183
|
*
|
|
20173
|
-
* @param
|
|
20174
|
-
* @param
|
|
20175
|
-
* @param
|
|
20184
|
+
* @param to Destination phone number
|
|
20185
|
+
* @param file URL or path to media file
|
|
20186
|
+
* @param type Optional media type description (unused but required by interface)
|
|
20187
|
+
* @returns Promise resolving to API response
|
|
20188
|
+
* @throws Error if file type cannot be determined or exceeds size limit
|
|
20176
20189
|
*/
|
|
20177
|
-
this.sendMedia = async (
|
|
20178
|
-
|
|
20179
|
-
|
|
20180
|
-
|
|
20181
|
-
|
|
20182
|
-
|
|
20183
|
-
|
|
20184
|
-
|
|
20185
|
-
|
|
20186
|
-
|
|
20190
|
+
this.sendMedia = async (to, file, type) => {
|
|
20191
|
+
try {
|
|
20192
|
+
const fileDownloaded = await generalDownload(file);
|
|
20193
|
+
// Check file size
|
|
20194
|
+
const stats = fs$1.statSync(fileDownloaded);
|
|
20195
|
+
if (stats.size > MAX_FILE_SIZE) {
|
|
20196
|
+
throw new Error(`File size exceeds limit of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
|
|
20197
|
+
}
|
|
20198
|
+
const mimeType = mime$1.lookup(fileDownloaded);
|
|
20199
|
+
if (!mimeType)
|
|
20200
|
+
throw new Error('Could not determine MIME type');
|
|
20201
|
+
if (mimeType.includes('image')) {
|
|
20202
|
+
return this.sendImage(to, fileDownloaded, type || '');
|
|
20203
|
+
}
|
|
20204
|
+
if (mimeType.includes('video')) {
|
|
20205
|
+
return this.sendVideo(to, fileDownloaded, type || '');
|
|
20206
|
+
}
|
|
20207
|
+
if (mimeType.includes('audio')) {
|
|
20208
|
+
return this.sendAudio(to, fileDownloaded);
|
|
20209
|
+
}
|
|
20210
|
+
return this.sendFile(to, fileDownloaded, type || '');
|
|
20187
20211
|
}
|
|
20188
|
-
|
|
20189
|
-
|
|
20212
|
+
catch (error) {
|
|
20213
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending media';
|
|
20214
|
+
console.error('Error sending media:', errorMessage);
|
|
20215
|
+
throw new Error(`Failed to send media: ${errorMessage}`);
|
|
20190
20216
|
}
|
|
20191
|
-
return this.sendFile(number, fileDownloaded, caption || '');
|
|
20192
20217
|
};
|
|
20193
20218
|
/**
|
|
20194
|
-
*
|
|
20195
|
-
* @param number
|
|
20196
|
-
* @param filePath
|
|
20197
|
-
* @param caption
|
|
20219
|
+
* Send an image to the given number
|
|
20220
|
+
* @param number Destination number
|
|
20221
|
+
* @param filePath Local path to image
|
|
20222
|
+
* @param caption Optional text caption
|
|
20223
|
+
* @returns Promise resolving to API response
|
|
20198
20224
|
*/
|
|
20199
20225
|
this.sendImage = async (number, filePath, caption) => {
|
|
20200
|
-
|
|
20201
|
-
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
|
|
20205
|
-
|
|
20206
|
-
|
|
20207
|
-
|
|
20208
|
-
|
|
20209
|
-
};
|
|
20210
|
-
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20226
|
+
try {
|
|
20227
|
+
const body = await this.prepareMediaMessageBody(number, filePath, 'image', caption);
|
|
20228
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20229
|
+
}
|
|
20230
|
+
catch (error) {
|
|
20231
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending image';
|
|
20232
|
+
console.error('Error sending image:', errorMessage);
|
|
20233
|
+
throw new Error(`Failed to send image: ${errorMessage}`);
|
|
20234
|
+
}
|
|
20211
20235
|
};
|
|
20212
20236
|
/**
|
|
20213
|
-
*
|
|
20214
|
-
* @param
|
|
20215
|
-
* @param
|
|
20216
|
-
* @param caption
|
|
20237
|
+
* Send a video to the given number
|
|
20238
|
+
* @param to Destination number
|
|
20239
|
+
* @param mediaUrl Local path to video
|
|
20240
|
+
* @param caption Optional text caption
|
|
20241
|
+
* @returns Promise resolving to API response
|
|
20217
20242
|
*/
|
|
20218
|
-
this.sendVideo = async (
|
|
20219
|
-
|
|
20220
|
-
|
|
20221
|
-
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20225
|
-
|
|
20226
|
-
|
|
20227
|
-
|
|
20228
|
-
}
|
|
20229
|
-
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20243
|
+
this.sendVideo = async (to, mediaUrl, caption) => {
|
|
20244
|
+
try {
|
|
20245
|
+
const fileDownloaded = mediaUrl.startsWith('http') ? await generalDownload(mediaUrl) : mediaUrl;
|
|
20246
|
+
const body = await this.prepareMediaMessageBody(to, fileDownloaded, 'video', caption);
|
|
20247
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20248
|
+
}
|
|
20249
|
+
catch (error) {
|
|
20250
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending video';
|
|
20251
|
+
console.error('Error sending video:', errorMessage);
|
|
20252
|
+
throw new Error(`Failed to send video: ${errorMessage}`);
|
|
20253
|
+
}
|
|
20230
20254
|
};
|
|
20231
20255
|
/**
|
|
20232
|
-
*
|
|
20233
|
-
* @param
|
|
20234
|
-
* @param
|
|
20256
|
+
* Send an audio file in compatible format (OPUS)
|
|
20257
|
+
* @param to Destination number
|
|
20258
|
+
* @param mediaUrl Local path to audio file
|
|
20259
|
+
* @param mediaName Optional media name (unused but required by interface)
|
|
20260
|
+
* @param caption Optional caption (unused for audio)
|
|
20261
|
+
* @returns Promise resolving to API response
|
|
20235
20262
|
*/
|
|
20236
|
-
this.sendAudio = async (
|
|
20237
|
-
|
|
20238
|
-
|
|
20239
|
-
|
|
20240
|
-
|
|
20241
|
-
|
|
20242
|
-
|
|
20243
|
-
|
|
20244
|
-
|
|
20245
|
-
|
|
20263
|
+
this.sendAudio = async (to, mediaUrl, mediaName, caption) => {
|
|
20264
|
+
try {
|
|
20265
|
+
const fileDownloaded = mediaUrl.startsWith('http') ? await generalDownload(mediaUrl) : mediaUrl;
|
|
20266
|
+
const mediaBase64 = await this.fileToBase64(fileDownloaded);
|
|
20267
|
+
const body = {
|
|
20268
|
+
number: to,
|
|
20269
|
+
media: mediaBase64,
|
|
20270
|
+
mimetype: 'audio/ogg; codecs=opus',
|
|
20271
|
+
mediatype: 'audio',
|
|
20272
|
+
delay: 0,
|
|
20273
|
+
};
|
|
20274
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20275
|
+
}
|
|
20276
|
+
catch (error) {
|
|
20277
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending audio';
|
|
20278
|
+
console.error('Error sending audio:', errorMessage);
|
|
20279
|
+
throw new Error(`Failed to send audio: ${errorMessage}`);
|
|
20280
|
+
}
|
|
20246
20281
|
};
|
|
20247
20282
|
/**
|
|
20248
|
-
*
|
|
20249
|
-
* @param number
|
|
20250
|
-
* @param filePath
|
|
20251
|
-
* @param caption
|
|
20283
|
+
* Send a generic document to the given number
|
|
20284
|
+
* @param number Destination number
|
|
20285
|
+
* @param filePath Local path to the file
|
|
20286
|
+
* @param caption Optional text caption
|
|
20287
|
+
* @returns Promise resolving to API response
|
|
20252
20288
|
*/
|
|
20253
20289
|
this.sendFile = async (number, filePath, caption) => {
|
|
20254
|
-
|
|
20255
|
-
|
|
20256
|
-
|
|
20257
|
-
|
|
20258
|
-
|
|
20259
|
-
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
caption: caption || path$1.basename(filePath),
|
|
20264
|
-
delay: 0,
|
|
20265
|
-
};
|
|
20266
|
-
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20290
|
+
try {
|
|
20291
|
+
const body = await this.prepareMediaMessageBody(number, filePath, 'document', caption);
|
|
20292
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20293
|
+
}
|
|
20294
|
+
catch (error) {
|
|
20295
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending file';
|
|
20296
|
+
console.error('Error sending file:', errorMessage);
|
|
20297
|
+
throw new Error(`Failed to send file: ${errorMessage}`);
|
|
20298
|
+
}
|
|
20267
20299
|
};
|
|
20268
20300
|
/**
|
|
20269
|
-
*
|
|
20270
|
-
* @param number
|
|
20271
|
-
* @param message
|
|
20301
|
+
* Send a plain text message
|
|
20302
|
+
* @param number Destination number
|
|
20303
|
+
* @param message Message content
|
|
20304
|
+
* @returns Promise resolving to API response
|
|
20272
20305
|
*/
|
|
20273
20306
|
this.sendText = async (number, message) => {
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20307
|
+
try {
|
|
20308
|
+
const endpoint = '/message/sendText/';
|
|
20309
|
+
const body = {
|
|
20310
|
+
number,
|
|
20311
|
+
text: message,
|
|
20312
|
+
delay: 0,
|
|
20313
|
+
};
|
|
20314
|
+
return this.sendMessageEvoApi(body, endpoint);
|
|
20315
|
+
}
|
|
20316
|
+
catch (error) {
|
|
20317
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending text';
|
|
20318
|
+
console.error('Error sending text:', errorMessage);
|
|
20319
|
+
throw new Error(`Failed to send text: ${errorMessage}`);
|
|
20320
|
+
}
|
|
20281
20321
|
};
|
|
20282
20322
|
/**
|
|
20283
|
-
*
|
|
20284
|
-
* @param body
|
|
20285
|
-
* @param
|
|
20323
|
+
* General function for making POST requests to external API
|
|
20324
|
+
* @param body Request body
|
|
20325
|
+
* @param endpoint Relative endpoint path (optional)
|
|
20326
|
+
* @returns Promise resolving to API response
|
|
20327
|
+
* @throws Error if request fails
|
|
20286
20328
|
*/
|
|
20287
|
-
this.sendMessageToApi = async (body,
|
|
20329
|
+
this.sendMessageToApi = async (body, endpoint = '/message/') => {
|
|
20288
20330
|
const { baseURL, instanceName, apiKey } = this.globalVendorArgs;
|
|
20289
|
-
const
|
|
20290
|
-
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20331
|
+
const url = `${baseURL}${endpoint}${instanceName}`;
|
|
20332
|
+
try {
|
|
20333
|
+
const response = await fetch(url, {
|
|
20334
|
+
method: 'POST',
|
|
20335
|
+
headers: this.builderHeader(),
|
|
20336
|
+
body: JSON.stringify(body),
|
|
20337
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
20338
|
+
});
|
|
20339
|
+
if (!response.ok) {
|
|
20340
|
+
throw new Error(`Error sending message: ${response.statusText}`);
|
|
20341
|
+
}
|
|
20342
|
+
const data = await response.json();
|
|
20343
|
+
return data;
|
|
20344
|
+
}
|
|
20345
|
+
catch (error) {
|
|
20346
|
+
const message = error instanceof Error ? error.message : 'Unknown error in API request';
|
|
20347
|
+
console.error(`API request failed (${endpoint}):`, message);
|
|
20348
|
+
throw new Error(`API request failed: ${message}`);
|
|
20299
20349
|
}
|
|
20300
|
-
const data = await response.json();
|
|
20301
|
-
return data;
|
|
20302
20350
|
};
|
|
20303
20351
|
/**
|
|
20304
|
-
*
|
|
20305
|
-
* @param body
|
|
20306
|
-
* @param
|
|
20352
|
+
* Queue a message send to ensure order and avoid conflicts
|
|
20353
|
+
* @param body Message body
|
|
20354
|
+
* @param endpoint API endpoint
|
|
20355
|
+
* @returns Promise resolving to API response
|
|
20307
20356
|
*/
|
|
20308
|
-
this.sendMessageEvoApi = (body,
|
|
20309
|
-
return new Promise((resolve) => this.queue.add(async () => {
|
|
20310
|
-
|
|
20311
|
-
|
|
20357
|
+
this.sendMessageEvoApi = (body, endpoint) => {
|
|
20358
|
+
return new Promise((resolve, reject) => this.queue.add(async () => {
|
|
20359
|
+
try {
|
|
20360
|
+
const resp = await this.sendMessageToApi(body, endpoint);
|
|
20361
|
+
resolve(resp);
|
|
20362
|
+
}
|
|
20363
|
+
catch (error) {
|
|
20364
|
+
reject(error);
|
|
20365
|
+
}
|
|
20312
20366
|
}));
|
|
20313
20367
|
};
|
|
20368
|
+
/**
|
|
20369
|
+
* Save a file from context
|
|
20370
|
+
* @param ctx Partial bot context
|
|
20371
|
+
* @param options Save options
|
|
20372
|
+
* @returns Promise resolving to the file path
|
|
20373
|
+
* @throws Error if file cannot be saved
|
|
20374
|
+
*/
|
|
20314
20375
|
this.saveFile = async (ctx, options = {}) => {
|
|
20315
20376
|
try {
|
|
20377
|
+
if (!ctx.base64) {
|
|
20378
|
+
throw new Error('No base64 data provided');
|
|
20379
|
+
}
|
|
20316
20380
|
const buffer = ctx.base64;
|
|
20317
|
-
const extension = mime$1.extension(ctx.mimetype);
|
|
20381
|
+
const extension = mime$1.extension(ctx.mimetype ?? 'application/octet-stream');
|
|
20318
20382
|
const fileName = `file-${Date.now()}.${extension}`;
|
|
20319
|
-
const pathFile =
|
|
20383
|
+
const pathFile = require$$1$1.join(options?.path ?? require$$0$2.tmpdir(), fileName);
|
|
20320
20384
|
await promises.writeFile(pathFile, buffer);
|
|
20321
|
-
return
|
|
20385
|
+
return require$$1$1.resolve(pathFile);
|
|
20322
20386
|
}
|
|
20323
20387
|
catch (error) {
|
|
20324
|
-
|
|
20388
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error saving file';
|
|
20389
|
+
console.error('Error saving file:', errorMessage);
|
|
20390
|
+
return Promise.reject(new Error(`Failed to save file: ${errorMessage}`));
|
|
20325
20391
|
}
|
|
20326
20392
|
};
|
|
20393
|
+
// Validate required parameters
|
|
20394
|
+
if (!args.apiKey) {
|
|
20395
|
+
throw new Error('API Key is required');
|
|
20396
|
+
}
|
|
20397
|
+
if (!args.instanceName) {
|
|
20398
|
+
throw new Error('Instance name is required');
|
|
20399
|
+
}
|
|
20327
20400
|
this.globalVendorArgs = { ...this.globalVendorArgs, ...args };
|
|
20328
20401
|
this.queue = new Queue({
|
|
20329
20402
|
concurrent: 1,
|
|
@@ -20336,7 +20409,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20336
20409
|
*/
|
|
20337
20410
|
beforeHttpServerInit() {
|
|
20338
20411
|
this.server = this.server
|
|
20339
|
-
.use(json())
|
|
20412
|
+
.use(json({ limit: '50mb' }))
|
|
20340
20413
|
.use((req, _, next) => {
|
|
20341
20414
|
req['globalVendorArgs'] = this.globalVendorArgs;
|
|
20342
20415
|
return next();
|
|
@@ -20346,6 +20419,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20346
20419
|
}
|
|
20347
20420
|
/**
|
|
20348
20421
|
* Initialize vendor core
|
|
20422
|
+
* @returns Promise resolving to the vendor instance
|
|
20349
20423
|
*/
|
|
20350
20424
|
initVendor() {
|
|
20351
20425
|
const vendor = new EvolutionCoreVendor(this.queue);
|
|
@@ -20361,19 +20435,23 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20361
20435
|
const { apiKey } = this.globalVendorArgs;
|
|
20362
20436
|
return {
|
|
20363
20437
|
apikey: apiKey,
|
|
20438
|
+
'Content-Type': 'application/json',
|
|
20364
20439
|
...additionalHeaders,
|
|
20365
20440
|
};
|
|
20366
20441
|
}
|
|
20367
20442
|
/**
|
|
20368
20443
|
* Verify connection with Evolution API after HTTP server initialization
|
|
20369
|
-
|
|
20444
|
+
* @throws Error if connection fails
|
|
20445
|
+
*/
|
|
20446
|
+
async afterHttpServerInit() {
|
|
20370
20447
|
try {
|
|
20371
20448
|
const { baseURL, instanceName } = this.globalVendorArgs;
|
|
20372
20449
|
// Verify connection with Evolution API
|
|
20373
20450
|
const response = await axios.get(`${baseURL}/instance/connectionState/${instanceName}`, {
|
|
20374
20451
|
headers: this.builderHeader(),
|
|
20452
|
+
timeout: DEFAULT_TIMEOUT,
|
|
20375
20453
|
});
|
|
20376
|
-
const state = response.data
|
|
20454
|
+
const state = response.data?.state ?? response.data?.instance?.state ?? 'close';
|
|
20377
20455
|
if (state === 'open') {
|
|
20378
20456
|
this.emit('ready');
|
|
20379
20457
|
}
|
|
@@ -20395,6 +20473,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20395
20473
|
}
|
|
20396
20474
|
/**
|
|
20397
20475
|
* Event bus configuration
|
|
20476
|
+
* @returns Array of event handlers
|
|
20398
20477
|
*/
|
|
20399
20478
|
busEvents() {
|
|
20400
20479
|
return [
|
|
@@ -20419,18 +20498,72 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20419
20498
|
];
|
|
20420
20499
|
}
|
|
20421
20500
|
/**
|
|
20422
|
-
*
|
|
20423
|
-
*
|
|
20501
|
+
* Convert file to base64 with size validation
|
|
20502
|
+
* @param filePath Path to file
|
|
20503
|
+
* @returns Base64 encoded file content
|
|
20504
|
+
* @throws Error if file is too large
|
|
20505
|
+
*/
|
|
20506
|
+
async fileToBase64(filePath) {
|
|
20507
|
+
const stats = fs$1.statSync(filePath);
|
|
20508
|
+
if (stats.size > MAX_FILE_SIZE) {
|
|
20509
|
+
throw new Error(`File size exceeds limit of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
|
|
20510
|
+
}
|
|
20511
|
+
return fs$1.readFileSync(filePath, { encoding: 'base64' });
|
|
20512
|
+
}
|
|
20513
|
+
/**
|
|
20514
|
+
* Prepare media message body
|
|
20515
|
+
* @param number Destination number
|
|
20516
|
+
* @param filePath Media file path
|
|
20517
|
+
* @param mediaType Type of media
|
|
20518
|
+
* @param caption Optional caption
|
|
20519
|
+
* @returns Prepared message body
|
|
20520
|
+
*/
|
|
20521
|
+
async prepareMediaMessageBody(number, filePath, mediaType, caption) {
|
|
20522
|
+
const mediaBase64 = await this.fileToBase64(filePath);
|
|
20523
|
+
const mimeType = mime$1.lookup(filePath) || 'application/octet-stream';
|
|
20524
|
+
const fileName = require$$1$1.basename(filePath);
|
|
20525
|
+
const body = {
|
|
20526
|
+
number,
|
|
20527
|
+
media: mediaBase64,
|
|
20528
|
+
mimetype: mimeType,
|
|
20529
|
+
mediatype: mediaType,
|
|
20530
|
+
caption: caption || fileName,
|
|
20531
|
+
delay: 0,
|
|
20532
|
+
};
|
|
20533
|
+
if (mediaType === 'document') {
|
|
20534
|
+
body.fileName = fileName;
|
|
20535
|
+
}
|
|
20536
|
+
return body;
|
|
20537
|
+
}
|
|
20538
|
+
/**
|
|
20539
|
+
* General router for sending messages.
|
|
20540
|
+
* If it includes media, it's sent as a file. If not, as plain text.
|
|
20424
20541
|
*
|
|
20425
|
-
* @param
|
|
20426
|
-
* @param message
|
|
20427
|
-
* @param
|
|
20542
|
+
* @param to Destination number
|
|
20543
|
+
* @param message Text message
|
|
20544
|
+
* @param args Additional options (media, etc.)
|
|
20545
|
+
* @returns Promise resolving to API response
|
|
20428
20546
|
*/
|
|
20429
|
-
async sendMessage(
|
|
20430
|
-
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20547
|
+
async sendMessage(to, message, args) {
|
|
20548
|
+
try {
|
|
20549
|
+
// Sanitize phone number (remove non-numeric chars except +)
|
|
20550
|
+
const sanitizedNumber = to.replace(/[^\d+]/g, '');
|
|
20551
|
+
// Process options
|
|
20552
|
+
const options = args;
|
|
20553
|
+
const mergedOptions = { ...options, ...options?.['options'] };
|
|
20554
|
+
let response;
|
|
20555
|
+
if (mergedOptions?.media) {
|
|
20556
|
+
response = await this.sendMedia(sanitizedNumber, mergedOptions.media, mergedOptions.type || '');
|
|
20557
|
+
}
|
|
20558
|
+
else {
|
|
20559
|
+
response = await this.sendText(sanitizedNumber, message);
|
|
20560
|
+
}
|
|
20561
|
+
return response;
|
|
20562
|
+
}
|
|
20563
|
+
catch (error) {
|
|
20564
|
+
console.error('Error in sendMessage:', error);
|
|
20565
|
+
throw error;
|
|
20566
|
+
}
|
|
20434
20567
|
}
|
|
20435
20568
|
}
|
|
20436
20569
|
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,47 @@ export declare class File {
|
|
|
12
12
|
export interface SaveFileOptions {
|
|
13
13
|
path?: string;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Possible types of media to send
|
|
17
|
+
*/
|
|
18
|
+
export type MediaType = 'image' | 'video' | 'audio' | 'document';
|
|
19
|
+
/**
|
|
20
|
+
* Base message structure for API requests
|
|
21
|
+
*/
|
|
22
|
+
interface BaseMessage {
|
|
23
|
+
number: string;
|
|
24
|
+
delay: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Structure for text messages
|
|
28
|
+
*/
|
|
29
|
+
export interface TextMessage extends BaseMessage {
|
|
30
|
+
text: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Structure for media messages
|
|
34
|
+
*/
|
|
35
|
+
export interface MediaMessage extends BaseMessage {
|
|
36
|
+
media: string;
|
|
37
|
+
mimetype: string;
|
|
38
|
+
mediatype: MediaType;
|
|
39
|
+
caption?: string;
|
|
40
|
+
fileName?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Standard API response structure
|
|
44
|
+
*/
|
|
45
|
+
export interface ApiResponse {
|
|
46
|
+
key?: {
|
|
47
|
+
remoteJid?: string;
|
|
48
|
+
fromMe?: boolean;
|
|
49
|
+
id?: string;
|
|
50
|
+
};
|
|
51
|
+
status?: string;
|
|
52
|
+
message?: string;
|
|
53
|
+
error?: boolean;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
15
56
|
export interface EvolutionGlobalVendorArgs extends GlobalVendorArgs {
|
|
16
57
|
participant?: string;
|
|
17
58
|
}
|
|
@@ -81,4 +122,5 @@ export interface WebhookEvent {
|
|
|
81
122
|
server_url: string;
|
|
82
123
|
apikey: string;
|
|
83
124
|
}
|
|
125
|
+
export {};
|
|
84
126
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAGlE,qBAAa,IAAI;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,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a,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEzF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,GAAG,EAAE,YAAY,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,aAAa,CAAA;IACrB,OAAO,EAAE,cAAc,CAAA;IACvB,WAAW,EAAE,WAAW,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,aAAa,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACtB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,2BAA2B,GAC3B,eAAe,CAAA;AAErB;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,gBAAgB,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,gBAAgB,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-evolution-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10-5.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "aurik3 <aurik3@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/aurik3/bot-whatsapp#readme",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"queue-promise": "^2.2.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@builderbot/bot": "^1.2.
|
|
43
|
+
"@builderbot/bot": "^1.2.10-5.0",
|
|
44
44
|
"@jest/globals": "^29.7.0",
|
|
45
45
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
46
46
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"tslib": "^2.6.2",
|
|
66
66
|
"tsm": "^2.3.0"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "ab5d77e82299bab6478d370c9b86451053eec2d1"
|
|
69
69
|
}
|