@builderbot/provider-web-whatsapp 0.1.3-alpha.22

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.
@@ -0,0 +1,135 @@
1
+ import { ProviderClass } from '@builderbot/bot';
2
+ import { BotCtxMiddlewareOptions, SendOptions } from '@builderbot/bot/dist/types';
3
+ import WAWebJS, { Client } from 'whatsapp-web.js';
4
+
5
+ import { WebWhatsappHttpServer } from './server';
6
+ /**
7
+ * ⚙️ WebWhatsappProvider: Es una clase tipo adaptor
8
+ * que extiende clases de ProviderClass (la cual es como interfaz para sber que funciones rqueridas)
9
+ * https://github.com/pedroslopez/whatsapp-web.js
10
+ */
11
+ declare class WebWhatsappProvider extends ProviderClass {
12
+ globalVendorArgs: {
13
+ name: string;
14
+ gifPlayback: boolean;
15
+ port: number;
16
+ };
17
+ vendor: Client;
18
+ http: WebWhatsappHttpServer | undefined;
19
+ constructor(args: {
20
+ name: string;
21
+ gifPlayback: boolean;
22
+ });
23
+ /**
24
+ *
25
+ * @param port
26
+ * @param opts
27
+ * @returns
28
+ */
29
+ initHttpServer: (port: number, opts: Pick<BotCtxMiddlewareOptions, 'blacklist'>) => void;
30
+ /**
31
+ * Mapeamos los eventos nativos de whatsapp-web.js a los que la clase Provider espera
32
+ * para tener un standar de eventos
33
+ * @returns
34
+ */
35
+ busEvents: () => ({
36
+ event: string;
37
+ func: (qr: string) => Promise<void>;
38
+ } | {
39
+ event: string;
40
+ func: (payload: WAWebJS.Message & {
41
+ _data: {
42
+ lng?: string;
43
+ lat?: string;
44
+ type?: string;
45
+ };
46
+ name: string;
47
+ }) => void;
48
+ })[];
49
+ /**
50
+ * Enviar botones
51
+ * https://docs.wwebjs.dev/Buttons.html
52
+ * @private
53
+ * @param {*} number
54
+ * @param {*} message
55
+ * @param {*} buttons []
56
+ * @returns
57
+ */
58
+ sendButtons: (number: string, message: any, buttons?: any) => Promise<WAWebJS.Message>;
59
+ /**
60
+ * Enviar lista
61
+ * https://docs.wwebjs.dev/List.html
62
+ * @private
63
+ * @alpha No funciona en whatsapp bussines
64
+ * @param {*} number
65
+ * @param {*} message
66
+ * @param {*} buttons []
67
+ * @returns
68
+ */
69
+ /**
70
+ * Enviar un mensaje solo texto
71
+ * https://docs.wwebjs.dev/Message.html
72
+ * @private
73
+ * @param {*} number
74
+ * @param {*} message
75
+ * @returns
76
+ */
77
+ sendText: (number: string, message: WAWebJS.MessageContent) => Promise<WAWebJS.Message>;
78
+ /**
79
+ * Enviar imagen
80
+ * @param {*} number
81
+ * @param {*} imageUrl
82
+ * @param {*} text
83
+ * @returns
84
+ */
85
+ sendImage: (number: string, filePath: string, caption: string) => Promise<WAWebJS.Message>;
86
+ /**
87
+ * Enviar audio
88
+ * @param {*} number
89
+ * @param {*} imageUrl
90
+ * @param {*} text
91
+ * @returns
92
+ */
93
+ sendAudio: (number: string, filePath: string, caption: string) => Promise<WAWebJS.Message>;
94
+ /**
95
+ * Enviar video
96
+ * @param {*} number
97
+ * @param {*} imageUrl
98
+ * @param {*} text
99
+ * @returns
100
+ */
101
+ sendVideo: (number: string, filePath: string) => Promise<WAWebJS.Message>;
102
+ /**
103
+ * Enviar Arhivos/pdf
104
+ * @param {*} number
105
+ * @param {*} imageUrl
106
+ * @param {*} text
107
+ * @returns
108
+ */
109
+ sendFile: (number: string, filePath: string) => Promise<WAWebJS.Message>;
110
+ /**
111
+ * Enviar imagen o multimedia
112
+ * @param {*} number
113
+ * @param {*} mediaInput
114
+ * @param {*} message
115
+ * @returns
116
+ */
117
+ sendMedia: (number: string, mediaUrl: string, text: string) => Promise<WAWebJS.Message>;
118
+ /**
119
+ * Funcion SendRaw envia opciones directamente del proveedor
120
+ * @param {string} number
121
+ * @param {string} message
122
+ * @example await sendMessage('+XXXXXXXXXXX', 'Hello World')
123
+ */
124
+ sendRaw: () => (chatId: string, content: WAWebJS.MessageContent, options?: WAWebJS.MessageSendOptions) => Promise<WAWebJS.Message>;
125
+ /**
126
+ *
127
+ * @param {*} userId
128
+ * @param {*} message
129
+ * @param {*} param2
130
+ * @returns
131
+ */
132
+ sendMessage: (number: string, message: string, options?: SendOptions) => Promise<any>;
133
+ }
134
+ export { WebWhatsappProvider };
135
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAoB,uBAAuB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAInG,OAAO,OAAO,EAAE,EAAE,MAAM,EAAoC,MAAM,iBAAiB,CAAA;AAEnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAOhD;;;;GAIG;AACH,cAAM,mBAAoB,SAAQ,aAAa;IAC3C,gBAAgB;;;;MAAkD;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,qBAAqB,GAAG,SAAS,CAAA;gBAC3B,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE;IAkCxD;;;;;OAKG;IACH,cAAc,SAAU,MAAM,QAAQ,KAAK,uBAAuB,EAAE,WAAW,CAAC,UAe/E;IAED;;;;OAIG;IACH,SAAS;;mBAOgB,MAAM;;;wBAsBV,QAAQ,OAAO,GAAG;YAAE,KAAK,EAAE;gBAAE,GAAG,CAAC,EAAE,MAAM,CAAC;gBAAC,GAAG,CAAC,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAA;aAAE,CAAC;YAAC,MAAM,MAAM,CAAA;SAAE;SA+B5G;IAED;;;;;;;;OAQG;IACH,WAAW,WAAkB,MAAM,WAAW,GAAG,YAAW,GAAG,8BAU9D;IAED;;;;;;;;;OASG;IAeH;;;;;;;OAOG;IACH,QAAQ,WAAkB,MAAM,WAAW,QAAQ,cAAc,8BAEhE;IAED;;;;;;OAMG;IACH,SAAS,WAAkB,MAAM,YAAY,MAAM,WAAW,MAAM,8BAKnE;IAED;;;;;;OAMG;IAEH,SAAS,WAAkB,MAAM,YAAY,MAAM,WAAW,MAAM,8BAKnE;IAED;;;;;;OAMG;IACH,SAAS,WAAkB,MAAM,YAAY,MAAM,8BAOlD;IAED;;;;;;OAMG;IACH,QAAQ,WAAkB,MAAM,YAAY,MAAM,8BAKjD;IAED;;;;;;OAMG;IACH,SAAS,WAAkB,MAAM,YAAY,MAAM,QAAQ,MAAM,8BAYhE;IAED;;;;;OAKG;IAEH,OAAO,4HAAgC;IACvC;;;;;;OAMG;IACH,WAAW,WAAkB,MAAM,WAAW,MAAM,YAAY,WAAW,KAAG,QAAQ,GAAG,CAAC,CAMzF;CACJ;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'node:events';
3
+ import polka, { Polka } from 'polka';
4
+
5
+ import { WebWhatsappProvider } from '.';
6
+ import { BotCtxMiddleware } from './types';
7
+ export declare class WebWhatsappHttpServer extends EventEmitter {
8
+ #private;
9
+ server: Polka;
10
+ port: number;
11
+ constructor(botName: string, _port: number);
12
+ /**
13
+ * Contruir HTTP Server
14
+ */
15
+ protected buildHTTPServer(): Polka;
16
+ /**
17
+ * Iniciar el servidor HTTP
18
+ */
19
+ start(vendor: BotCtxMiddleware, port?: number, args?: {
20
+ botName: string;
21
+ }): void;
22
+ /**
23
+ *
24
+ * @param _
25
+ * @param res
26
+ */
27
+ protected indexHome: polka.Middleware;
28
+ stop(): Promise<void>;
29
+ }
30
+ /**
31
+ *
32
+ * @param inHandleCtx
33
+ * @returns
34
+ */
35
+ export declare const inHandleCtx: <T extends Pick<WebWhatsappProvider, "sendMessage" | "vendor"> & {
36
+ provider: WebWhatsappProvider;
37
+ }>(ctxPolka: (bot: T, req: any, res: any) => Promise<void>) => (req: any, res: any) => any;
38
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,aAAa,CAAA;AAGtC,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,GAAG,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK1C,qBAAa,qBAAsB,SAAQ,YAAY;;IAC5C,MAAM,EAAE,KAAK,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;gBAGP,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAO1C;;OAEG;IACH,SAAS,CAAC,eAAe,IAAI,KAAK;IAOlC;;OAEG;IAEH,KAAK,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAczE;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,CAMpC;IAED,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAWxB;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW;cACyD,mBAAmB;2BACxD,GAAG,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,WAEjE,GAAG,OAAO,GAAG,QAoBlB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { ProviderClass } from '@builderbot/bot';
2
+ export type BotCtxMiddleware = Partial<ProviderClass & {
3
+ provider: any;
4
+ }>;
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,aAAa,GAAG;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ declare const wwebCleanNumber: (number: string, full?: boolean) => string;
2
+ declare const wwebGenerateImage: (base64: string, name?: string) => Promise<void>;
3
+ declare const wwebIsValidNumber: (rawNumber: string) => boolean;
4
+ declare const wwebDownloadMedia: (url: string) => Promise<string>;
5
+ export { wwebCleanNumber, wwebGenerateImage, wwebIsValidNumber, wwebDownloadMedia };
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,eAAe,WAAY,MAAM,SAAQ,OAAO,KAAW,MAIhE,CAAA;AAED,QAAA,MAAM,iBAAiB,WAAkB,MAAM,SAAQ,MAAM,KAAc,QAAQ,IAAI,CAatF,CAAA;AAED,QAAA,MAAM,iBAAiB,cAAe,MAAM,KAAG,OAI9C,CAAA;AAED,QAAA,MAAM,iBAAiB,QAAe,MAAM,KAAG,QAAQ,MAAM,CAsB5D,CAAA;AAED,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAA"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@builderbot/provider-web-whatsapp",
3
+ "version": "0.1.3-alpha.22",
4
+ "description": "Now I’m the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin’ letters to relatives / Embellishin’ my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
5
+ "keywords": [],
6
+ "author": "Leifer Mendez <leifer33@gmail.com>",
7
+ "license": "ISC",
8
+ "main": "dist/index.cjs",
9
+ "types": "dist/index.d.ts",
10
+ "type": "module",
11
+ "scripts": {
12
+ "build": "rimraf dist && rollup --config",
13
+ "test": "npx uvu -r tsm ./__tests__",
14
+ "test:coverage": "npx c8 npm run test"
15
+ },
16
+ "directories": {
17
+ "lib": "dist",
18
+ "test": "__tests__"
19
+ },
20
+ "files": [
21
+ "./dist/"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/codigoencasa/bot-whatsapp.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/codigoencasa/bot-whatsapp/issues"
29
+ },
30
+ "homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
31
+ "devDependencies": {
32
+ "@builderbot/bot": "^0.1.3-alpha.22",
33
+ "@rollup/plugin-commonjs": "^25.0.7",
34
+ "@rollup/plugin-json": "^6.1.0",
35
+ "@rollup/plugin-node-resolve": "^15.2.3",
36
+ "@types/body-parser": "^1.19.5",
37
+ "@types/mime-types": "^2.1.4",
38
+ "@types/node": "^20.11.0",
39
+ "@types/polka": "^0.5.7",
40
+ "@types/qr-image": "^3.2.9",
41
+ "@types/sinon": "^17.0.3",
42
+ "mime-types": "^2.1.35",
43
+ "pino": "^7.11.0",
44
+ "qr-image": "^3.2.0",
45
+ "rimraf": "^5.0.5",
46
+ "rollup-plugin-typescript2": "^0.36.0",
47
+ "sinon": "^17.0.1"
48
+ },
49
+ "dependencies": {
50
+ "body-parser": "^1.20.2",
51
+ "polka": "^0.5.2",
52
+ "whatsapp-web.js": "^1.23.0"
53
+ },
54
+ "gitHead": "e52a9fe13d30d65b650a54b6e116953c949b1158"
55
+ }