wppapi-sdk 0.2.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 +103 -0
- package/index.d.ts +60 -0
- package/index.js +138 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IPRoute Tecnologia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# WPPAPI — SDK JavaScript
|
|
2
|
+
|
|
3
|
+
SDK oficial da [WPPAPI](https://wpp-api.com?utm_source=github&utm_medium=sdk) — API WhatsApp multi-tenant, gerenciada e dev-friendly. Envie e receba mensagens de WhatsApp via REST, com webhooks assinados (HMAC), integração nativa com Chatwoot e painel self-service.
|
|
4
|
+
|
|
5
|
+
- **Zero dependências** — usa `fetch` nativo (browser e Node 18+)
|
|
6
|
+
- **Trial de 3 dias grátis, sem cartão** → [criar conta](https://app.wpp-api.com/signup?utm_source=github&utm_medium=sdk)
|
|
7
|
+
- Base da API: `https://api.wpp-api.com`
|
|
8
|
+
|
|
9
|
+
## Instalação
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install github:iproute-tecnologia/wppapi-sdk-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Ou copie o `index.js` — é um arquivo único, sem dependências.
|
|
16
|
+
|
|
17
|
+
## Uso
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { WppApiClient } from "wppapi-sdk";
|
|
21
|
+
|
|
22
|
+
const client = new WppApiClient({
|
|
23
|
+
baseUrl: "https://api.wpp-api.com",
|
|
24
|
+
instanceId: "sua-instancia",
|
|
25
|
+
token: "seu-token",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Texto
|
|
29
|
+
await client.sendText("5511999999999", "Olá! 👋");
|
|
30
|
+
|
|
31
|
+
// Imagem por URL, com legenda
|
|
32
|
+
await client.sendImage("5511999999999", "https://exemplo.com/foto.jpg", "Olha isso");
|
|
33
|
+
|
|
34
|
+
// Documento em base64
|
|
35
|
+
await client.sendFile("5511999999999", {
|
|
36
|
+
data: "<base64 sem prefixo data:>",
|
|
37
|
+
mimetype: "application/pdf",
|
|
38
|
+
filename: "proposta.pdf",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Validar número antes de enviar
|
|
42
|
+
const { exists } = await client.checkNumber("5511999999999");
|
|
43
|
+
|
|
44
|
+
// Sessão
|
|
45
|
+
await client.status(); // conectada? pareando?
|
|
46
|
+
await client.qrCode(); // QR para parear
|
|
47
|
+
await client.me(); // perfil conectado
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Token no header (em vez da URL)
|
|
51
|
+
|
|
52
|
+
Para ambientes onde URLs vão para logs, envie o token via header `Client-Token`:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
const client = new WppApiClient({
|
|
56
|
+
baseUrl: "https://api.wpp-api.com",
|
|
57
|
+
instanceId: "sua-instancia",
|
|
58
|
+
token: "seu-token",
|
|
59
|
+
clientTokenHeader: true,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Métodos
|
|
64
|
+
|
|
65
|
+
| Método | Endpoint |
|
|
66
|
+
|--------|----------|
|
|
67
|
+
| `status()` | `GET /status` |
|
|
68
|
+
| `qrCode()` | `GET /qr-code` |
|
|
69
|
+
| `me()` | `GET /me` |
|
|
70
|
+
| `sendText(phone, message)` | `POST /send-text` |
|
|
71
|
+
| `sendImage(phone, image, caption?)` | `POST /send-image` |
|
|
72
|
+
| `sendFile(phone, file, caption?)` | `POST /send-file` |
|
|
73
|
+
| `sendVoice(phone, audio)` | `POST /send-voice` |
|
|
74
|
+
| `sendVideo(phone, video, caption?)` | `POST /send-video` |
|
|
75
|
+
| `checkNumber(phone)` | `GET /check-number` |
|
|
76
|
+
| `chats(limit?)` | `GET /chats` |
|
|
77
|
+
| `groups()` | `GET /groups` |
|
|
78
|
+
|
|
79
|
+
A API completa (location, contact, reply, reaction, typing, seen, sticker, poll, list, status/stories, edit, pin) está documentada em [wpp-api.com/docs](https://wpp-api.com/docs?utm_source=github&utm_medium=sdk) e no Swagger do painel.
|
|
80
|
+
|
|
81
|
+
## Recebendo mensagens (webhooks)
|
|
82
|
+
|
|
83
|
+
Cadastre uma URL de webhook no painel e receba eventos assinados com HMAC-SHA256 (`X-WPPAPI-Signature`). Exemplo completo de receptor em Node.js com validação de assinatura: [guia de webhooks](https://wpp-api.com/guias/webhooks-whatsapp-nodejs?utm_source=github&utm_medium=sdk).
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
// Payload de mensagem recebida
|
|
87
|
+
{
|
|
88
|
+
"event": "received",
|
|
89
|
+
"instanceId": "sua-instancia",
|
|
90
|
+
"timestamp": "2026-07-23T15:00:00.000Z",
|
|
91
|
+
"data": { "from": "5511999999999", "body": "oi", "type": "chat", "fromMe": false }
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Guias
|
|
96
|
+
|
|
97
|
+
- [WhatsApp no n8n](https://wpp-api.com/guias/whatsapp-n8n?utm_source=github&utm_medium=sdk)
|
|
98
|
+
- [Chatwoot + WhatsApp (integração nativa)](https://wpp-api.com/guias/whatsapp-chatwoot?utm_source=github&utm_medium=sdk)
|
|
99
|
+
- [Webhooks com HMAC em Node.js](https://wpp-api.com/guias/webhooks-whatsapp-nodejs?utm_source=github&utm_medium=sdk)
|
|
100
|
+
|
|
101
|
+
## Licença
|
|
102
|
+
|
|
103
|
+
[MIT](./LICENSE) © IPRoute Tecnologia
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface WppApiClientOptions {
|
|
2
|
+
/** Base da API, ex.: https://api.wpp-api.com */
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** ID público da instância */
|
|
5
|
+
instanceId: string;
|
|
6
|
+
/** Token da instância */
|
|
7
|
+
token: string;
|
|
8
|
+
/** Envia o token no header `Client-Token` em vez da URL */
|
|
9
|
+
clientTokenHeader?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MediaFile {
|
|
13
|
+
/** URL pública do arquivo */
|
|
14
|
+
url?: string;
|
|
15
|
+
/** Conteúdo em base64 (sem prefixo data:) */
|
|
16
|
+
data?: string;
|
|
17
|
+
mimetype?: string;
|
|
18
|
+
filename?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type MediaInput = string | MediaFile;
|
|
22
|
+
|
|
23
|
+
export declare class WppApiClient {
|
|
24
|
+
constructor(options: WppApiClientOptions);
|
|
25
|
+
|
|
26
|
+
/** Status da sessão (conectada, pareando, desconectada). */
|
|
27
|
+
status(): Promise<Record<string, unknown>>;
|
|
28
|
+
|
|
29
|
+
/** QR Code para parear o número. */
|
|
30
|
+
qrCode(): Promise<Record<string, unknown>>;
|
|
31
|
+
|
|
32
|
+
/** Perfil do número conectado. */
|
|
33
|
+
me(): Promise<Record<string, unknown>>;
|
|
34
|
+
|
|
35
|
+
/** Envia mensagem de texto. */
|
|
36
|
+
sendText(phone: string, message: string): Promise<Record<string, unknown>>;
|
|
37
|
+
|
|
38
|
+
/** Envia imagem com legenda opcional. */
|
|
39
|
+
sendImage(phone: string, image: MediaInput, caption?: string): Promise<Record<string, unknown>>;
|
|
40
|
+
|
|
41
|
+
/** Envia arquivo/documento. */
|
|
42
|
+
sendFile(phone: string, file: MediaInput, caption?: string): Promise<Record<string, unknown>>;
|
|
43
|
+
|
|
44
|
+
/** Envia áudio/voz. */
|
|
45
|
+
sendVoice(phone: string, audio: MediaInput): Promise<Record<string, unknown>>;
|
|
46
|
+
|
|
47
|
+
/** Envia vídeo com legenda opcional. */
|
|
48
|
+
sendVideo(phone: string, video: MediaInput, caption?: string): Promise<Record<string, unknown>>;
|
|
49
|
+
|
|
50
|
+
/** Verifica se o número tem WhatsApp antes de enviar. */
|
|
51
|
+
checkNumber(phone: string): Promise<Record<string, unknown>>;
|
|
52
|
+
|
|
53
|
+
/** Lista os chats da instância. */
|
|
54
|
+
chats(limit?: number): Promise<Record<string, unknown>[]>;
|
|
55
|
+
|
|
56
|
+
/** Lista os grupos da instância. */
|
|
57
|
+
groups(): Promise<Record<string, unknown>[]>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default WppApiClient;
|
package/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WPPAPI JS SDK — cliente mínimo para o gateway público da WPPAPI.
|
|
3
|
+
* https://wpp-api.com
|
|
4
|
+
*
|
|
5
|
+
* Zero dependências: usa fetch nativo (browser / Node 18+).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { WppApiClient } from "wppapi-sdk";
|
|
9
|
+
*
|
|
10
|
+
* const client = new WppApiClient({
|
|
11
|
+
* baseUrl: "https://api.wpp-api.com",
|
|
12
|
+
* instanceId: "sua-instancia",
|
|
13
|
+
* token: "seu-token",
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* await client.sendText("5511999999999", "Olá! 👋");
|
|
17
|
+
*/
|
|
18
|
+
export class WppApiClient {
|
|
19
|
+
/**
|
|
20
|
+
* @param {object} opts
|
|
21
|
+
* @param {string} opts.baseUrl - Base da API, ex.: https://api.wpp-api.com
|
|
22
|
+
* @param {string} opts.instanceId - ID público da instância
|
|
23
|
+
* @param {string} opts.token - Token da instância
|
|
24
|
+
* @param {boolean} [opts.clientTokenHeader=false] - Envia o token no header
|
|
25
|
+
* `Client-Token` em vez da URL (recomendado em ambientes com logs de URL)
|
|
26
|
+
*/
|
|
27
|
+
constructor({ baseUrl, instanceId, token, clientTokenHeader = false }) {
|
|
28
|
+
if (!baseUrl || !instanceId || !token) {
|
|
29
|
+
throw new Error("baseUrl, instanceId e token são obrigatórios");
|
|
30
|
+
}
|
|
31
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
32
|
+
this.instanceId = instanceId;
|
|
33
|
+
this.token = token;
|
|
34
|
+
this.clientTokenHeader = clientTokenHeader;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
path(suffix) {
|
|
38
|
+
const t = this.clientTokenHeader ? "_" : this.token;
|
|
39
|
+
return `${this.baseUrl}/instances/${this.instanceId}/token/${t}${suffix}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
headers(json = true) {
|
|
43
|
+
const h = {};
|
|
44
|
+
if (json) h["Content-Type"] = "application/json";
|
|
45
|
+
if (this.clientTokenHeader) h["Client-Token"] = this.token;
|
|
46
|
+
return h;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async request(method, suffix, body) {
|
|
50
|
+
const res = await fetch(this.path(suffix), {
|
|
51
|
+
method,
|
|
52
|
+
headers: this.headers(body !== undefined),
|
|
53
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
54
|
+
});
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const err = await res.text();
|
|
57
|
+
throw new Error(err || res.statusText);
|
|
58
|
+
}
|
|
59
|
+
return res.json();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Status da sessão (conectada, pareando, desconectada). */
|
|
63
|
+
status() {
|
|
64
|
+
return this.request("GET", "/status");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** QR Code para parear o número. */
|
|
68
|
+
qrCode() {
|
|
69
|
+
return this.request("GET", "/qr-code");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Perfil do número conectado. */
|
|
73
|
+
me() {
|
|
74
|
+
return this.request("GET", "/me");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Envia mensagem de texto. */
|
|
78
|
+
sendText(phone, message) {
|
|
79
|
+
return this.request("POST", "/send-text", { phone, message });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Envia imagem com legenda opcional.
|
|
84
|
+
* @param {string|{url?: string, data?: string, mimetype?: string, filename?: string}} image
|
|
85
|
+
* URL da imagem, ou objeto file com `data` em base64 (sem prefixo data:)
|
|
86
|
+
*/
|
|
87
|
+
sendImage(phone, image, caption) {
|
|
88
|
+
const body =
|
|
89
|
+
typeof image === "string" ? { phone, image, caption } : { phone, file: image, caption };
|
|
90
|
+
return this.request("POST", "/send-image", body);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Envia arquivo/documento.
|
|
95
|
+
* @param {string|{url?: string, data?: string, mimetype?: string, filename?: string}} file
|
|
96
|
+
*/
|
|
97
|
+
sendFile(phone, file, caption) {
|
|
98
|
+
const body =
|
|
99
|
+
typeof file === "string" ? { phone, document: file, caption } : { phone, file, caption };
|
|
100
|
+
return this.request("POST", "/send-file", body);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Envia áudio/voz.
|
|
105
|
+
* @param {string|{url?: string, data?: string, mimetype?: string, filename?: string}} audio
|
|
106
|
+
*/
|
|
107
|
+
sendVoice(phone, audio) {
|
|
108
|
+
const body = typeof audio === "string" ? { phone, audio } : { phone, file: audio };
|
|
109
|
+
return this.request("POST", "/send-voice", body);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Envia vídeo com legenda opcional.
|
|
114
|
+
* @param {string|{url?: string, data?: string, mimetype?: string, filename?: string}} video
|
|
115
|
+
*/
|
|
116
|
+
sendVideo(phone, video, caption) {
|
|
117
|
+
const body =
|
|
118
|
+
typeof video === "string" ? { phone, video, caption } : { phone, file: video, caption };
|
|
119
|
+
return this.request("POST", "/send-video", body);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Verifica se o número tem WhatsApp antes de enviar. */
|
|
123
|
+
checkNumber(phone) {
|
|
124
|
+
return this.request("GET", `/check-number?phone=${encodeURIComponent(phone)}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Lista os chats da instância. */
|
|
128
|
+
chats(limit = 50) {
|
|
129
|
+
return this.request("GET", `/chats?limit=${limit}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Lista os grupos da instância. */
|
|
133
|
+
groups() {
|
|
134
|
+
return this.request("GET", "/groups");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default WppApiClient;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wppapi-sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "SDK JavaScript oficial da WPPAPI — API WhatsApp multi-tenant (envio de texto e mídia, status, webhooks). Zero dependências, browser e Node 18+.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"whatsapp",
|
|
7
|
+
"whatsapp-api",
|
|
8
|
+
"api-whatsapp",
|
|
9
|
+
"wppapi",
|
|
10
|
+
"chatbot",
|
|
11
|
+
"automacao",
|
|
12
|
+
"n8n",
|
|
13
|
+
"chatwoot"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://wpp-api.com?utm_source=npm&utm_medium=sdk",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/iproute-tecnologia/wppapi-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/iproute-tecnologia/wppapi-sdk-js.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "IPRoute Tecnologia <contato@wpp-api.com>",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"types": "index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"index.js",
|
|
30
|
+
"index.d.ts",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
}
|
|
37
|
+
}
|