botcast-sdk 1.0.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/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/client.cjs +91 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +87 -0
- package/dist/errors.cjs +59 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/modules/base.cjs +113 -0
- package/dist/modules/base.d.ts +22 -0
- package/dist/modules/base.d.ts.map +1 -0
- package/dist/modules/base.js +109 -0
- package/dist/modules/broadcast.cjs +30 -0
- package/dist/modules/broadcast.d.ts +27 -0
- package/dist/modules/broadcast.d.ts.map +1 -0
- package/dist/modules/broadcast.js +26 -0
- package/dist/modules/chats.cjs +113 -0
- package/dist/modules/chats.d.ts +106 -0
- package/dist/modules/chats.d.ts.map +1 -0
- package/dist/modules/chats.js +109 -0
- package/dist/modules/groups.cjs +200 -0
- package/dist/modules/groups.d.ts +139 -0
- package/dist/modules/groups.d.ts.map +1 -0
- package/dist/modules/groups.js +196 -0
- package/dist/modules/instances.cjs +138 -0
- package/dist/modules/instances.d.ts +91 -0
- package/dist/modules/instances.d.ts.map +1 -0
- package/dist/modules/instances.js +134 -0
- package/dist/modules/messages.cjs +217 -0
- package/dist/modules/messages.d.ts +155 -0
- package/dist/modules/messages.d.ts.map +1 -0
- package/dist/modules/messages.js +213 -0
- package/dist/modules/profile.cjs +129 -0
- package/dist/modules/profile.d.ts +92 -0
- package/dist/modules/profile.d.ts.map +1 -0
- package/dist/modules/profile.js +125 -0
- package/dist/types/chats.cjs +2 -0
- package/dist/types/chats.d.ts +62 -0
- package/dist/types/chats.d.ts.map +1 -0
- package/dist/types/chats.js +1 -0
- package/dist/types/groups.cjs +2 -0
- package/dist/types/groups.d.ts +47 -0
- package/dist/types/groups.d.ts.map +1 -0
- package/dist/types/groups.js +1 -0
- package/dist/types/index.cjs +22 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/instances.cjs +2 -0
- package/dist/types/instances.d.ts +65 -0
- package/dist/types/instances.d.ts.map +1 -0
- package/dist/types/instances.js +1 -0
- package/dist/types/messages.cjs +2 -0
- package/dist/types/messages.d.ts +86 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +1 -0
- package/dist/types/profile.cjs +2 -0
- package/dist/types/profile.d.ts +25 -0
- package/dist/types/profile.d.ts.map +1 -0
- package/dist/types/profile.js +1 -0
- package/dist/types/webhooks.cjs +2 -0
- package/dist/types/webhooks.d.ts +17 -0
- package/dist/types/webhooks.d.ts.map +1 -0
- package/dist/types/webhooks.js +1 -0
- package/dist/webhooks/index.cjs +71 -0
- package/dist/webhooks/index.d.ts +26 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +67 -0
- package/package.json +61 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WebhookEvent, WebhookMessageReceivedEvent, WebhookHandler } from '../types/index.js';
|
|
2
|
+
export declare class BotcastWebhook {
|
|
3
|
+
private handlers;
|
|
4
|
+
/**
|
|
5
|
+
* Registers a callback for incoming messages.
|
|
6
|
+
*/
|
|
7
|
+
onMessage(handler: WebhookHandler<WebhookMessageReceivedEvent>): this;
|
|
8
|
+
/**
|
|
9
|
+
* Registers a callback for any event type.
|
|
10
|
+
*/
|
|
11
|
+
on<T = WebhookEvent>(event: string, handler: WebhookHandler<T>): this;
|
|
12
|
+
/**
|
|
13
|
+
* Dispatches and processes a raw webhook event body.
|
|
14
|
+
*/
|
|
15
|
+
handleEvent(event: WebhookEvent): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Express / Connect compatible middleware:
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* app.post('/webhook', botcast.webhook.middleware());
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
middleware(): (req: any, res: any, next?: any) => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/webhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9F,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAoD;IAEpE;;OAEG;IACI,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC,2BAA2B,CAAC,GAAG,IAAI,CAE3E;IAED;;OAEG;IACI,EAAE,CAAC,CAAC,GAAG,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAM3E;IAED;;OAEG;IACU,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB3D;IAED;;;;;;;OAOG;IACI,UAAU,UACI,GAAG,OAAO,GAAG,SAAS,GAAG,mBAe7C;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export class BotcastWebhook {
|
|
2
|
+
handlers = new Map();
|
|
3
|
+
/**
|
|
4
|
+
* Registers a callback for incoming messages.
|
|
5
|
+
*/
|
|
6
|
+
onMessage(handler) {
|
|
7
|
+
return this.on('message_received', handler);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Registers a callback for any event type.
|
|
11
|
+
*/
|
|
12
|
+
on(event, handler) {
|
|
13
|
+
if (!this.handlers.has(event)) {
|
|
14
|
+
this.handlers.set(event, new Set());
|
|
15
|
+
}
|
|
16
|
+
this.handlers.get(event).add(handler);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Dispatches and processes a raw webhook event body.
|
|
21
|
+
*/
|
|
22
|
+
async handleEvent(event) {
|
|
23
|
+
if (!event || !event.event)
|
|
24
|
+
return;
|
|
25
|
+
// Trigger specific event handlers
|
|
26
|
+
const specificHandlers = this.handlers.get(event.event);
|
|
27
|
+
if (specificHandlers) {
|
|
28
|
+
for (const handler of specificHandlers) {
|
|
29
|
+
await handler(event);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Trigger wildcard '*' handlers
|
|
33
|
+
const wildcardHandlers = this.handlers.get('*');
|
|
34
|
+
if (wildcardHandlers) {
|
|
35
|
+
for (const handler of wildcardHandlers) {
|
|
36
|
+
await handler(event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Express / Connect compatible middleware:
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* app.post('/webhook', botcast.webhook.middleware());
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
middleware() {
|
|
49
|
+
return async (req, res, next) => {
|
|
50
|
+
try {
|
|
51
|
+
const body = req.body;
|
|
52
|
+
if (body && body.event) {
|
|
53
|
+
await this.handleEvent(body);
|
|
54
|
+
}
|
|
55
|
+
res.status(200).json({ received: true });
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (typeof next === 'function') {
|
|
59
|
+
next(err);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
res.status(500).json({ error: 'Webhook processing failed', message: err.message });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "botcast-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official TypeScript/JavaScript SDK for Botcast WhatsApp Multi-Instance API Gateway",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./webhooks": {
|
|
16
|
+
"types": "./dist/webhooks/index.d.ts",
|
|
17
|
+
"import": "./dist/webhooks/index.js",
|
|
18
|
+
"require": "./dist/webhooks/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "node build.mjs",
|
|
28
|
+
"test": "node --test test/client.test.js",
|
|
29
|
+
"prepublishOnly": "npm run build && npm test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"botcast",
|
|
33
|
+
"whatsapp",
|
|
34
|
+
"whatsapp-api",
|
|
35
|
+
"whatsapp-gateway",
|
|
36
|
+
"baileys",
|
|
37
|
+
"multi-instance",
|
|
38
|
+
"whatsapp-bot",
|
|
39
|
+
"otp",
|
|
40
|
+
"messaging",
|
|
41
|
+
"sms-alternative",
|
|
42
|
+
"webhooks"
|
|
43
|
+
],
|
|
44
|
+
"author": "Botcast <support@botcast.site>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"homepage": "https://botcast.site",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/ANOOBALSA/Botcast.git",
|
|
50
|
+
"directory": "packages/botcast-sdk"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://botcast.site/support"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"typescript": "^5.8.2"
|
|
60
|
+
}
|
|
61
|
+
}
|