@builderbot/provider-meta 1.0.20-alpha.0 → 1.0.23-alpha.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/index.cjs +219 -408
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/meta.d.ts +49 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/metaInterface.d.ts +26 -0
- package/dist/metaInterface.d.ts.map +1 -0
- package/dist/server.d.ts +7 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/number.d.ts +2 -0
- package/dist/utils/number.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/metaProvider.d.ts +0 -160
- package/dist/metaProvider.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -31872,10 +31872,33 @@ async function getProfile(version, numberId, token) {
|
|
|
31872
31872
|
}
|
|
31873
31873
|
}
|
|
31874
31874
|
|
|
31875
|
-
const
|
|
31875
|
+
const parseMetaNumber = (number) => {
|
|
31876
|
+
number = number.replace(/\+/g, '');
|
|
31877
|
+
return number;
|
|
31878
|
+
};
|
|
31879
|
+
|
|
31880
|
+
const idCtxBot = 'id-ctx-bot';
|
|
31881
|
+
const idBotName = 'id-bot';
|
|
31876
31882
|
class MetaWebHookServer extends node_events.EventEmitter {
|
|
31877
31883
|
constructor(jwtToken, numberId, version, token, metaPort = 3000) {
|
|
31878
31884
|
super();
|
|
31885
|
+
this.getListRoutes = (app) => {
|
|
31886
|
+
try {
|
|
31887
|
+
const list = app.routes;
|
|
31888
|
+
const methodKeys = Object.keys(list);
|
|
31889
|
+
const parseListRoutes = methodKeys.reduce((prev, current) => {
|
|
31890
|
+
const routesForMethod = list[current].flat(2).map((i) => ({ method: current, path: i.old }));
|
|
31891
|
+
prev = prev.concat(routesForMethod);
|
|
31892
|
+
return prev;
|
|
31893
|
+
}, []);
|
|
31894
|
+
const unique = parseListRoutes.map((r) => `[${r.method}]: http://localhost:${this.port}${r.path}`);
|
|
31895
|
+
return [...new Set(unique)];
|
|
31896
|
+
}
|
|
31897
|
+
catch (e) {
|
|
31898
|
+
console.log(`[Error]:`, e);
|
|
31899
|
+
return [];
|
|
31900
|
+
}
|
|
31901
|
+
};
|
|
31879
31902
|
/**
|
|
31880
31903
|
* Mensaje entrante
|
|
31881
31904
|
* emit: 'message'
|
|
@@ -31938,7 +31961,7 @@ class MetaWebHookServer extends node_events.EventEmitter {
|
|
|
31938
31961
|
return;
|
|
31939
31962
|
}
|
|
31940
31963
|
if (this.tokenIsValid(mode, token)) {
|
|
31941
|
-
|
|
31964
|
+
this.emit('ready');
|
|
31942
31965
|
res.statusCode = 200;
|
|
31943
31966
|
res.end(challenge);
|
|
31944
31967
|
return;
|
|
@@ -31947,7 +31970,7 @@ class MetaWebHookServer extends node_events.EventEmitter {
|
|
|
31947
31970
|
res.end('Invalid token!');
|
|
31948
31971
|
};
|
|
31949
31972
|
this.emptyCtrl = (_, res) => {
|
|
31950
|
-
res.end('');
|
|
31973
|
+
res.end('running ok');
|
|
31951
31974
|
};
|
|
31952
31975
|
this.port = metaPort;
|
|
31953
31976
|
this.token = token;
|
|
@@ -31985,27 +32008,24 @@ class MetaWebHookServer extends node_events.EventEmitter {
|
|
|
31985
32008
|
/**
|
|
31986
32009
|
* Iniciar el servidor HTTP
|
|
31987
32010
|
*/
|
|
31988
|
-
async start(vendor, port) {
|
|
32011
|
+
async start(vendor, port, args, cb = () => null) {
|
|
31989
32012
|
if (port)
|
|
31990
32013
|
this.port = port;
|
|
31991
32014
|
this.server.use(async (req, _, next) => {
|
|
31992
32015
|
req[idCtxBot] = vendor;
|
|
32016
|
+
req[idBotName] = args?.botName ?? 'bot';
|
|
31993
32017
|
if (req[idCtxBot])
|
|
31994
32018
|
return next();
|
|
31995
32019
|
return next();
|
|
31996
32020
|
});
|
|
31997
|
-
this.server.listen(this.port, () => {
|
|
31998
|
-
console.log(`[meta]: Agregar esta url "Webhook"`);
|
|
31999
|
-
console.log(`[meta]: POST http://localhost:${this.port}/webhook`);
|
|
32000
|
-
console.log(`[meta]: Más información en la documentación`);
|
|
32001
|
-
});
|
|
32002
32021
|
const profile = await getProfile(this.version, this.numberId, this.jwtToken);
|
|
32003
32022
|
const host = {
|
|
32004
32023
|
...profile,
|
|
32005
32024
|
phone: profile?.display_phone_number,
|
|
32006
32025
|
};
|
|
32007
|
-
this.emit('ready');
|
|
32008
32026
|
this.emit('host', host);
|
|
32027
|
+
const routes = this.getListRoutes(this.server).join('\n');
|
|
32028
|
+
this.server.listen(this.port, cb(routes));
|
|
32009
32029
|
}
|
|
32010
32030
|
stop() {
|
|
32011
32031
|
return new Promise((resolve, reject) => {
|
|
@@ -32023,49 +32043,39 @@ class MetaWebHookServer extends node_events.EventEmitter {
|
|
|
32023
32043
|
|
|
32024
32044
|
const URL = `https://graph.facebook.com`;
|
|
32025
32045
|
class MetaProvider extends bot.ProviderClass {
|
|
32026
|
-
constructor(
|
|
32046
|
+
constructor(args) {
|
|
32027
32047
|
super();
|
|
32028
|
-
this.
|
|
32029
|
-
this.
|
|
32030
|
-
|
|
32031
|
-
|
|
32032
|
-
|
|
32033
|
-
|
|
32048
|
+
this.queue = new Queue();
|
|
32049
|
+
this.globalVendorArgs = {
|
|
32050
|
+
name: 'bot',
|
|
32051
|
+
jwtToken: undefined,
|
|
32052
|
+
numberId: undefined,
|
|
32053
|
+
verifyToken: undefined,
|
|
32054
|
+
version: 'v18.0',
|
|
32034
32055
|
};
|
|
32035
32056
|
/**
|
|
32036
32057
|
*
|
|
32037
|
-
* @param
|
|
32038
|
-
* @param
|
|
32058
|
+
* @param ctx
|
|
32059
|
+
* @param options
|
|
32039
32060
|
* @returns
|
|
32040
32061
|
*/
|
|
32041
|
-
this.
|
|
32042
|
-
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
|
|
32049
|
-
|
|
32050
|
-
|
|
32051
|
-
|
|
32052
|
-
|
|
32053
|
-
});
|
|
32054
|
-
},
|
|
32055
|
-
};
|
|
32056
|
-
this.http.start(methods, port);
|
|
32057
|
-
this.listenOnEvents();
|
|
32058
|
-
return;
|
|
32062
|
+
this.saveFile = async (ctx, options = {}) => {
|
|
32063
|
+
try {
|
|
32064
|
+
const { buffer, extension } = await downloadFile(ctx?.url, this.globalVendorArgs.jwtToken);
|
|
32065
|
+
const fileName = `file-${Date.now()}.${extension}`;
|
|
32066
|
+
const pathFile = require$$1$3.join(options?.path ?? os.tmpdir(), fileName);
|
|
32067
|
+
await promises.writeFile(pathFile, buffer);
|
|
32068
|
+
return pathFile;
|
|
32069
|
+
}
|
|
32070
|
+
catch (err) {
|
|
32071
|
+
console.log(`[Error]:`, err.message);
|
|
32072
|
+
return 'ERROR';
|
|
32073
|
+
}
|
|
32059
32074
|
};
|
|
32060
|
-
/**
|
|
32061
|
-
* Mapeamos los eventos nativos a los que la clase Provider espera
|
|
32062
|
-
* para tener un standar de eventos
|
|
32063
|
-
* @returns
|
|
32064
|
-
*/
|
|
32065
32075
|
this.busEvents = () => [
|
|
32066
32076
|
{
|
|
32067
32077
|
event: 'auth_failure',
|
|
32068
|
-
func: (payload) => this.emit('
|
|
32078
|
+
func: (payload) => this.emit('auth_failure', payload),
|
|
32069
32079
|
},
|
|
32070
32080
|
{
|
|
32071
32081
|
event: 'ready',
|
|
@@ -32084,20 +32094,45 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32084
32094
|
},
|
|
32085
32095
|
},
|
|
32086
32096
|
];
|
|
32087
|
-
this.
|
|
32088
|
-
const
|
|
32089
|
-
|
|
32090
|
-
|
|
32091
|
-
|
|
32092
|
-
|
|
32093
|
-
|
|
32094
|
-
|
|
32095
|
-
|
|
32097
|
+
this.listenOnEvents = () => {
|
|
32098
|
+
const listEvents = this.busEvents();
|
|
32099
|
+
for (const { event, func } of listEvents) {
|
|
32100
|
+
this.http.on(event, func);
|
|
32101
|
+
}
|
|
32102
|
+
};
|
|
32103
|
+
this.initHttpServer = (port, opts) => {
|
|
32104
|
+
const methods = {
|
|
32105
|
+
sendMessage: this.sendMessage,
|
|
32106
|
+
provider: this,
|
|
32107
|
+
blacklist: opts.blacklist,
|
|
32108
|
+
dispatch: (customEvent, payload) => {
|
|
32109
|
+
this.emit('message', {
|
|
32110
|
+
...payload,
|
|
32111
|
+
body: bot.utils.setEvent(customEvent),
|
|
32112
|
+
name: payload.name,
|
|
32113
|
+
from: bot.utils.removePlus(payload.from),
|
|
32114
|
+
});
|
|
32096
32115
|
},
|
|
32097
32116
|
};
|
|
32098
|
-
|
|
32117
|
+
this.http.start(methods, port, { botName: this.globalVendorArgs.name }, (routes) => {
|
|
32118
|
+
this.emit('notice', {
|
|
32119
|
+
title: '🛜 HTTP Server ON ',
|
|
32120
|
+
instructions: routes,
|
|
32121
|
+
});
|
|
32122
|
+
this.emit('notice', {
|
|
32123
|
+
title: '⚡⚡ SETUP META/FACEBOOK ⚡⚡',
|
|
32124
|
+
instructions: [
|
|
32125
|
+
`Add "Webhook" URL`,
|
|
32126
|
+
`http://localhost:${port}/webhook`,
|
|
32127
|
+
`More info https://builderbot.vercel.app/en/providers/meta`,
|
|
32128
|
+
],
|
|
32129
|
+
});
|
|
32130
|
+
});
|
|
32131
|
+
this.listenOnEvents();
|
|
32132
|
+
return;
|
|
32099
32133
|
};
|
|
32100
32134
|
this.sendImage = async (to, mediaInput = null) => {
|
|
32135
|
+
to = parseMetaNumber(to);
|
|
32101
32136
|
if (!mediaInput)
|
|
32102
32137
|
throw new Error(`MEDIA_INPUT_NULL_: ${mediaInput}`);
|
|
32103
32138
|
const formData = new FormData$1();
|
|
@@ -32106,9 +32141,9 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32106
32141
|
contentType: mimeType,
|
|
32107
32142
|
});
|
|
32108
32143
|
formData.append('messaging_product', 'whatsapp');
|
|
32109
|
-
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.version}/${this.numberId}/media`, formData, {
|
|
32144
|
+
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.globalVendorArgs.version}/${this.globalVendorArgs.numberId}/media`, formData, {
|
|
32110
32145
|
headers: {
|
|
32111
|
-
Authorization: `Bearer ${this.jwtToken}`,
|
|
32146
|
+
Authorization: `Bearer ${this.globalVendorArgs.jwtToken}`,
|
|
32112
32147
|
...formData.getHeaders(),
|
|
32113
32148
|
},
|
|
32114
32149
|
});
|
|
@@ -32122,14 +32157,8 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32122
32157
|
};
|
|
32123
32158
|
return this.sendMessageMeta(body);
|
|
32124
32159
|
};
|
|
32125
|
-
/**
|
|
32126
|
-
*
|
|
32127
|
-
* @param {*} number
|
|
32128
|
-
* @param {*} _
|
|
32129
|
-
* @param {*} pathVideo
|
|
32130
|
-
* @returns
|
|
32131
|
-
*/
|
|
32132
32160
|
this.sendVideo = async (to, pathVideo = null) => {
|
|
32161
|
+
to = parseMetaNumber(to);
|
|
32133
32162
|
if (!pathVideo)
|
|
32134
32163
|
throw new Error(`MEDIA_INPUT_NULL_: ${pathVideo}`);
|
|
32135
32164
|
const formData = new FormData$1();
|
|
@@ -32138,9 +32167,9 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32138
32167
|
contentType: mimeType,
|
|
32139
32168
|
});
|
|
32140
32169
|
formData.append('messaging_product', 'whatsapp');
|
|
32141
|
-
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.version}/${this.numberId}/media`, formData, {
|
|
32170
|
+
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.globalVendorArgs.version}/${this.globalVendorArgs.numberId}/media`, formData, {
|
|
32142
32171
|
headers: {
|
|
32143
|
-
Authorization: `Bearer ${this.jwtToken}`,
|
|
32172
|
+
Authorization: `Bearer ${this.globalVendorArgs.jwtToken}`,
|
|
32144
32173
|
...formData.getHeaders(),
|
|
32145
32174
|
},
|
|
32146
32175
|
});
|
|
@@ -32154,13 +32183,9 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32154
32183
|
};
|
|
32155
32184
|
return this.sendMessageMeta(body);
|
|
32156
32185
|
};
|
|
32157
|
-
|
|
32158
|
-
|
|
32159
|
-
|
|
32160
|
-
* @param {string} message
|
|
32161
|
-
* @example await sendMessage('+XXXXXXXXXXX', 'https://dominio.com/imagen.jpg' | 'img/imagen.jpg')
|
|
32162
|
-
*/
|
|
32163
|
-
this.sendMedia = async (to, text = '', mediaInput) => {
|
|
32186
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32187
|
+
this.sendMedia = async (to, _ = '', mediaInput) => {
|
|
32188
|
+
to = parseMetaNumber(to);
|
|
32164
32189
|
const fileDownloaded = await bot.utils.generalDownload(mediaInput);
|
|
32165
32190
|
const mimeType = mime$1.lookup(fileDownloaded);
|
|
32166
32191
|
mediaInput = fileDownloaded;
|
|
@@ -32169,19 +32194,13 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32169
32194
|
if (mimeType.includes('video'))
|
|
32170
32195
|
return this.sendVideo(to, fileDownloaded);
|
|
32171
32196
|
if (mimeType.includes('audio')) {
|
|
32172
|
-
const fileOpus = await bot.utils.convertAudio(mediaInput);
|
|
32173
|
-
return this.sendAudio(to, fileOpus
|
|
32197
|
+
const fileOpus = await bot.utils.convertAudio(mediaInput, 'mp3');
|
|
32198
|
+
return this.sendAudio(to, fileOpus);
|
|
32174
32199
|
}
|
|
32175
32200
|
return this.sendFile(to, mediaInput);
|
|
32176
32201
|
};
|
|
32177
|
-
|
|
32178
|
-
|
|
32179
|
-
* @param {*} number
|
|
32180
|
-
* @param {*} text
|
|
32181
|
-
* @param {*} buttons
|
|
32182
|
-
* @returns
|
|
32183
|
-
*/
|
|
32184
|
-
this.sendLists = async (to, list) => {
|
|
32202
|
+
this.sendList = async (to, list) => {
|
|
32203
|
+
to = parseMetaNumber(to);
|
|
32185
32204
|
const parseList = { ...list, ...{ type: 'list' } };
|
|
32186
32205
|
const body = {
|
|
32187
32206
|
messaging_product: 'whatsapp',
|
|
@@ -32192,63 +32211,13 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32192
32211
|
};
|
|
32193
32212
|
return this.sendMessageMeta(body);
|
|
32194
32213
|
};
|
|
32195
|
-
|
|
32196
|
-
|
|
32197
|
-
* @param {*} number
|
|
32198
|
-
* @param {*} header
|
|
32199
|
-
* @param {*} text
|
|
32200
|
-
* @param {*} footer
|
|
32201
|
-
* @param {*} button
|
|
32202
|
-
* @param {*} list
|
|
32203
|
-
* @returns
|
|
32204
|
-
*/
|
|
32205
|
-
this.sendList = async (to, header, text, footer, button, list = []) => {
|
|
32206
|
-
const parseList = list.map((list) => ({
|
|
32207
|
-
title: list.title,
|
|
32208
|
-
rows: list.rows.map((row) => ({
|
|
32209
|
-
id: row.id,
|
|
32210
|
-
title: row.title,
|
|
32211
|
-
description: row.description,
|
|
32212
|
-
})),
|
|
32213
|
-
}));
|
|
32214
|
-
const body = {
|
|
32215
|
-
messaging_product: 'whatsapp',
|
|
32216
|
-
recipient_type: 'individual',
|
|
32217
|
-
to,
|
|
32218
|
-
type: 'interactive',
|
|
32219
|
-
interactive: {
|
|
32220
|
-
type: 'list',
|
|
32221
|
-
header: {
|
|
32222
|
-
type: 'text',
|
|
32223
|
-
text: header,
|
|
32224
|
-
},
|
|
32225
|
-
body: {
|
|
32226
|
-
text: text,
|
|
32227
|
-
},
|
|
32228
|
-
footer: {
|
|
32229
|
-
text: footer,
|
|
32230
|
-
},
|
|
32231
|
-
action: {
|
|
32232
|
-
button: button,
|
|
32233
|
-
sections: parseList,
|
|
32234
|
-
},
|
|
32235
|
-
},
|
|
32236
|
-
};
|
|
32237
|
-
return this.sendMessageMeta(body);
|
|
32238
|
-
};
|
|
32239
|
-
/**
|
|
32240
|
-
* Enviar buttons
|
|
32241
|
-
* @param {*} number
|
|
32242
|
-
* @param {*} text
|
|
32243
|
-
* @param {*} buttons
|
|
32244
|
-
* @returns
|
|
32245
|
-
*/
|
|
32246
|
-
this.sendButtons = async (to, text, buttons = []) => {
|
|
32214
|
+
this.sendButtons = async (to, buttons = [], text) => {
|
|
32215
|
+
to = parseMetaNumber(to);
|
|
32247
32216
|
const parseButtons = buttons.map((btn, i) => ({
|
|
32248
32217
|
type: 'reply',
|
|
32249
32218
|
reply: {
|
|
32250
32219
|
id: `btn-${i}`,
|
|
32251
|
-
title: btn.body,
|
|
32220
|
+
title: btn.body.slice(0, 15),
|
|
32252
32221
|
},
|
|
32253
32222
|
}));
|
|
32254
32223
|
const body = {
|
|
@@ -32259,7 +32228,7 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32259
32228
|
interactive: {
|
|
32260
32229
|
type: 'button',
|
|
32261
32230
|
body: {
|
|
32262
|
-
text
|
|
32231
|
+
text,
|
|
32263
32232
|
},
|
|
32264
32233
|
action: {
|
|
32265
32234
|
buttons: parseButtons,
|
|
@@ -32268,213 +32237,55 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32268
32237
|
};
|
|
32269
32238
|
return this.sendMessageMeta(body);
|
|
32270
32239
|
};
|
|
32271
|
-
|
|
32272
|
-
|
|
32273
|
-
* @param {*} number
|
|
32274
|
-
* @param {*} text
|
|
32275
|
-
* @param {*} buttons
|
|
32276
|
-
* @returns
|
|
32277
|
-
*/
|
|
32278
|
-
this.sendButtonsText = async (to, text, buttons = []) => {
|
|
32279
|
-
const parseButtons = buttons.map((btn) => ({
|
|
32280
|
-
type: 'reply',
|
|
32281
|
-
reply: {
|
|
32282
|
-
id: btn.id,
|
|
32283
|
-
title: btn.title,
|
|
32284
|
-
},
|
|
32285
|
-
}));
|
|
32240
|
+
this.sendButtonUrl = async (to, button, text) => {
|
|
32241
|
+
to = parseMetaNumber(to);
|
|
32286
32242
|
const body = {
|
|
32287
32243
|
messaging_product: 'whatsapp',
|
|
32288
32244
|
recipient_type: 'individual',
|
|
32289
32245
|
to,
|
|
32290
32246
|
type: 'interactive',
|
|
32291
32247
|
interactive: {
|
|
32292
|
-
type: '
|
|
32248
|
+
type: 'cta_url',
|
|
32293
32249
|
body: {
|
|
32294
|
-
text
|
|
32250
|
+
text,
|
|
32295
32251
|
},
|
|
32296
32252
|
action: {
|
|
32297
|
-
|
|
32298
|
-
|
|
32299
|
-
|
|
32300
|
-
|
|
32301
|
-
return this.sendMessageMeta(body);
|
|
32302
|
-
};
|
|
32303
|
-
/**
|
|
32304
|
-
* Enviar buttons with image
|
|
32305
|
-
* @param {*} number
|
|
32306
|
-
* @param {*} text
|
|
32307
|
-
* @param {*} buttons
|
|
32308
|
-
* @param {*} url
|
|
32309
|
-
* @returns
|
|
32310
|
-
*/
|
|
32311
|
-
this.sendButtonsMedia = async (to, text, buttons = [], url) => {
|
|
32312
|
-
const parseButtons = buttons.map((btn) => ({
|
|
32313
|
-
type: 'reply',
|
|
32314
|
-
reply: {
|
|
32315
|
-
id: btn.id,
|
|
32316
|
-
title: btn.title,
|
|
32317
|
-
},
|
|
32318
|
-
}));
|
|
32319
|
-
const body = {
|
|
32320
|
-
messaging_product: 'whatsapp',
|
|
32321
|
-
recipient_type: 'individual',
|
|
32322
|
-
to,
|
|
32323
|
-
type: 'interactive',
|
|
32324
|
-
interactive: {
|
|
32325
|
-
type: 'button',
|
|
32326
|
-
header: {
|
|
32327
|
-
type: 'image',
|
|
32328
|
-
image: {
|
|
32329
|
-
link: url,
|
|
32253
|
+
name: 'cta_url',
|
|
32254
|
+
parameters: {
|
|
32255
|
+
display_text: button.body.slice(0, 15),
|
|
32256
|
+
url: button.url,
|
|
32330
32257
|
},
|
|
32331
32258
|
},
|
|
32332
|
-
body: {
|
|
32333
|
-
text: text,
|
|
32334
|
-
},
|
|
32335
|
-
action: {
|
|
32336
|
-
buttons: parseButtons,
|
|
32337
|
-
},
|
|
32338
32259
|
},
|
|
32339
32260
|
};
|
|
32340
32261
|
return this.sendMessageMeta(body);
|
|
32341
32262
|
};
|
|
32342
|
-
|
|
32343
|
-
|
|
32344
|
-
|
|
32345
|
-
* @param {*} template
|
|
32346
|
-
* @param {*} languageCode
|
|
32347
|
-
* Usarse de acuerdo a cada plantilla en particular, esto solo es un mapeo de como funciona.
|
|
32348
|
-
* @returns
|
|
32349
|
-
*/
|
|
32350
|
-
this.sendTemplate = async (number, template, languageCode) => {
|
|
32351
|
-
const body = {
|
|
32352
|
-
messaging_product: 'whatsapp',
|
|
32353
|
-
recipient_type: 'individual',
|
|
32354
|
-
to: number,
|
|
32355
|
-
type: 'template',
|
|
32356
|
-
template: {
|
|
32357
|
-
name: template,
|
|
32358
|
-
language: {
|
|
32359
|
-
code: languageCode, // examples: es_Mex, en_Us
|
|
32360
|
-
},
|
|
32361
|
-
components: [
|
|
32362
|
-
{
|
|
32363
|
-
type: 'header',
|
|
32364
|
-
parameters: [
|
|
32365
|
-
{
|
|
32366
|
-
type: 'image',
|
|
32367
|
-
image: {
|
|
32368
|
-
link: 'https://i.imgur.com/3xUQq0U.png',
|
|
32369
|
-
},
|
|
32370
|
-
},
|
|
32371
|
-
],
|
|
32372
|
-
},
|
|
32373
|
-
{
|
|
32374
|
-
type: 'body',
|
|
32375
|
-
parameters: [
|
|
32376
|
-
{
|
|
32377
|
-
type: 'text', // currency, date_time, etc
|
|
32378
|
-
text: 'text-string',
|
|
32379
|
-
},
|
|
32380
|
-
{
|
|
32381
|
-
type: 'currency',
|
|
32382
|
-
currency: {
|
|
32383
|
-
fallback_value: '$100.99',
|
|
32384
|
-
code: 'USD',
|
|
32385
|
-
amount_1000: 100990,
|
|
32386
|
-
},
|
|
32387
|
-
},
|
|
32388
|
-
],
|
|
32389
|
-
},
|
|
32390
|
-
{
|
|
32391
|
-
type: 'button',
|
|
32392
|
-
subtype: 'quick_reply',
|
|
32393
|
-
index: 0,
|
|
32394
|
-
parameters: [
|
|
32395
|
-
{
|
|
32396
|
-
type: 'payload',
|
|
32397
|
-
payload: 'aGlzIHRoaXMgaXMgY29v',
|
|
32398
|
-
},
|
|
32399
|
-
],
|
|
32400
|
-
},
|
|
32401
|
-
],
|
|
32402
|
-
},
|
|
32403
|
-
};
|
|
32263
|
+
this.sendTemplate = async (to, template) => {
|
|
32264
|
+
to = parseMetaNumber(to);
|
|
32265
|
+
const body = { ...template };
|
|
32404
32266
|
return this.sendMessageMeta(body);
|
|
32405
32267
|
};
|
|
32406
|
-
|
|
32407
|
-
|
|
32408
|
-
* @param {*} number
|
|
32409
|
-
* @param {*} contact
|
|
32410
|
-
* @returns
|
|
32411
|
-
*/
|
|
32412
|
-
this.sendContacts = async (to, contact = []) => {
|
|
32413
|
-
const parseContacts = contact.map((contact) => ({
|
|
32414
|
-
name: {
|
|
32415
|
-
formatted_name: contact.name,
|
|
32416
|
-
first_name: contact.first_name,
|
|
32417
|
-
last_name: contact.last_name,
|
|
32418
|
-
middle_name: contact.middle_name,
|
|
32419
|
-
suffix: contact.suffix,
|
|
32420
|
-
prefix: contact.prefix,
|
|
32421
|
-
},
|
|
32422
|
-
birthday: contact.birthday,
|
|
32423
|
-
phones: contact.phones.map((phone) => ({
|
|
32424
|
-
phone: phone.phone,
|
|
32425
|
-
wa_id: phone.wa_id,
|
|
32426
|
-
type: phone.type,
|
|
32427
|
-
})),
|
|
32428
|
-
emails: contact.emails.map((email) => ({
|
|
32429
|
-
email: email.email,
|
|
32430
|
-
type: email.type,
|
|
32431
|
-
})),
|
|
32432
|
-
org: {
|
|
32433
|
-
company: contact.company,
|
|
32434
|
-
department: contact.department,
|
|
32435
|
-
title: contact.title,
|
|
32436
|
-
},
|
|
32437
|
-
urls: contact.urls.map((url) => ({
|
|
32438
|
-
url: url.url,
|
|
32439
|
-
type: url.type,
|
|
32440
|
-
})),
|
|
32441
|
-
addresses: contact.addresses.map((address) => ({
|
|
32442
|
-
street: address.street,
|
|
32443
|
-
city: address.city,
|
|
32444
|
-
state: address.state,
|
|
32445
|
-
zip: address.zip,
|
|
32446
|
-
country: address.country,
|
|
32447
|
-
country_code: address.counry_code,
|
|
32448
|
-
type: address.type,
|
|
32449
|
-
})),
|
|
32450
|
-
}));
|
|
32268
|
+
this.sendContacts = async (to, contacts = []) => {
|
|
32269
|
+
to = parseMetaNumber(to);
|
|
32451
32270
|
const body = {
|
|
32452
32271
|
messaging_product: 'whatsapp',
|
|
32453
|
-
recipient_type: 'individual',
|
|
32454
32272
|
to,
|
|
32455
32273
|
type: 'contacts',
|
|
32456
|
-
contacts
|
|
32274
|
+
contacts,
|
|
32457
32275
|
};
|
|
32458
32276
|
return this.sendMessageMeta(body);
|
|
32459
32277
|
};
|
|
32460
|
-
|
|
32461
|
-
|
|
32462
|
-
* @param {*} number
|
|
32463
|
-
* @param {*} bodyText
|
|
32464
|
-
* @param {*} itemCatalogId
|
|
32465
|
-
* @param {*} footerText
|
|
32466
|
-
* @returns
|
|
32467
|
-
*/
|
|
32468
|
-
this.sendCatalog = async (number, bodyText, itemCatalogId) => {
|
|
32278
|
+
this.sendCatalog = async (to, text, itemCatalogId) => {
|
|
32279
|
+
to = parseMetaNumber(to);
|
|
32469
32280
|
const body = {
|
|
32470
32281
|
messaging_product: 'whatsapp',
|
|
32471
32282
|
recipient_type: 'individual',
|
|
32472
|
-
to
|
|
32283
|
+
to,
|
|
32473
32284
|
type: 'interactive',
|
|
32474
32285
|
interactive: {
|
|
32475
32286
|
type: 'catalog_message',
|
|
32476
32287
|
body: {
|
|
32477
|
-
text
|
|
32288
|
+
text,
|
|
32478
32289
|
},
|
|
32479
32290
|
action: {
|
|
32480
32291
|
name: 'catalog_message',
|
|
@@ -32486,31 +32297,81 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32486
32297
|
};
|
|
32487
32298
|
return this.sendMessageMeta(body);
|
|
32488
32299
|
};
|
|
32489
|
-
|
|
32490
|
-
|
|
32491
|
-
* @param {*} userId
|
|
32492
|
-
* @param {*} message
|
|
32493
|
-
* @param {*} param2
|
|
32494
|
-
* @returns
|
|
32495
|
-
*/
|
|
32496
|
-
this.sendMessage = async (number, message, options) => {
|
|
32300
|
+
this.sendMessage = async (to, message, options) => {
|
|
32301
|
+
to = parseMetaNumber(to);
|
|
32497
32302
|
options = { ...options, ...options['options'] };
|
|
32498
32303
|
if (options?.buttons?.length)
|
|
32499
|
-
return this.sendButtons(
|
|
32304
|
+
return this.sendButtons(to, options.buttons, message);
|
|
32500
32305
|
if (options?.media)
|
|
32501
|
-
return this.sendMedia(
|
|
32502
|
-
this.sendText(
|
|
32306
|
+
return this.sendMedia(to, message, options.media);
|
|
32307
|
+
this.sendText(to, message);
|
|
32503
32308
|
};
|
|
32504
|
-
|
|
32505
|
-
|
|
32506
|
-
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32309
|
+
this.sendFile = async (to, mediaInput = null) => {
|
|
32310
|
+
to = parseMetaNumber(to);
|
|
32311
|
+
if (!mediaInput)
|
|
32312
|
+
throw new Error(`MEDIA_INPUT_NULL_: ${mediaInput}`);
|
|
32313
|
+
const formData = new FormData$1();
|
|
32314
|
+
const mimeType = mime$1.lookup(mediaInput);
|
|
32315
|
+
formData.append('file', require$$6$1.createReadStream(mediaInput), {
|
|
32316
|
+
contentType: mimeType,
|
|
32317
|
+
});
|
|
32318
|
+
formData.append('messaging_product', 'whatsapp');
|
|
32319
|
+
const nameOriginal = require$$1$3.basename(mediaInput) || 'Doc';
|
|
32320
|
+
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.globalVendorArgs.version}/${this.globalVendorArgs.numberId}/media`, formData, {
|
|
32321
|
+
headers: {
|
|
32322
|
+
Authorization: `Bearer ${this.globalVendorArgs.jwtToken}`,
|
|
32323
|
+
...formData.getHeaders(),
|
|
32324
|
+
},
|
|
32325
|
+
});
|
|
32326
|
+
const body = {
|
|
32327
|
+
messaging_product: 'whatsapp',
|
|
32328
|
+
to: to,
|
|
32329
|
+
type: 'document',
|
|
32330
|
+
document: {
|
|
32331
|
+
id: mediaId,
|
|
32332
|
+
filename: nameOriginal,
|
|
32333
|
+
},
|
|
32334
|
+
};
|
|
32335
|
+
return this.sendMessageMeta(body);
|
|
32336
|
+
};
|
|
32337
|
+
this.sendAudio = async (to, pathVideo = null) => {
|
|
32338
|
+
to = parseMetaNumber(to);
|
|
32339
|
+
if (!pathVideo)
|
|
32340
|
+
throw new Error(`MEDIA_INPUT_NULL_: ${pathVideo}`);
|
|
32341
|
+
const formData = new FormData$1();
|
|
32342
|
+
const mimeType = mime$1.lookup(pathVideo);
|
|
32343
|
+
if (['audio/ogg'].includes(mimeType)) {
|
|
32344
|
+
console.log([
|
|
32345
|
+
`Format (${mimeType}) not supported, you should use`,
|
|
32346
|
+
`https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types`,
|
|
32347
|
+
].join('\n'));
|
|
32348
|
+
}
|
|
32349
|
+
formData.append('file', require$$6$1.createReadStream(pathVideo), {
|
|
32350
|
+
contentType: mimeType,
|
|
32351
|
+
});
|
|
32352
|
+
formData.append('messaging_product', 'whatsapp');
|
|
32353
|
+
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.globalVendorArgs.version}/${this.globalVendorArgs.numberId}/media`, formData, {
|
|
32354
|
+
headers: {
|
|
32355
|
+
Authorization: `Bearer ${this.globalVendorArgs.jwtToken}`,
|
|
32356
|
+
...formData.getHeaders(),
|
|
32357
|
+
},
|
|
32358
|
+
});
|
|
32359
|
+
const body = {
|
|
32360
|
+
messaging_product: 'whatsapp',
|
|
32361
|
+
to,
|
|
32362
|
+
type: 'audio',
|
|
32363
|
+
audio: {
|
|
32364
|
+
id: mediaId,
|
|
32365
|
+
},
|
|
32366
|
+
};
|
|
32367
|
+
return this.sendMessageMeta(body);
|
|
32368
|
+
};
|
|
32369
|
+
this.sendReaction = async (to, react) => {
|
|
32370
|
+
to = parseMetaNumber(to);
|
|
32510
32371
|
const body = {
|
|
32511
32372
|
messaging_product: 'whatsapp',
|
|
32512
32373
|
recipient_type: 'individual',
|
|
32513
|
-
to
|
|
32374
|
+
to,
|
|
32514
32375
|
type: 'reaction',
|
|
32515
32376
|
reaction: {
|
|
32516
32377
|
message_id: react.message_id,
|
|
@@ -32519,15 +32380,8 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32519
32380
|
};
|
|
32520
32381
|
return this.sendMessageMeta(body);
|
|
32521
32382
|
};
|
|
32522
|
-
/**
|
|
32523
|
-
* Enviar Ubicación
|
|
32524
|
-
* @param {*} longitude
|
|
32525
|
-
* @param {*} latitude
|
|
32526
|
-
* @param {*} name
|
|
32527
|
-
* @param {*} address
|
|
32528
|
-
* @returns
|
|
32529
|
-
*/
|
|
32530
32383
|
this.sendLocation = async (to, localization) => {
|
|
32384
|
+
to = parseMetaNumber(to);
|
|
32531
32385
|
const { long_number, lat_number, name, address } = localization;
|
|
32532
32386
|
const body = {
|
|
32533
32387
|
messaging_product: 'whatsapp',
|
|
@@ -32542,89 +32396,46 @@ class MetaProvider extends bot.ProviderClass {
|
|
|
32542
32396
|
};
|
|
32543
32397
|
return this.sendMessageMeta(body);
|
|
32544
32398
|
};
|
|
32545
|
-
this.
|
|
32546
|
-
|
|
32547
|
-
const { buffer, extension } = await downloadFile(ctx?.url, this.jwtToken);
|
|
32548
|
-
const fileName = `file-${Date.now()}.${extension}`;
|
|
32549
|
-
const pathFile = require$$1$3.join(options?.path ?? os.tmpdir(), fileName);
|
|
32550
|
-
await promises.writeFile(pathFile, buffer);
|
|
32551
|
-
return pathFile;
|
|
32552
|
-
}
|
|
32553
|
-
catch (err) {
|
|
32554
|
-
console.log(`[Error]:`, err.message);
|
|
32555
|
-
return 'ERROR';
|
|
32556
|
-
}
|
|
32557
|
-
};
|
|
32558
|
-
this.sendFile = async (to, mediaInput = null) => {
|
|
32559
|
-
if (!mediaInput)
|
|
32560
|
-
throw new Error(`MEDIA_INPUT_NULL_: ${mediaInput}`);
|
|
32561
|
-
const formData = new FormData$1();
|
|
32562
|
-
const mimeType = mime$1.lookup(mediaInput);
|
|
32563
|
-
formData.append('file', require$$6$1.createReadStream(mediaInput), {
|
|
32564
|
-
contentType: mimeType,
|
|
32565
|
-
});
|
|
32566
|
-
formData.append('messaging_product', 'whatsapp');
|
|
32567
|
-
const nameOriginal = require$$1$3.basename(mediaInput) || 'Doc';
|
|
32568
|
-
const { data: { id: mediaId }, } = await axios.post(`${URL}/${this.version}/${this.numberId}/media`, formData, {
|
|
32569
|
-
headers: {
|
|
32570
|
-
Authorization: `Bearer ${this.jwtToken}`,
|
|
32571
|
-
...formData.getHeaders(),
|
|
32572
|
-
},
|
|
32573
|
-
});
|
|
32399
|
+
this.sendText = async (to, message) => {
|
|
32400
|
+
to = parseMetaNumber(to);
|
|
32574
32401
|
const body = {
|
|
32575
32402
|
messaging_product: 'whatsapp',
|
|
32576
|
-
|
|
32577
|
-
|
|
32578
|
-
|
|
32579
|
-
|
|
32580
|
-
|
|
32403
|
+
recipient_type: 'individual',
|
|
32404
|
+
to,
|
|
32405
|
+
type: 'text',
|
|
32406
|
+
text: {
|
|
32407
|
+
preview_url: false,
|
|
32408
|
+
body: message,
|
|
32581
32409
|
},
|
|
32582
32410
|
};
|
|
32583
32411
|
return this.sendMessageMeta(body);
|
|
32584
32412
|
};
|
|
32585
|
-
this.
|
|
32586
|
-
|
|
32587
|
-
|
|
32588
|
-
this.
|
|
32589
|
-
|
|
32413
|
+
this.sendMessageMeta = (body) => {
|
|
32414
|
+
return this.queue.add(() => this.sendMessageToApi(body));
|
|
32415
|
+
};
|
|
32416
|
+
this.sendMessageToApi = async (body) => {
|
|
32417
|
+
try {
|
|
32418
|
+
const fullUrl = `${URL}/${this.globalVendorArgs.version}/${this.globalVendorArgs.numberId}/messages`;
|
|
32419
|
+
const response = await axios.post(fullUrl, body, {
|
|
32420
|
+
headers: {
|
|
32421
|
+
Authorization: `Bearer ${this.globalVendorArgs.jwtToken}`,
|
|
32422
|
+
},
|
|
32423
|
+
});
|
|
32424
|
+
return response.data;
|
|
32425
|
+
}
|
|
32426
|
+
catch (error) {
|
|
32427
|
+
console.error(error.message);
|
|
32428
|
+
throw error;
|
|
32429
|
+
}
|
|
32430
|
+
};
|
|
32431
|
+
this.globalVendorArgs = { ...this.globalVendorArgs, ...args };
|
|
32432
|
+
this.http = new MetaWebHookServer(this.globalVendorArgs.jwtToken, this.globalVendorArgs.numberId, this.globalVendorArgs.version, this.globalVendorArgs.verifyToken, args.port);
|
|
32590
32433
|
this.queue = new Queue({
|
|
32591
32434
|
concurrent: 1,
|
|
32592
32435
|
interval: 100,
|
|
32593
32436
|
start: true,
|
|
32594
32437
|
});
|
|
32595
32438
|
}
|
|
32596
|
-
/**
|
|
32597
|
-
* Sends a message with metadata to the API.
|
|
32598
|
-
*
|
|
32599
|
-
* @param {Object} body - The body of the message.
|
|
32600
|
-
* @return {void} A Promise that resolves when the message is sent.
|
|
32601
|
-
*/
|
|
32602
|
-
sendMessageMeta(body) {
|
|
32603
|
-
return this.queue.add(() => this.sendMessageToApi(body));
|
|
32604
|
-
}
|
|
32605
|
-
/**
|
|
32606
|
-
* Sends a message to the API.
|
|
32607
|
-
*
|
|
32608
|
-
* @param {Object} body - The body of the message.
|
|
32609
|
-
* @return {Object} The response data from the API.
|
|
32610
|
-
*/
|
|
32611
|
-
async sendMessageToApi(body) {
|
|
32612
|
-
try {
|
|
32613
|
-
const response = await axios.post(`${URL}/${this.version}/${this.numberId}/messages`, body, {
|
|
32614
|
-
headers: {
|
|
32615
|
-
Authorization: `Bearer ${this.jwtToken}`,
|
|
32616
|
-
},
|
|
32617
|
-
});
|
|
32618
|
-
return response.data;
|
|
32619
|
-
}
|
|
32620
|
-
catch (error) {
|
|
32621
|
-
console.error(error.message);
|
|
32622
|
-
throw error;
|
|
32623
|
-
}
|
|
32624
|
-
}
|
|
32625
|
-
sendAudio(to, fileOpus, text) {
|
|
32626
|
-
console.log({ to, fileOpus, text });
|
|
32627
|
-
}
|
|
32628
32439
|
}
|
|
32629
32440
|
|
|
32630
32441
|
exports.MetaProvider = MetaProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { MetaProvider } from './
|
|
1
|
+
export { MetaProvider } from './meta';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/meta.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ProviderClass } from '@builderbot/bot';
|
|
2
|
+
import { Vendor } from '@builderbot/bot/dist/provider/providerClass';
|
|
3
|
+
import { BotContext, BotCtxMiddlewareOptions, Button, SendOptions } from '@builderbot/bot/dist/types';
|
|
4
|
+
import Queue from 'queue-promise';
|
|
5
|
+
|
|
6
|
+
import { MetaInterface } from './metaInterface';
|
|
7
|
+
import { MetaWebHookServer } from './server';
|
|
8
|
+
import { GlobalVendorArgs, Localization, Message, MetaList, MetaProviderOptions, ParsedContact, Reaction, SaveFileOptions, TextGenericParams, TextMessageBody } from './types';
|
|
9
|
+
declare class MetaProvider extends ProviderClass implements MetaInterface {
|
|
10
|
+
http: MetaWebHookServer | undefined;
|
|
11
|
+
queue: Queue;
|
|
12
|
+
vendor: Vendor<MetaInterface>;
|
|
13
|
+
globalVendorArgs: MetaProviderOptions & Partial<GlobalVendorArgs>;
|
|
14
|
+
constructor(args: MetaProviderOptions & Partial<GlobalVendorArgs>);
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param ctx
|
|
18
|
+
* @param options
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
saveFile: (ctx: Partial<Message & BotContext>, options?: SaveFileOptions) => Promise<string>;
|
|
22
|
+
busEvents: () => {
|
|
23
|
+
event: string;
|
|
24
|
+
func: (payload: any) => void;
|
|
25
|
+
}[];
|
|
26
|
+
private listenOnEvents;
|
|
27
|
+
initHttpServer: (port: number, opts: Pick<BotCtxMiddlewareOptions, 'blacklist'>) => void;
|
|
28
|
+
sendImage: (to: string, mediaInput?: any) => Promise<void>;
|
|
29
|
+
sendVideo: (to: string, pathVideo?: any) => Promise<void>;
|
|
30
|
+
sendMedia: (to: string, _: string, mediaInput: string) => Promise<void>;
|
|
31
|
+
sendList: (to: string, list: MetaList) => Promise<void>;
|
|
32
|
+
sendButtons: (to: string, buttons: Button[], text: string) => Promise<void>;
|
|
33
|
+
sendButtonUrl: (to: string, button: Button & {
|
|
34
|
+
url: string;
|
|
35
|
+
}, text: string) => Promise<any>;
|
|
36
|
+
sendTemplate: (to: string, template: TextGenericParams) => Promise<void>;
|
|
37
|
+
sendContacts: (to: string, contacts?: ParsedContact[]) => Promise<void>;
|
|
38
|
+
sendCatalog: (to: string, text: string, itemCatalogId: string) => Promise<void>;
|
|
39
|
+
sendMessage: (to: string, message: string, options?: SendOptions) => Promise<any>;
|
|
40
|
+
sendFile: (to: string, mediaInput?: any) => Promise<void>;
|
|
41
|
+
sendAudio: (to: string, pathVideo?: any) => Promise<void>;
|
|
42
|
+
sendReaction: (to: string, react: Reaction) => Promise<void>;
|
|
43
|
+
sendLocation: (to: string, localization: Localization) => Promise<void>;
|
|
44
|
+
sendText: (to: string, message: string) => Promise<void>;
|
|
45
|
+
sendMessageMeta: (body: TextMessageBody) => void;
|
|
46
|
+
sendMessageToApi: (body: TextMessageBody) => Promise<any>;
|
|
47
|
+
}
|
|
48
|
+
export { MetaProvider };
|
|
49
|
+
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,6CAA6C,CAAA;AACpE,OAAO,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MAAM,KAAG,QAAQ,GAAG,CAAC,CAsB/F;IAED,YAAY,OAAc,MAAM,YAAY,iBAAiB,mBAI5D;IAED,YAAY,OAAc,MAAM,aAAY,aAAa,EAAE,mBAU1D;IAED,WAAW,OAAc,MAAM,QAAQ,MAAM,iBAAiB,MAAM,mBAqBnE;IAED,WAAW,OAAc,MAAM,WAAW,MAAM,YAAY,WAAW,KAAG,QAAQ,GAAG,CAAC,CAMrF;IAED,QAAQ,OAAc,MAAM,qCAoC3B;IAED,SAAS,OAAc,MAAM,oCAyC5B;IAED,YAAY,OAAc,MAAM,SAAS,QAAQ,mBAahD;IAED,YAAY,OAAc,MAAM,gBAAgB,YAAY,mBAe3D;IAED,QAAQ,OAAc,MAAM,WAAW,MAAM,mBAa5C;IAED,eAAe,SAAU,eAAe,KAAG,IAAI,CAE9C;IAED,gBAAgB,SAAgB,eAAe,KAAG,QAAQ,GAAG,CAAC,CAa7D;CACJ;AACD,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SendOptions, BotContext, Button } from '@builderbot/bot/dist/types';
|
|
2
|
+
|
|
3
|
+
import { TextMessageBody, Reaction, Localization, Message, SaveFileOptions, MetaList, TextGenericParams } from './types';
|
|
4
|
+
export interface MetaInterface {
|
|
5
|
+
sendMessageMeta: (body: TextMessageBody) => void;
|
|
6
|
+
sendMessageToApi: (body: TextMessageBody) => Promise<any>;
|
|
7
|
+
sendText: (to: string, message: string) => Promise<any>;
|
|
8
|
+
sendImage: (to: string, mediaInput: string | null) => Promise<any>;
|
|
9
|
+
sendVideo: (to: string, pathVideo: string | null) => Promise<any>;
|
|
10
|
+
sendMedia: (to: string, text: string, mediaInput: string) => Promise<any>;
|
|
11
|
+
sendList: (to: string, list: MetaList) => Promise<any>;
|
|
12
|
+
sendButtons: (to: string, buttons: Button[], text: string) => Promise<any>;
|
|
13
|
+
sendButtonUrl: (to: string, button: Button & {
|
|
14
|
+
url: string;
|
|
15
|
+
}, text: string) => Promise<any>;
|
|
16
|
+
sendTemplate: (number: any, template: TextGenericParams) => Promise<any>;
|
|
17
|
+
sendContacts: (to: string, contact: any[]) => Promise<any>;
|
|
18
|
+
sendCatalog: (number: any, bodyText: any, itemCatalogId: any) => Promise<any>;
|
|
19
|
+
sendMessage: (number: string, message: string, options?: SendOptions) => Promise<any>;
|
|
20
|
+
sendReaction: (number: string, react: Reaction) => Promise<any>;
|
|
21
|
+
sendLocation: (to: string, localization: Localization) => Promise<any>;
|
|
22
|
+
saveFile: (ctx: Partial<Message & BotContext>, options?: SaveFileOptions) => Promise<string>;
|
|
23
|
+
sendFile: (to: string, mediaInput: string | null) => Promise<any>;
|
|
24
|
+
sendAudio: (to: string, fileOpus: string, text: string) => void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=metaInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metaInterface.d.ts","sourceRoot":"","sources":["../src/metaInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAE5E,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAExH,MAAM,WAAW,aAAa;IAC1B,eAAe,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA;IAChD,gBAAgB,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACzD,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACvD,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAClE,SAAS,EA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,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACtE,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC5F,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACjE,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAClE"}
|
package/dist/server.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BotCtxMiddleware } from '@builderbot/bot/dist/types';
|
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
4
|
import polka, { Polka } from 'polka';
|
|
5
5
|
|
|
6
|
-
import type { MetaProvider } from './
|
|
6
|
+
import type { MetaProvider } from './meta';
|
|
7
7
|
import { Message } from './types';
|
|
8
8
|
declare class MetaWebHookServer extends EventEmitter {
|
|
9
9
|
server: Polka;
|
|
@@ -14,6 +14,7 @@ declare class MetaWebHookServer extends EventEmitter {
|
|
|
14
14
|
private version;
|
|
15
15
|
private messageQueue;
|
|
16
16
|
constructor(jwtToken: string, numberId: string, version: string, token: string, metaPort?: number);
|
|
17
|
+
protected getListRoutes: (app: Polka) => string[];
|
|
17
18
|
/**
|
|
18
19
|
* Mensaje entrante
|
|
19
20
|
* emit: 'message'
|
|
@@ -34,8 +35,8 @@ declare class MetaWebHookServer extends EventEmitter {
|
|
|
34
35
|
* @param {*} req
|
|
35
36
|
* @param {*} res
|
|
36
37
|
*/
|
|
37
|
-
protected verifyToken:
|
|
38
|
-
protected emptyCtrl:
|
|
38
|
+
protected verifyToken: polka.Middleware;
|
|
39
|
+
protected emptyCtrl: polka.Middleware;
|
|
39
40
|
/**
|
|
40
41
|
* Contruir HTTP Server
|
|
41
42
|
*/
|
|
@@ -43,7 +44,9 @@ declare class MetaWebHookServer extends EventEmitter {
|
|
|
43
44
|
/**
|
|
44
45
|
* Iniciar el servidor HTTP
|
|
45
46
|
*/
|
|
46
|
-
start(vendor: BotCtxMiddleware, port?: number
|
|
47
|
+
start(vendor: BotCtxMiddleware, port?: number, args?: {
|
|
48
|
+
botName: string;
|
|
49
|
+
}, cb?: (arg?: any) => void): Promise<void>;
|
|
47
50
|
stop(): Promise<void>;
|
|
48
51
|
}
|
|
49
52
|
/**
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAGpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAKjC,cAAM,iBAAkB,SAAQ,YAAY;IACjC,MAAM,EAAE,KAAK,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;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
9
|
+
header: {
|
|
10
|
+
type: string;
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
body: {
|
|
14
|
+
text: string;
|
|
15
|
+
};
|
|
16
|
+
footer: {
|
|
17
|
+
text: string;
|
|
18
|
+
};
|
|
19
|
+
action: {
|
|
20
|
+
button: string;
|
|
21
|
+
sections: {
|
|
22
|
+
title: string;
|
|
23
|
+
rows: {
|
|
24
|
+
id: string;
|
|
25
|
+
title: string;
|
|
26
|
+
description: string;
|
|
27
|
+
}[];
|
|
28
|
+
}[];
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface GlobalVendorArgs {
|
|
32
|
+
name: string;
|
|
33
|
+
port: number;
|
|
34
|
+
}
|
|
8
35
|
export interface Order {
|
|
9
36
|
catalog_id: string;
|
|
10
37
|
product_items: string[];
|
|
@@ -34,6 +61,26 @@ export interface ParamasIncomingMessage {
|
|
|
34
61
|
version: string;
|
|
35
62
|
message: any;
|
|
36
63
|
}
|
|
64
|
+
export type TextGenericParams = {
|
|
65
|
+
messaging_product: 'whatsapp';
|
|
66
|
+
recipient_type: string;
|
|
67
|
+
to: string;
|
|
68
|
+
type: string;
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
};
|
|
71
|
+
export type ParsedContact = {
|
|
72
|
+
name: {
|
|
73
|
+
formatted_name: string;
|
|
74
|
+
first_name: string;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
};
|
|
77
|
+
phones: {
|
|
78
|
+
phone: string;
|
|
79
|
+
type: string;
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
}[];
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
};
|
|
37
84
|
export interface TextMessageBody {
|
|
38
85
|
messaging_product: string;
|
|
39
86
|
to: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC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AAE,MAAM,CAAA;IACrB,wBAAwB,EAAE,MAAM,CAAA;IAChC,oBAAoB,EAAE,MAAM,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE;QACR,KAAK,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,EAAE,EAAE,MAAM,CAAA;CACb"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { getMediaUrl } from './mediaUrl';
|
|
|
2
2
|
export { downloadFile, fileTypeFromFile } from './downloadFile';
|
|
3
3
|
export { processIncomingMessage } from './processaIncomingMsg';
|
|
4
4
|
export { getProfile } from './profile';
|
|
5
|
+
export { parseMetaNumber } from './number';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/utils/number.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,MAGhD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-meta",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23-alpha.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "vicente1992 <vic_ortiz20@hotmail.es>",
|
|
6
6
|
"homepage": "https://github.com/vicente1992/bot-whatsapp#readme",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"queue-promise": "^2.2.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@builderbot/bot": "^1.0.
|
|
41
|
+
"@builderbot/bot": "^1.0.23-alpha.0",
|
|
42
42
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
43
43
|
"@rollup/plugin-json": "^6.1.0",
|
|
44
44
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"tslib": "^2.6.2",
|
|
58
58
|
"tsm": "^2.3.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "eda828c77a06b4e0215deb54d3000469c0e2ecb4"
|
|
61
61
|
}
|
package/dist/metaProvider.d.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { ProviderClass } from '@builderbot/bot';
|
|
2
|
-
import { BotContext, BotCtxMiddlewareOptions, SendOptions } from '@builderbot/bot/dist/types';
|
|
3
|
-
import Queue from 'queue-promise';
|
|
4
|
-
|
|
5
|
-
import { MetaWebHookServer } from './server';
|
|
6
|
-
import { Localization, Message, MetaProviderOptions, Reaction, SaveFileOptions, TextMessageBody } from './types';
|
|
7
|
-
declare class MetaProvider extends ProviderClass {
|
|
8
|
-
http: MetaWebHookServer | undefined;
|
|
9
|
-
jwtToken: string | undefined;
|
|
10
|
-
verifyToken: string | undefined;
|
|
11
|
-
numberId: string | undefined;
|
|
12
|
-
version: string;
|
|
13
|
-
queue: Queue;
|
|
14
|
-
constructor({ jwtToken, numberId, verifyToken, version }: MetaProviderOptions);
|
|
15
|
-
private listenOnEvents;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param port
|
|
19
|
-
* @param opts
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
initHttpServer: (port: number, opts: Pick<BotCtxMiddlewareOptions, 'blacklist'>) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Mapeamos los eventos nativos a los que la clase Provider espera
|
|
25
|
-
* para tener un standar de eventos
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
busEvents: () => {
|
|
29
|
-
event: string;
|
|
30
|
-
func: (payload: any) => void;
|
|
31
|
-
}[];
|
|
32
|
-
/**
|
|
33
|
-
* Sends a message with metadata to the API.
|
|
34
|
-
*
|
|
35
|
-
* @param {Object} body - The body of the message.
|
|
36
|
-
* @return {void} A Promise that resolves when the message is sent.
|
|
37
|
-
*/
|
|
38
|
-
sendMessageMeta(body: TextMessageBody): void;
|
|
39
|
-
/**
|
|
40
|
-
* Sends a message to the API.
|
|
41
|
-
*
|
|
42
|
-
* @param {Object} body - The body of the message.
|
|
43
|
-
* @return {Object} The response data from the API.
|
|
44
|
-
*/
|
|
45
|
-
sendMessageToApi(body: TextMessageBody): Promise<any>;
|
|
46
|
-
sendText: (to: string, message: string) => Promise<void>;
|
|
47
|
-
sendImage: (to: string, mediaInput?: any) => Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {*} number
|
|
51
|
-
* @param {*} _
|
|
52
|
-
* @param {*} pathVideo
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
sendVideo: (to: string, pathVideo?: any) => Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* @alpha
|
|
58
|
-
* @param {string} number
|
|
59
|
-
* @param {string} message
|
|
60
|
-
* @example await sendMessage('+XXXXXXXXXXX', 'https://dominio.com/imagen.jpg' | 'img/imagen.jpg')
|
|
61
|
-
*/
|
|
62
|
-
sendMedia: (to: string, text: string, mediaInput: string) => Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Enviar listas
|
|
65
|
-
* @param {*} number
|
|
66
|
-
* @param {*} text
|
|
67
|
-
* @param {*} buttons
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
sendLists: (to: string, list: any) => Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Enviar listas alternativo
|
|
73
|
-
* @param {*} number
|
|
74
|
-
* @param {*} header
|
|
75
|
-
* @param {*} text
|
|
76
|
-
* @param {*} footer
|
|
77
|
-
* @param {*} button
|
|
78
|
-
* @param {*} list
|
|
79
|
-
* @returns
|
|
80
|
-
*/
|
|
81
|
-
sendList: (to: string, header: string, text: string, footer: string, button: string, list?: any[]) => Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* Enviar buttons
|
|
84
|
-
* @param {*} number
|
|
85
|
-
* @param {*} text
|
|
86
|
-
* @param {*} buttons
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
sendButtons: (to: string, text: string, buttons?: any[]) => Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Enviar buttons only text
|
|
92
|
-
* @param {*} number
|
|
93
|
-
* @param {*} text
|
|
94
|
-
* @param {*} buttons
|
|
95
|
-
* @returns
|
|
96
|
-
*/
|
|
97
|
-
sendButtonsText: (to: string, text: string, buttons?: any[]) => Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Enviar buttons with image
|
|
100
|
-
* @param {*} number
|
|
101
|
-
* @param {*} text
|
|
102
|
-
* @param {*} buttons
|
|
103
|
-
* @param {*} url
|
|
104
|
-
* @returns
|
|
105
|
-
*/
|
|
106
|
-
sendButtonsMedia: (to: string, text: string, buttons: any[], url: string) => Promise<void>;
|
|
107
|
-
/**
|
|
108
|
-
* Enviar plantillas
|
|
109
|
-
* @param {*} number
|
|
110
|
-
* @param {*} template
|
|
111
|
-
* @param {*} languageCode
|
|
112
|
-
* Usarse de acuerdo a cada plantilla en particular, esto solo es un mapeo de como funciona.
|
|
113
|
-
* @returns
|
|
114
|
-
*/
|
|
115
|
-
sendTemplate: (number: any, template: any, languageCode: any) => Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Enviar Contactos
|
|
118
|
-
* @param {*} number
|
|
119
|
-
* @param {*} contact
|
|
120
|
-
* @returns
|
|
121
|
-
*/
|
|
122
|
-
sendContacts: (to: string, contact?: any[]) => Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Enviar catálogo
|
|
125
|
-
* @param {*} number
|
|
126
|
-
* @param {*} bodyText
|
|
127
|
-
* @param {*} itemCatalogId
|
|
128
|
-
* @param {*} footerText
|
|
129
|
-
* @returns
|
|
130
|
-
*/
|
|
131
|
-
sendCatalog: (number: any, bodyText: any, itemCatalogId: any) => Promise<void>;
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
* @param {*} userId
|
|
135
|
-
* @param {*} message
|
|
136
|
-
* @param {*} param2
|
|
137
|
-
* @returns
|
|
138
|
-
*/
|
|
139
|
-
sendMessage: (number: string, message: string, options?: SendOptions) => Promise<any>;
|
|
140
|
-
/**
|
|
141
|
-
* Enviar reacción a un mensaje
|
|
142
|
-
* @param {*} number
|
|
143
|
-
* @param {*} react
|
|
144
|
-
*/
|
|
145
|
-
sendReaction: (number: string, react: Reaction) => Promise<void>;
|
|
146
|
-
/**
|
|
147
|
-
* Enviar Ubicación
|
|
148
|
-
* @param {*} longitude
|
|
149
|
-
* @param {*} latitude
|
|
150
|
-
* @param {*} name
|
|
151
|
-
* @param {*} address
|
|
152
|
-
* @returns
|
|
153
|
-
*/
|
|
154
|
-
sendLocation: (to: string, localization: Localization) => Promise<void>;
|
|
155
|
-
saveFile: (ctx: Partial<Message & BotContext>, options?: SaveFileOptions) => Promise<string>;
|
|
156
|
-
sendFile: (to: string, mediaInput?: any) => Promise<void>;
|
|
157
|
-
sendAudio(to: string, fileOpus: string, text: string): void;
|
|
158
|
-
}
|
|
159
|
-
export { MetaProvider };
|
|
160
|
-
//# sourceMappingURL=metaProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metaProvider.d.ts","sourceRoot":"","sources":["../src/metaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAoB,uBAAuB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAQ/G,OAAO,KAAK,MAAM,eAAe,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKhH,cAAM,YAAa,SAAQ,aAAa;IACpC,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAAA;IACnC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,OAAO,EAAE,MAAM,CAAU;IACzB,KAAK,EAAE,KAAK,CAAA;gBAEA,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,mBAAmB;IAc7E,OAAO,CAAC,cAAc,CAKrB;IAED;;;;;OAKG;IACH,cAAc,SAAU,MAAM,QAAQ,KAAK,uBAAuB,EAAE,WAAW,CAAC,UAkB/E;IAED;;;;OAIG;IACH,SAAS;;wBAWe,GAAG;QAU1B;IAED;;;;;OAKG;IACH,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAI5C;;;;;OAKG;IACG,gBAAgB,CAAC,IAAI,EAAE,eAAe,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