@builderbot/provider-evolution-api 1.2.8 → 1.2.9
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 -55
- package/dist/evolution/provider.d.ts.map +1 -1
- package/dist/index.cjs +266 -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,CAgHnC;IAED;;;OAGG;IACI,cAAc,GAAI,SAAS,GAAG,KAAG,OAAO,CAAC,IAAI,CAAC,CASpD;CACJ"}
|
|
@@ -1,12 +1,11 @@
|
|
|
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
|
-
|
|
8
7
|
import type { EvolutionInterface } from '../interface/evolution';
|
|
9
|
-
import type { EvolutionGlobalVendorArgs, SaveFileOptions } from '../types';
|
|
8
|
+
import type { EvolutionGlobalVendorArgs, SaveFileOptions, ApiResponse } from '../types';
|
|
10
9
|
/**
|
|
11
10
|
* Evolution API Provider implementation
|
|
12
11
|
* Handles all communication with Evolution API for sending messages, media, etc.
|
|
@@ -17,19 +16,20 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
17
16
|
incomingMsg: polka.Middleware;
|
|
18
17
|
}>;
|
|
19
18
|
queue: Queue;
|
|
20
|
-
incomingMsg: any
|
|
19
|
+
incomingMsg: (req: any, res: any) => void | Promise<void>;
|
|
21
20
|
globalVendorArgs: EvolutionGlobalVendorArgs;
|
|
22
21
|
/**
|
|
23
22
|
* Creates an instance of Evolution Provider
|
|
24
23
|
* @param args Provider configuration
|
|
24
|
+
* @throws Error if required configuration is missing
|
|
25
25
|
*/
|
|
26
26
|
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<
|
|
27
|
+
sendMessageMeta: <K = ApiResponse>(body: any) => Promise<K>;
|
|
28
|
+
sendImageUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
29
|
+
sendVideoUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
30
|
+
sendAudioUrl: (to: string, url: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
31
|
+
sendList: (to: string, list: any) => Promise<ApiResponse>;
|
|
32
|
+
sendListComplete: (to: string, list: any) => Promise<ApiResponse>;
|
|
33
33
|
indexHome?: Middleware<any, any, any, any>;
|
|
34
34
|
/**
|
|
35
35
|
* Initialize HTTP server middleware
|
|
@@ -37,6 +37,7 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
37
37
|
protected beforeHttpServerInit(): void;
|
|
38
38
|
/**
|
|
39
39
|
* Initialize vendor core
|
|
40
|
+
* @returns Promise resolving to the vendor instance
|
|
40
41
|
*/
|
|
41
42
|
protected initVendor(): Promise<any>;
|
|
42
43
|
/**
|
|
@@ -47,77 +48,116 @@ declare class EvolutionProvider extends ProviderClass<EvolutionInterface> implem
|
|
|
47
48
|
private builderHeader;
|
|
48
49
|
/**
|
|
49
50
|
* Verify connection with Evolution API after HTTP server initialization
|
|
50
|
-
|
|
51
|
+
* @throws Error if connection fails
|
|
52
|
+
*/
|
|
53
|
+
protected afterHttpServerInit(): Promise<void>;
|
|
51
54
|
/**
|
|
52
55
|
* Event bus configuration
|
|
56
|
+
* @returns Array of event handlers
|
|
53
57
|
*/
|
|
54
58
|
protected busEvents(): {
|
|
55
59
|
event: string;
|
|
56
|
-
func: (payload:
|
|
60
|
+
func: (payload: unknown) => void;
|
|
57
61
|
}[];
|
|
58
62
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
63
|
+
* Entry point for sending media files.
|
|
64
|
+
* Detects file type and routes to appropriate function.
|
|
61
65
|
*
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
66
|
+
* @param to Destination phone number
|
|
67
|
+
* @param file URL or path to media file
|
|
68
|
+
* @param type Optional media type description (unused but required by interface)
|
|
69
|
+
* @returns Promise resolving to API response
|
|
70
|
+
* @throws Error if file type cannot be determined or exceeds size limit
|
|
71
|
+
*/
|
|
72
|
+
sendMedia: (to: string, file: string, type: string) => Promise<ApiResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Convert file to base64 with size validation
|
|
75
|
+
* @param filePath Path to file
|
|
76
|
+
* @returns Base64 encoded file content
|
|
77
|
+
* @throws Error if file is too large
|
|
65
78
|
*/
|
|
66
|
-
|
|
79
|
+
private fileToBase64;
|
|
67
80
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param number
|
|
70
|
-
* @param filePath
|
|
71
|
-
* @param
|
|
81
|
+
* Prepare media message body
|
|
82
|
+
* @param number Destination number
|
|
83
|
+
* @param filePath Media file path
|
|
84
|
+
* @param mediaType Type of media
|
|
85
|
+
* @param caption Optional caption
|
|
86
|
+
* @returns Prepared message body
|
|
72
87
|
*/
|
|
73
|
-
|
|
88
|
+
private prepareMediaMessageBody;
|
|
74
89
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param number
|
|
77
|
-
* @param filePath
|
|
78
|
-
* @param caption
|
|
90
|
+
* Send an image to the given number
|
|
91
|
+
* @param number Destination number
|
|
92
|
+
* @param filePath Local path to image
|
|
93
|
+
* @param caption Optional text caption
|
|
94
|
+
* @returns Promise resolving to API response
|
|
79
95
|
*/
|
|
80
|
-
|
|
96
|
+
sendImage: (number: string, filePath: string, caption: string) => Promise<ApiResponse>;
|
|
81
97
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
98
|
+
* Send a video to the given number
|
|
99
|
+
* @param to Destination number
|
|
100
|
+
* @param mediaUrl Local path to video
|
|
101
|
+
* @param caption Optional text caption
|
|
102
|
+
* @returns Promise resolving to API response
|
|
85
103
|
*/
|
|
86
|
-
|
|
104
|
+
sendVideo: (to: string, mediaUrl: string, caption?: string) => Promise<ApiResponse>;
|
|
87
105
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
106
|
+
* Send an audio file in compatible format (OPUS)
|
|
107
|
+
* @param to Destination number
|
|
108
|
+
* @param mediaUrl Local path to audio file
|
|
109
|
+
* @param mediaName Optional media name (unused but required by interface)
|
|
110
|
+
* @param caption Optional caption (unused for audio)
|
|
111
|
+
* @returns Promise resolving to API response
|
|
92
112
|
*/
|
|
93
|
-
|
|
113
|
+
sendAudio: (to: string, mediaUrl: string, mediaName?: string, caption?: string) => Promise<ApiResponse>;
|
|
94
114
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param number
|
|
97
|
-
* @param
|
|
115
|
+
* Send a generic document to the given number
|
|
116
|
+
* @param number Destination number
|
|
117
|
+
* @param filePath Local path to the file
|
|
118
|
+
* @param caption Optional text caption
|
|
119
|
+
* @returns Promise resolving to API response
|
|
98
120
|
*/
|
|
99
|
-
|
|
121
|
+
sendFile: (number: string, filePath: string, caption: string) => Promise<ApiResponse>;
|
|
100
122
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param
|
|
103
|
-
* @param
|
|
123
|
+
* Send a plain text message
|
|
124
|
+
* @param number Destination number
|
|
125
|
+
* @param message Message content
|
|
126
|
+
* @returns Promise resolving to API response
|
|
104
127
|
*/
|
|
105
|
-
|
|
128
|
+
sendText: (number: string, message: string) => Promise<ApiResponse>;
|
|
106
129
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @param body
|
|
109
|
-
* @param
|
|
130
|
+
* General function for making POST requests to external API
|
|
131
|
+
* @param body Request body
|
|
132
|
+
* @param endpoint Relative endpoint path (optional)
|
|
133
|
+
* @returns Promise resolving to API response
|
|
134
|
+
* @throws Error if request fails
|
|
110
135
|
*/
|
|
111
|
-
|
|
136
|
+
sendMessageToApi: <K = ApiResponse>(body: any, endpoint?: string) => Promise<K>;
|
|
112
137
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
138
|
+
* Queue a message send to ensure order and avoid conflicts
|
|
139
|
+
* @param body Message body
|
|
140
|
+
* @param endpoint API endpoint
|
|
141
|
+
* @returns Promise resolving to API response
|
|
142
|
+
*/
|
|
143
|
+
sendMessageEvoApi: <K = ApiResponse>(body: any, endpoint: string) => Promise<K>;
|
|
144
|
+
/**
|
|
145
|
+
* General router for sending messages.
|
|
146
|
+
* If it includes media, it's sent as a file. If not, as plain text.
|
|
115
147
|
*
|
|
116
|
-
* @param
|
|
117
|
-
* @param message
|
|
118
|
-
* @param
|
|
148
|
+
* @param to Destination number
|
|
149
|
+
* @param message Text message
|
|
150
|
+
* @param args Additional options (media, etc.)
|
|
151
|
+
* @returns Promise resolving to API response
|
|
152
|
+
*/
|
|
153
|
+
sendMessage<K = ApiResponse>(to: string, message: string, args?: any): Promise<K>;
|
|
154
|
+
/**
|
|
155
|
+
* Save a file from context
|
|
156
|
+
* @param ctx Partial bot context
|
|
157
|
+
* @param options Save options
|
|
158
|
+
* @returns Promise resolving to the file path
|
|
159
|
+
* @throws Error if file cannot be saved
|
|
119
160
|
*/
|
|
120
|
-
sendMessage(number: string, message: string, options?: SendOptions): Promise<any>;
|
|
121
161
|
saveFile: (ctx: Partial<BotContext>, options?: SaveFileOptions) => Promise<string>;
|
|
122
162
|
}
|
|
123
163
|
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.ts"],"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AAO,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;
|
|
@@ -20147,6 +20146,10 @@ class EvolutionCoreVendor extends EventEmitter {
|
|
|
20147
20146
|
}
|
|
20148
20147
|
}
|
|
20149
20148
|
|
|
20149
|
+
// Maximum file size in bytes (10MB)
|
|
20150
|
+
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
20151
|
+
// Default timeout for API requests in ms
|
|
20152
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
20150
20153
|
/**
|
|
20151
20154
|
* Evolution API Provider implementation
|
|
20152
20155
|
* Handles all communication with Evolution API for sending messages, media, etc.
|
|
@@ -20155,6 +20158,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20155
20158
|
/**
|
|
20156
20159
|
* Creates an instance of Evolution Provider
|
|
20157
20160
|
* @param args Provider configuration
|
|
20161
|
+
* @throws Error if required configuration is missing
|
|
20158
20162
|
*/
|
|
20159
20163
|
constructor(args) {
|
|
20160
20164
|
super();
|
|
@@ -20167,163 +20171,225 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20167
20171
|
port: 3000,
|
|
20168
20172
|
};
|
|
20169
20173
|
/**
|
|
20170
|
-
*
|
|
20171
|
-
*
|
|
20174
|
+
* Entry point for sending media files.
|
|
20175
|
+
* Detects file type and routes to appropriate function.
|
|
20172
20176
|
*
|
|
20173
|
-
* @param
|
|
20174
|
-
* @param
|
|
20175
|
-
* @param
|
|
20177
|
+
* @param to Destination phone number
|
|
20178
|
+
* @param file URL or path to media file
|
|
20179
|
+
* @param type Optional media type description (unused but required by interface)
|
|
20180
|
+
* @returns Promise resolving to API response
|
|
20181
|
+
* @throws Error if file type cannot be determined or exceeds size limit
|
|
20176
20182
|
*/
|
|
20177
|
-
this.sendMedia = async (
|
|
20178
|
-
|
|
20179
|
-
|
|
20180
|
-
|
|
20181
|
-
|
|
20182
|
-
|
|
20183
|
-
|
|
20184
|
-
|
|
20185
|
-
|
|
20186
|
-
|
|
20183
|
+
this.sendMedia = async (to, file, type) => {
|
|
20184
|
+
try {
|
|
20185
|
+
const fileDownloaded = await generalDownload(file);
|
|
20186
|
+
// Check file size
|
|
20187
|
+
const stats = fs$1.statSync(fileDownloaded);
|
|
20188
|
+
if (stats.size > MAX_FILE_SIZE) {
|
|
20189
|
+
throw new Error(`File size exceeds limit of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
|
|
20190
|
+
}
|
|
20191
|
+
const mimeType = mime$1.lookup(fileDownloaded);
|
|
20192
|
+
if (!mimeType)
|
|
20193
|
+
throw new Error('Could not determine MIME type');
|
|
20194
|
+
if (mimeType.includes('image')) {
|
|
20195
|
+
return this.sendImage(to, fileDownloaded, type || '');
|
|
20196
|
+
}
|
|
20197
|
+
if (mimeType.includes('video')) {
|
|
20198
|
+
return this.sendVideo(to, fileDownloaded, type || '');
|
|
20199
|
+
}
|
|
20200
|
+
if (mimeType.includes('audio')) {
|
|
20201
|
+
return this.sendAudio(to, fileDownloaded);
|
|
20202
|
+
}
|
|
20203
|
+
return this.sendFile(to, fileDownloaded, type || '');
|
|
20187
20204
|
}
|
|
20188
|
-
|
|
20189
|
-
|
|
20205
|
+
catch (error) {
|
|
20206
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending media';
|
|
20207
|
+
console.error('Error sending media:', errorMessage);
|
|
20208
|
+
throw new Error(`Failed to send media: ${errorMessage}`);
|
|
20190
20209
|
}
|
|
20191
|
-
return this.sendFile(number, fileDownloaded, caption || '');
|
|
20192
20210
|
};
|
|
20193
20211
|
/**
|
|
20194
|
-
*
|
|
20195
|
-
* @param number
|
|
20196
|
-
* @param filePath
|
|
20197
|
-
* @param caption
|
|
20212
|
+
* Send an image to the given number
|
|
20213
|
+
* @param number Destination number
|
|
20214
|
+
* @param filePath Local path to image
|
|
20215
|
+
* @param caption Optional text caption
|
|
20216
|
+
* @returns Promise resolving to API response
|
|
20198
20217
|
*/
|
|
20199
20218
|
this.sendImage = async (number, filePath, caption) => {
|
|
20200
|
-
|
|
20201
|
-
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
|
|
20205
|
-
|
|
20206
|
-
|
|
20207
|
-
|
|
20208
|
-
|
|
20209
|
-
};
|
|
20210
|
-
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20219
|
+
try {
|
|
20220
|
+
const body = await this.prepareMediaMessageBody(number, filePath, 'image', caption);
|
|
20221
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20222
|
+
}
|
|
20223
|
+
catch (error) {
|
|
20224
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending image';
|
|
20225
|
+
console.error('Error sending image:', errorMessage);
|
|
20226
|
+
throw new Error(`Failed to send image: ${errorMessage}`);
|
|
20227
|
+
}
|
|
20211
20228
|
};
|
|
20212
20229
|
/**
|
|
20213
|
-
*
|
|
20214
|
-
* @param
|
|
20215
|
-
* @param
|
|
20216
|
-
* @param caption
|
|
20230
|
+
* Send a video to the given number
|
|
20231
|
+
* @param to Destination number
|
|
20232
|
+
* @param mediaUrl Local path to video
|
|
20233
|
+
* @param caption Optional text caption
|
|
20234
|
+
* @returns Promise resolving to API response
|
|
20217
20235
|
*/
|
|
20218
|
-
this.sendVideo = async (
|
|
20219
|
-
|
|
20220
|
-
|
|
20221
|
-
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20225
|
-
|
|
20226
|
-
|
|
20227
|
-
|
|
20228
|
-
}
|
|
20229
|
-
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20236
|
+
this.sendVideo = async (to, mediaUrl, caption) => {
|
|
20237
|
+
try {
|
|
20238
|
+
const fileDownloaded = mediaUrl.startsWith('http') ? await generalDownload(mediaUrl) : mediaUrl;
|
|
20239
|
+
const body = await this.prepareMediaMessageBody(to, fileDownloaded, 'video', caption);
|
|
20240
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20241
|
+
}
|
|
20242
|
+
catch (error) {
|
|
20243
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending video';
|
|
20244
|
+
console.error('Error sending video:', errorMessage);
|
|
20245
|
+
throw new Error(`Failed to send video: ${errorMessage}`);
|
|
20246
|
+
}
|
|
20230
20247
|
};
|
|
20231
20248
|
/**
|
|
20232
|
-
*
|
|
20233
|
-
* @param
|
|
20234
|
-
* @param
|
|
20249
|
+
* Send an audio file in compatible format (OPUS)
|
|
20250
|
+
* @param to Destination number
|
|
20251
|
+
* @param mediaUrl Local path to audio file
|
|
20252
|
+
* @param mediaName Optional media name (unused but required by interface)
|
|
20253
|
+
* @param caption Optional caption (unused for audio)
|
|
20254
|
+
* @returns Promise resolving to API response
|
|
20235
20255
|
*/
|
|
20236
|
-
this.sendAudio = async (
|
|
20237
|
-
|
|
20238
|
-
|
|
20239
|
-
|
|
20240
|
-
|
|
20241
|
-
|
|
20242
|
-
|
|
20243
|
-
|
|
20244
|
-
|
|
20245
|
-
|
|
20256
|
+
this.sendAudio = async (to, mediaUrl, mediaName, caption) => {
|
|
20257
|
+
try {
|
|
20258
|
+
const fileDownloaded = mediaUrl.startsWith('http') ? await generalDownload(mediaUrl) : mediaUrl;
|
|
20259
|
+
const mediaBase64 = await this.fileToBase64(fileDownloaded);
|
|
20260
|
+
const body = {
|
|
20261
|
+
number: to,
|
|
20262
|
+
media: mediaBase64,
|
|
20263
|
+
mimetype: 'audio/ogg; codecs=opus',
|
|
20264
|
+
mediatype: 'audio',
|
|
20265
|
+
delay: 0,
|
|
20266
|
+
};
|
|
20267
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20268
|
+
}
|
|
20269
|
+
catch (error) {
|
|
20270
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending audio';
|
|
20271
|
+
console.error('Error sending audio:', errorMessage);
|
|
20272
|
+
throw new Error(`Failed to send audio: ${errorMessage}`);
|
|
20273
|
+
}
|
|
20246
20274
|
};
|
|
20247
20275
|
/**
|
|
20248
|
-
*
|
|
20249
|
-
* @param number
|
|
20250
|
-
* @param filePath
|
|
20251
|
-
* @param caption
|
|
20276
|
+
* Send a generic document to the given number
|
|
20277
|
+
* @param number Destination number
|
|
20278
|
+
* @param filePath Local path to the file
|
|
20279
|
+
* @param caption Optional text caption
|
|
20280
|
+
* @returns Promise resolving to API response
|
|
20252
20281
|
*/
|
|
20253
20282
|
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/');
|
|
20283
|
+
try {
|
|
20284
|
+
const body = await this.prepareMediaMessageBody(number, filePath, 'document', caption);
|
|
20285
|
+
return this.sendMessageEvoApi(body, '/message/sendMedia/');
|
|
20286
|
+
}
|
|
20287
|
+
catch (error) {
|
|
20288
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending file';
|
|
20289
|
+
console.error('Error sending file:', errorMessage);
|
|
20290
|
+
throw new Error(`Failed to send file: ${errorMessage}`);
|
|
20291
|
+
}
|
|
20267
20292
|
};
|
|
20268
20293
|
/**
|
|
20269
|
-
*
|
|
20270
|
-
* @param number
|
|
20271
|
-
* @param message
|
|
20294
|
+
* Send a plain text message
|
|
20295
|
+
* @param number Destination number
|
|
20296
|
+
* @param message Message content
|
|
20297
|
+
* @returns Promise resolving to API response
|
|
20272
20298
|
*/
|
|
20273
20299
|
this.sendText = async (number, message) => {
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20300
|
+
try {
|
|
20301
|
+
const endpoint = '/message/sendText/';
|
|
20302
|
+
const body = {
|
|
20303
|
+
number,
|
|
20304
|
+
text: message,
|
|
20305
|
+
delay: 0,
|
|
20306
|
+
};
|
|
20307
|
+
return this.sendMessageEvoApi(body, endpoint);
|
|
20308
|
+
}
|
|
20309
|
+
catch (error) {
|
|
20310
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error sending text';
|
|
20311
|
+
console.error('Error sending text:', errorMessage);
|
|
20312
|
+
throw new Error(`Failed to send text: ${errorMessage}`);
|
|
20313
|
+
}
|
|
20281
20314
|
};
|
|
20282
20315
|
/**
|
|
20283
|
-
*
|
|
20284
|
-
* @param body
|
|
20285
|
-
* @param
|
|
20316
|
+
* General function for making POST requests to external API
|
|
20317
|
+
* @param body Request body
|
|
20318
|
+
* @param endpoint Relative endpoint path (optional)
|
|
20319
|
+
* @returns Promise resolving to API response
|
|
20320
|
+
* @throws Error if request fails
|
|
20286
20321
|
*/
|
|
20287
|
-
this.sendMessageToApi = async (body,
|
|
20322
|
+
this.sendMessageToApi = async (body, endpoint = '/message/') => {
|
|
20288
20323
|
const { baseURL, instanceName, apiKey } = this.globalVendorArgs;
|
|
20289
|
-
const
|
|
20290
|
-
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20324
|
+
const url = `${baseURL}${endpoint}${instanceName}`;
|
|
20325
|
+
try {
|
|
20326
|
+
const response = await fetch(url, {
|
|
20327
|
+
method: 'POST',
|
|
20328
|
+
headers: this.builderHeader(),
|
|
20329
|
+
body: JSON.stringify(body),
|
|
20330
|
+
signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
|
|
20331
|
+
});
|
|
20332
|
+
if (!response.ok) {
|
|
20333
|
+
throw new Error(`Error sending message: ${response.statusText}`);
|
|
20334
|
+
}
|
|
20335
|
+
const data = await response.json();
|
|
20336
|
+
return data;
|
|
20337
|
+
}
|
|
20338
|
+
catch (error) {
|
|
20339
|
+
const message = error instanceof Error ? error.message : 'Unknown error in API request';
|
|
20340
|
+
console.error(`API request failed (${endpoint}):`, message);
|
|
20341
|
+
throw new Error(`API request failed: ${message}`);
|
|
20299
20342
|
}
|
|
20300
|
-
const data = await response.json();
|
|
20301
|
-
return data;
|
|
20302
20343
|
};
|
|
20303
20344
|
/**
|
|
20304
|
-
*
|
|
20305
|
-
* @param body
|
|
20306
|
-
* @param
|
|
20345
|
+
* Queue a message send to ensure order and avoid conflicts
|
|
20346
|
+
* @param body Message body
|
|
20347
|
+
* @param endpoint API endpoint
|
|
20348
|
+
* @returns Promise resolving to API response
|
|
20307
20349
|
*/
|
|
20308
|
-
this.sendMessageEvoApi = (body,
|
|
20309
|
-
return new Promise((resolve) => this.queue.add(async () => {
|
|
20310
|
-
|
|
20311
|
-
|
|
20350
|
+
this.sendMessageEvoApi = (body, endpoint) => {
|
|
20351
|
+
return new Promise((resolve, reject) => this.queue.add(async () => {
|
|
20352
|
+
try {
|
|
20353
|
+
const resp = await this.sendMessageToApi(body, endpoint);
|
|
20354
|
+
resolve(resp);
|
|
20355
|
+
}
|
|
20356
|
+
catch (error) {
|
|
20357
|
+
reject(error);
|
|
20358
|
+
}
|
|
20312
20359
|
}));
|
|
20313
20360
|
};
|
|
20361
|
+
/**
|
|
20362
|
+
* Save a file from context
|
|
20363
|
+
* @param ctx Partial bot context
|
|
20364
|
+
* @param options Save options
|
|
20365
|
+
* @returns Promise resolving to the file path
|
|
20366
|
+
* @throws Error if file cannot be saved
|
|
20367
|
+
*/
|
|
20314
20368
|
this.saveFile = async (ctx, options = {}) => {
|
|
20315
20369
|
try {
|
|
20370
|
+
if (!ctx.base64) {
|
|
20371
|
+
throw new Error('No base64 data provided');
|
|
20372
|
+
}
|
|
20316
20373
|
const buffer = ctx.base64;
|
|
20317
|
-
const extension = mime$1.extension(ctx.mimetype);
|
|
20374
|
+
const extension = mime$1.extension(ctx.mimetype ?? 'application/octet-stream');
|
|
20318
20375
|
const fileName = `file-${Date.now()}.${extension}`;
|
|
20319
|
-
const pathFile =
|
|
20376
|
+
const pathFile = require$$1$1.join(options?.path ?? require$$0$2.tmpdir(), fileName);
|
|
20320
20377
|
await promises.writeFile(pathFile, buffer);
|
|
20321
|
-
return
|
|
20378
|
+
return require$$1$1.resolve(pathFile);
|
|
20322
20379
|
}
|
|
20323
20380
|
catch (error) {
|
|
20324
|
-
|
|
20381
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error saving file';
|
|
20382
|
+
console.error('Error saving file:', errorMessage);
|
|
20383
|
+
return Promise.reject(new Error(`Failed to save file: ${errorMessage}`));
|
|
20325
20384
|
}
|
|
20326
20385
|
};
|
|
20386
|
+
// Validate required parameters
|
|
20387
|
+
if (!args.apiKey) {
|
|
20388
|
+
throw new Error('API Key is required');
|
|
20389
|
+
}
|
|
20390
|
+
if (!args.instanceName) {
|
|
20391
|
+
throw new Error('Instance name is required');
|
|
20392
|
+
}
|
|
20327
20393
|
this.globalVendorArgs = { ...this.globalVendorArgs, ...args };
|
|
20328
20394
|
this.queue = new Queue({
|
|
20329
20395
|
concurrent: 1,
|
|
@@ -20336,7 +20402,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20336
20402
|
*/
|
|
20337
20403
|
beforeHttpServerInit() {
|
|
20338
20404
|
this.server = this.server
|
|
20339
|
-
.use(json())
|
|
20405
|
+
.use(json({ limit: '50mb' }))
|
|
20340
20406
|
.use((req, _, next) => {
|
|
20341
20407
|
req['globalVendorArgs'] = this.globalVendorArgs;
|
|
20342
20408
|
return next();
|
|
@@ -20346,6 +20412,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20346
20412
|
}
|
|
20347
20413
|
/**
|
|
20348
20414
|
* Initialize vendor core
|
|
20415
|
+
* @returns Promise resolving to the vendor instance
|
|
20349
20416
|
*/
|
|
20350
20417
|
initVendor() {
|
|
20351
20418
|
const vendor = new EvolutionCoreVendor(this.queue);
|
|
@@ -20361,19 +20428,23 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20361
20428
|
const { apiKey } = this.globalVendorArgs;
|
|
20362
20429
|
return {
|
|
20363
20430
|
apikey: apiKey,
|
|
20431
|
+
'Content-Type': 'application/json',
|
|
20364
20432
|
...additionalHeaders,
|
|
20365
20433
|
};
|
|
20366
20434
|
}
|
|
20367
20435
|
/**
|
|
20368
20436
|
* Verify connection with Evolution API after HTTP server initialization
|
|
20369
|
-
|
|
20437
|
+
* @throws Error if connection fails
|
|
20438
|
+
*/
|
|
20439
|
+
async afterHttpServerInit() {
|
|
20370
20440
|
try {
|
|
20371
20441
|
const { baseURL, instanceName } = this.globalVendorArgs;
|
|
20372
20442
|
// Verify connection with Evolution API
|
|
20373
20443
|
const response = await axios.get(`${baseURL}/instance/connectionState/${instanceName}`, {
|
|
20374
20444
|
headers: this.builderHeader(),
|
|
20445
|
+
timeout: DEFAULT_TIMEOUT,
|
|
20375
20446
|
});
|
|
20376
|
-
const state = response.data
|
|
20447
|
+
const state = response.data?.state ?? response.data?.instance?.state ?? 'close';
|
|
20377
20448
|
if (state === 'open') {
|
|
20378
20449
|
this.emit('ready');
|
|
20379
20450
|
}
|
|
@@ -20395,6 +20466,7 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20395
20466
|
}
|
|
20396
20467
|
/**
|
|
20397
20468
|
* Event bus configuration
|
|
20469
|
+
* @returns Array of event handlers
|
|
20398
20470
|
*/
|
|
20399
20471
|
busEvents() {
|
|
20400
20472
|
return [
|
|
@@ -20419,18 +20491,72 @@ class EvolutionProvider extends bot.ProviderClass {
|
|
|
20419
20491
|
];
|
|
20420
20492
|
}
|
|
20421
20493
|
/**
|
|
20422
|
-
*
|
|
20423
|
-
*
|
|
20494
|
+
* Convert file to base64 with size validation
|
|
20495
|
+
* @param filePath Path to file
|
|
20496
|
+
* @returns Base64 encoded file content
|
|
20497
|
+
* @throws Error if file is too large
|
|
20498
|
+
*/
|
|
20499
|
+
async fileToBase64(filePath) {
|
|
20500
|
+
const stats = fs$1.statSync(filePath);
|
|
20501
|
+
if (stats.size > MAX_FILE_SIZE) {
|
|
20502
|
+
throw new Error(`File size exceeds limit of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
|
|
20503
|
+
}
|
|
20504
|
+
return fs$1.readFileSync(filePath, { encoding: 'base64' });
|
|
20505
|
+
}
|
|
20506
|
+
/**
|
|
20507
|
+
* Prepare media message body
|
|
20508
|
+
* @param number Destination number
|
|
20509
|
+
* @param filePath Media file path
|
|
20510
|
+
* @param mediaType Type of media
|
|
20511
|
+
* @param caption Optional caption
|
|
20512
|
+
* @returns Prepared message body
|
|
20513
|
+
*/
|
|
20514
|
+
async prepareMediaMessageBody(number, filePath, mediaType, caption) {
|
|
20515
|
+
const mediaBase64 = await this.fileToBase64(filePath);
|
|
20516
|
+
const mimeType = mime$1.lookup(filePath) || 'application/octet-stream';
|
|
20517
|
+
const fileName = require$$1$1.basename(filePath);
|
|
20518
|
+
const body = {
|
|
20519
|
+
number,
|
|
20520
|
+
media: mediaBase64,
|
|
20521
|
+
mimetype: mimeType,
|
|
20522
|
+
mediatype: mediaType,
|
|
20523
|
+
caption: caption || fileName,
|
|
20524
|
+
delay: 0,
|
|
20525
|
+
};
|
|
20526
|
+
if (mediaType === 'document') {
|
|
20527
|
+
body.fileName = fileName;
|
|
20528
|
+
}
|
|
20529
|
+
return body;
|
|
20530
|
+
}
|
|
20531
|
+
/**
|
|
20532
|
+
* General router for sending messages.
|
|
20533
|
+
* If it includes media, it's sent as a file. If not, as plain text.
|
|
20424
20534
|
*
|
|
20425
|
-
* @param
|
|
20426
|
-
* @param message
|
|
20427
|
-
* @param
|
|
20535
|
+
* @param to Destination number
|
|
20536
|
+
* @param message Text message
|
|
20537
|
+
* @param args Additional options (media, etc.)
|
|
20538
|
+
* @returns Promise resolving to API response
|
|
20428
20539
|
*/
|
|
20429
|
-
async sendMessage(
|
|
20430
|
-
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20540
|
+
async sendMessage(to, message, args) {
|
|
20541
|
+
try {
|
|
20542
|
+
// Sanitize phone number (remove non-numeric chars except +)
|
|
20543
|
+
const sanitizedNumber = to.replace(/[^\d+]/g, '');
|
|
20544
|
+
// Process options
|
|
20545
|
+
const options = args;
|
|
20546
|
+
const mergedOptions = { ...options, ...options?.['options'] };
|
|
20547
|
+
let response;
|
|
20548
|
+
if (mergedOptions?.media) {
|
|
20549
|
+
response = await this.sendMedia(sanitizedNumber, mergedOptions.media, mergedOptions.type || '');
|
|
20550
|
+
}
|
|
20551
|
+
else {
|
|
20552
|
+
response = await this.sendText(sanitizedNumber, message);
|
|
20553
|
+
}
|
|
20554
|
+
return response;
|
|
20555
|
+
}
|
|
20556
|
+
catch (error) {
|
|
20557
|
+
console.error('Error in sendMessage:', error);
|
|
20558
|
+
throw error;
|
|
20559
|
+
}
|
|
20434
20560
|
}
|
|
20435
20561
|
}
|
|
20436
20562
|
|
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,EAAE,MAAM,CAAA;IACxB,kBAAkB,EAAE,MAAM,CAAA;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,yBAAyB,EAAE,MAAM,CAAA;IACjC,aAAa,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACjB,cAAc,GACd,cAAc,GACd,cAAc,GACd,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,qBAAq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,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.9",
|
|
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.9",
|
|
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": "8fc7f609ee9615e058a3fff51d37f5b578cd9a61"
|
|
69
69
|
}
|