@openvertice/bot-sdk 0.0.0-stage → 0.1.1
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/README.md +198 -2
- package/dist/src/audio.d.ts +32 -0
- package/dist/src/audio.d.ts.map +1 -0
- package/dist/src/audio.js +47 -0
- package/dist/src/audio.js.map +1 -0
- package/dist/src/cliente.d.ts +213 -0
- package/dist/src/cliente.d.ts.map +1 -0
- package/dist/src/cliente.js +381 -0
- package/dist/src/cliente.js.map +1 -0
- package/dist/src/gateway.d.ts +81 -0
- package/dist/src/gateway.d.ts.map +1 -0
- package/dist/src/gateway.js +431 -0
- package/dist/src/gateway.js.map +1 -0
- package/dist/src/http.d.ts +119 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +189 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/tipos.d.ts +243 -0
- package/dist/src/tipos.d.ts.map +1 -0
- package/dist/src/tipos.js +5 -0
- package/dist/src/tipos.js.map +1 -0
- package/dist/src/voz-wrtc.d.ts +20 -0
- package/dist/src/voz-wrtc.d.ts.map +1 -0
- package/dist/src/voz-wrtc.js +68 -0
- package/dist/src/voz-wrtc.js.map +1 -0
- package/dist/src/voz.d.ts +150 -0
- package/dist/src/voz.d.ts.map +1 -0
- package/dist/src/voz.js +311 -0
- package/dist/src/voz.js.map +1 -0
- package/dist/src/wav.d.ts +29 -0
- package/dist/src/wav.d.ts.map +1 -0
- package/dist/src/wav.js +54 -0
- package/dist/src/wav.js.map +1 -0
- package/package.json +42 -3
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/** `WebSocket.readyState` for an open socket. */
|
|
2
|
+
const ABERTO = 1;
|
|
3
|
+
/** How long without any server frame before the connection is assumed dead. */
|
|
4
|
+
const SEM_SINAL_MS = 90_000;
|
|
5
|
+
/** Deadline for a new socket to answer `hello`/`ready` before the attempt is abandoned. */
|
|
6
|
+
const SEM_RESPOSTA_MS = 15_000;
|
|
7
|
+
/** Codes where retrying is pointless: the server refused the bot. */
|
|
8
|
+
const DEFINITIVOS = new Set([4001, 4003, 4005]);
|
|
9
|
+
/** Another connection took over this bot: reconnecting would fight over it. */
|
|
10
|
+
const OUTRA_CONEXAO = 4000;
|
|
11
|
+
/** Session closed (rotated token, disabled bot): it does not come back on its own. */
|
|
12
|
+
const SESSAO_ENCERRADA = 4009;
|
|
13
|
+
/** Expired session: renew the token and come back. */
|
|
14
|
+
const SESSAO_EXPIRADA = 4002;
|
|
15
|
+
/**
|
|
16
|
+
* WebSocket client for the Vértice gateway.
|
|
17
|
+
*
|
|
18
|
+
* It speaks the `{op, t, d, s}` envelope: op 10 `hello`, op 2 `identify` (or
|
|
19
|
+
* op 6 `resume`), op 1 heartbeat, op 11 heartbeat ack, op 0 dispatch and op 4
|
|
20
|
+
* action. Heartbeat, session resume and reconnection with exponential backoff
|
|
21
|
+
* are handled here, so bot authors never have to.
|
|
22
|
+
*
|
|
23
|
+
* One instance per bot: `conectar()` resolves only after `ready` arrives.
|
|
24
|
+
*/
|
|
25
|
+
export class Gateway {
|
|
26
|
+
opcoes;
|
|
27
|
+
#ws = null;
|
|
28
|
+
#sessao = null;
|
|
29
|
+
#seq = 0;
|
|
30
|
+
#batida = null;
|
|
31
|
+
#vigia = null;
|
|
32
|
+
/** Deadline of the attempt in progress (waiting for `hello`/`ready`). */
|
|
33
|
+
#prazo = null;
|
|
34
|
+
/** Backoff timer between attempts. */
|
|
35
|
+
#recuo = null;
|
|
36
|
+
/** Wakes the backoff early, so `fechar()` can settle a sleeping `conectar()`. */
|
|
37
|
+
#acordar = null;
|
|
38
|
+
/** Connection cycle in progress; one at a time, no matter who asks. */
|
|
39
|
+
#corrida = null;
|
|
40
|
+
#tentativa = 0;
|
|
41
|
+
#encerrado = false;
|
|
42
|
+
#estado = "conectando";
|
|
43
|
+
/** @param opcoes Endpoints, credentials and hooks used by the connection. */
|
|
44
|
+
constructor(opcoes) {
|
|
45
|
+
this.opcoes = opcoes;
|
|
46
|
+
}
|
|
47
|
+
/** Current connection state. */
|
|
48
|
+
get estado() {
|
|
49
|
+
return this.#estado;
|
|
50
|
+
}
|
|
51
|
+
/** Session in use, or `null` before the first connection attempt. */
|
|
52
|
+
get sessaoAtual() {
|
|
53
|
+
return this.#sessao;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Opens the socket and resolves once the bot is identified (`ready`).
|
|
57
|
+
*
|
|
58
|
+
* Transient failures — network drops, an unreachable server, a session that
|
|
59
|
+
* could not be renewed, a gateway that never answers — are retried with
|
|
60
|
+
* exponential backoff until the bot is ready. Only a definitive refusal (or
|
|
61
|
+
* {@link fechar}) stops the loop.
|
|
62
|
+
*
|
|
63
|
+
* @returns A promise that settles when the gateway is truly ready.
|
|
64
|
+
* @throws {Error} When the server refuses the bot or the gateway was closed.
|
|
65
|
+
*/
|
|
66
|
+
conectar() {
|
|
67
|
+
this.#encerrado = false;
|
|
68
|
+
// Already identified: nothing to open, and a healthy socket is not replaced.
|
|
69
|
+
if (this.#estado === "pronto")
|
|
70
|
+
return Promise.resolve();
|
|
71
|
+
if (this.#corrida)
|
|
72
|
+
return this.#corrida;
|
|
73
|
+
// A manual start begins with the short backoff again.
|
|
74
|
+
this.#tentativa = 0;
|
|
75
|
+
return this.#iniciarCiclo();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Starts a connection cycle, or joins the one already running.
|
|
79
|
+
*
|
|
80
|
+
* @returns The cycle promise; it settles on `ready`, on a definitive refusal
|
|
81
|
+
* or when {@link fechar} is called.
|
|
82
|
+
*/
|
|
83
|
+
#iniciarCiclo() {
|
|
84
|
+
if (this.#corrida)
|
|
85
|
+
return this.#corrida;
|
|
86
|
+
const corrida = this.#manterConectado().finally(() => {
|
|
87
|
+
if (this.#corrida === corrida)
|
|
88
|
+
this.#corrida = null;
|
|
89
|
+
});
|
|
90
|
+
this.#corrida = corrida;
|
|
91
|
+
return corrida;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Attempts the connection and retries until `ready` or a definitive refusal.
|
|
95
|
+
*
|
|
96
|
+
* Every failure comes back through here — including the ones that happen
|
|
97
|
+
* before a socket exists, such as a session that could not be renewed. It is
|
|
98
|
+
* a loop on purpose: a single retry used to end the reconnection, leaving the
|
|
99
|
+
* bot offline for good.
|
|
100
|
+
*/
|
|
101
|
+
async #manterConectado() {
|
|
102
|
+
for (;;) {
|
|
103
|
+
// `fechar()` may have run while we were sleeping in the backoff.
|
|
104
|
+
if (this.#encerrado)
|
|
105
|
+
throw new Error("gateway encerrado");
|
|
106
|
+
try {
|
|
107
|
+
await this.#abrir();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
catch (erro) {
|
|
111
|
+
if (this.#encerrado)
|
|
112
|
+
throw erro;
|
|
113
|
+
await this.#esperarRecuo(erro);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Waits out the backoff before the next attempt.
|
|
119
|
+
*
|
|
120
|
+
* The wait is interruptible: {@link fechar} wakes it, so a `conectar()` call
|
|
121
|
+
* sleeping here settles instead of hanging until the timer fires.
|
|
122
|
+
*
|
|
123
|
+
* @param erro Failure that triggered the wait; it goes into the state detail.
|
|
124
|
+
*/
|
|
125
|
+
async #esperarRecuo(erro) {
|
|
126
|
+
this.#tentativa += 1;
|
|
127
|
+
const espera = Math.min(30_000, 500 * 2 ** Math.min(this.#tentativa, 6));
|
|
128
|
+
this.#mudar("reconectando", `${mensagemDe(erro)}: volta em ${espera} ms (tentativa ${this.#tentativa})`);
|
|
129
|
+
await new Promise((resolver) => {
|
|
130
|
+
this.#acordar = () => {
|
|
131
|
+
this.#acordar = null;
|
|
132
|
+
if (this.#recuo)
|
|
133
|
+
clearTimeout(this.#recuo);
|
|
134
|
+
this.#recuo = null;
|
|
135
|
+
resolver();
|
|
136
|
+
};
|
|
137
|
+
this.#recuo = setTimeout(() => this.#acordar?.(), espera);
|
|
138
|
+
this.#recuo.unref?.();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Opens one socket attempt.
|
|
143
|
+
*
|
|
144
|
+
* Resolves on `ready` and rejects on any failure before it (socket error,
|
|
145
|
+
* close, no answer within {@link SEM_RESPOSTA_MS}, session error), which is
|
|
146
|
+
* what lets {@link #manterConectado} decide when to try again.
|
|
147
|
+
*/
|
|
148
|
+
async #abrir() {
|
|
149
|
+
this.#mudar("conectando");
|
|
150
|
+
const sessao = await this.opcoes.sessao();
|
|
151
|
+
// `fechar()` may have run while the session was being fetched: do not open
|
|
152
|
+
// a socket that nobody is waiting for.
|
|
153
|
+
if (this.#encerrado)
|
|
154
|
+
throw new Error("gateway encerrado");
|
|
155
|
+
this.#sessao = sessao;
|
|
156
|
+
return new Promise((resolver, rejeitar) => {
|
|
157
|
+
let concluido = false;
|
|
158
|
+
const concluir = (erro) => {
|
|
159
|
+
if (concluido)
|
|
160
|
+
return;
|
|
161
|
+
concluido = true;
|
|
162
|
+
if (this.#prazo)
|
|
163
|
+
clearTimeout(this.#prazo);
|
|
164
|
+
this.#prazo = null;
|
|
165
|
+
if (erro)
|
|
166
|
+
rejeitar(erro);
|
|
167
|
+
else
|
|
168
|
+
resolver();
|
|
169
|
+
};
|
|
170
|
+
let ws;
|
|
171
|
+
try {
|
|
172
|
+
ws = new WebSocket(this.opcoes.url);
|
|
173
|
+
}
|
|
174
|
+
catch (erro) {
|
|
175
|
+
concluir(erro instanceof Error ? erro : new Error(String(erro)));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.#ws = ws;
|
|
179
|
+
// A socket that opens but never answers would hang this attempt (and the
|
|
180
|
+
// retry loop) forever; the deadline settles it as a failure.
|
|
181
|
+
this.#prazo = setTimeout(() => {
|
|
182
|
+
this.#prazo = null;
|
|
183
|
+
if (this.#ws !== ws)
|
|
184
|
+
return;
|
|
185
|
+
try {
|
|
186
|
+
ws.close(4000, "sem resposta");
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
/* it had already dropped */
|
|
190
|
+
}
|
|
191
|
+
concluir(new Error("o gateway não respondeu ao `identify`"));
|
|
192
|
+
}, SEM_RESPOSTA_MS);
|
|
193
|
+
this.#prazo.unref?.();
|
|
194
|
+
ws.addEventListener("error", () => {
|
|
195
|
+
if (this.#ws !== ws)
|
|
196
|
+
return;
|
|
197
|
+
concluir(new Error("não consegui abrir o gateway"));
|
|
198
|
+
});
|
|
199
|
+
ws.addEventListener("message", (evento) => {
|
|
200
|
+
if (this.#ws !== ws)
|
|
201
|
+
return;
|
|
202
|
+
const envelope = this.#ler(evento);
|
|
203
|
+
if (!envelope)
|
|
204
|
+
return;
|
|
205
|
+
this.#armarVigia();
|
|
206
|
+
// hello: now it is safe to identify (or to resume, if a seq exists).
|
|
207
|
+
if (envelope.op === 10) {
|
|
208
|
+
this.#identificar(ws, sessao);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.#receber(envelope, () => concluir());
|
|
212
|
+
});
|
|
213
|
+
ws.addEventListener("close", (evento) => {
|
|
214
|
+
// A close from a socket that is no longer the current one is residue
|
|
215
|
+
// from a previous attempt: it must not touch the live connection.
|
|
216
|
+
if (this.#ws !== ws)
|
|
217
|
+
return;
|
|
218
|
+
const estavaPronto = this.#estado === "pronto";
|
|
219
|
+
const definitivo = this.#aoFechar(evento.code, evento.reason);
|
|
220
|
+
concluir(new Error(this.#estado === "encerrado"
|
|
221
|
+
? "gateway encerrado"
|
|
222
|
+
: `gateway ${definitivo ? "recusado" : "caiu"} (${evento.code})`));
|
|
223
|
+
// After `ready` there is no attempt left to fail — the loop already
|
|
224
|
+
// returned — so a drop has to start a new cycle.
|
|
225
|
+
if (!definitivo && estavaPronto) {
|
|
226
|
+
this.#corrida = null;
|
|
227
|
+
void this.#iniciarCiclo().catch(() => { });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Sends `identify` (op 2) on a fresh connection, or `resume` (op 6) when a
|
|
234
|
+
* sequence number from a previous connection is available.
|
|
235
|
+
*
|
|
236
|
+
* @param ws Socket already past `hello`.
|
|
237
|
+
* @param sessao Session to present to the server.
|
|
238
|
+
*/
|
|
239
|
+
#identificar(ws, sessao) {
|
|
240
|
+
const comandos = this.opcoes.comandos ?? [];
|
|
241
|
+
const envelope = this.#seq > 0
|
|
242
|
+
? { op: 6, d: { sessao: sessao.sessao, seq: this.#seq, comandos } }
|
|
243
|
+
: {
|
|
244
|
+
op: 2,
|
|
245
|
+
d: { sessao: sessao.sessao, intents: this.opcoes.intents, comandos },
|
|
246
|
+
};
|
|
247
|
+
ws.send(JSON.stringify(envelope));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Parses one socket frame, discarding anything that is not a valid envelope.
|
|
251
|
+
*
|
|
252
|
+
* @param evento Raw `message` event from the socket.
|
|
253
|
+
* @returns The envelope, or `null` when the payload is not JSON or has no `op`.
|
|
254
|
+
*/
|
|
255
|
+
#ler(evento) {
|
|
256
|
+
try {
|
|
257
|
+
const bruto = typeof evento.data === "string" ? evento.data : String(evento.data);
|
|
258
|
+
const envelope = JSON.parse(bruto);
|
|
259
|
+
return typeof envelope?.op === "number" ? envelope : null;
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Handles one gateway frame.
|
|
267
|
+
*
|
|
268
|
+
* op 0 is a dispatch, op 11 is the heartbeat ack and everything else is
|
|
269
|
+
* ignored here.
|
|
270
|
+
*
|
|
271
|
+
* @param envelope Frame received from the socket.
|
|
272
|
+
* @param aoPronto Called once, as soon as `ready` marks the bot as connected.
|
|
273
|
+
*/
|
|
274
|
+
#receber(envelope, aoPronto) {
|
|
275
|
+
if (envelope.op === 11)
|
|
276
|
+
return;
|
|
277
|
+
if (envelope.op !== 0 || !envelope.t)
|
|
278
|
+
return;
|
|
279
|
+
if (typeof envelope.s === "number")
|
|
280
|
+
this.#seq = envelope.s;
|
|
281
|
+
if (envelope.t === "ready") {
|
|
282
|
+
this.#tentativa = 0;
|
|
283
|
+
this.#mudar("pronto");
|
|
284
|
+
this.#bater();
|
|
285
|
+
aoPronto();
|
|
286
|
+
}
|
|
287
|
+
this.opcoes.aoEvento(envelope.t, envelope.d);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Sends an action (op 4) to the gateway.
|
|
291
|
+
*
|
|
292
|
+
* Voice uses this for `voz.entrar`, `voz.sair` and `voice.signal`; the same
|
|
293
|
+
* route carries `comandos` updates.
|
|
294
|
+
*
|
|
295
|
+
* @param tipo Action name understood by the server.
|
|
296
|
+
* @param dados Action payload, merged into `d`.
|
|
297
|
+
* @throws {Error} When the gateway is not connected.
|
|
298
|
+
*/
|
|
299
|
+
agir(tipo, dados = {}) {
|
|
300
|
+
const ws = this.#ws;
|
|
301
|
+
if (!ws || ws.readyState !== ABERTO)
|
|
302
|
+
throw new Error("O gateway não está conectado.");
|
|
303
|
+
ws.send(JSON.stringify({ op: 4, d: { tipo, ...dados } }));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Closes the connection on purpose: it will not reconnect.
|
|
307
|
+
*
|
|
308
|
+
* @param codigo WebSocket close code sent to the server.
|
|
309
|
+
* @param motivo Human-readable reason sent to the server.
|
|
310
|
+
*/
|
|
311
|
+
fechar(codigo = 1000, motivo = "pedido do bot") {
|
|
312
|
+
this.#encerrado = true;
|
|
313
|
+
this.#limpar();
|
|
314
|
+
// Nothing else to wait for: wake a `conectar()` that is sleeping in backoff.
|
|
315
|
+
this.#acordar?.();
|
|
316
|
+
try {
|
|
317
|
+
this.#ws?.close(codigo, motivo);
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
/* it was already closing */
|
|
321
|
+
}
|
|
322
|
+
// `#ws` is cleared by the close handler: it has to settle the attempt in
|
|
323
|
+
// progress, otherwise a `conectar()` waiting on it would never return.
|
|
324
|
+
this.#mudar("encerrado");
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Stores the new state, notifies the bot and logs the detail, when there is one.
|
|
328
|
+
*
|
|
329
|
+
* @param estado New connection state.
|
|
330
|
+
* @param detalhe Optional human-readable explanation for logs and errors.
|
|
331
|
+
*/
|
|
332
|
+
#mudar(estado, detalhe) {
|
|
333
|
+
this.#estado = estado;
|
|
334
|
+
this.opcoes.aoEstado?.(estado, detalhe);
|
|
335
|
+
if (detalhe)
|
|
336
|
+
this.opcoes.log?.(`[${estado}] ${detalhe}`);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* (Re)starts the heartbeat timer, sending op 1 with the last sequence number.
|
|
340
|
+
*
|
|
341
|
+
* The interval is left `unref`'d so it never keeps the process alive.
|
|
342
|
+
*/
|
|
343
|
+
#bater() {
|
|
344
|
+
if (this.#batida)
|
|
345
|
+
clearInterval(this.#batida);
|
|
346
|
+
this.#batida = setInterval(() => {
|
|
347
|
+
const ws = this.#ws;
|
|
348
|
+
if (!ws || ws.readyState !== ABERTO)
|
|
349
|
+
return;
|
|
350
|
+
ws.send(JSON.stringify({ op: 1, d: this.#seq }));
|
|
351
|
+
}, this.opcoes.heartbeatMs);
|
|
352
|
+
this.#batida.unref?.();
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* With nothing from the server for more than 90 s, the connection died
|
|
356
|
+
* silently (proxy, NAT). Drops it so the reconnect logic kicks in: it is the
|
|
357
|
+
* same deadline the server uses.
|
|
358
|
+
*/
|
|
359
|
+
#armarVigia() {
|
|
360
|
+
if (this.#vigia)
|
|
361
|
+
clearTimeout(this.#vigia);
|
|
362
|
+
this.#vigia = setTimeout(() => {
|
|
363
|
+
if (this.#estado === "encerrado")
|
|
364
|
+
return;
|
|
365
|
+
this.opcoes.log?.("sem sinal do servidor; reconectando");
|
|
366
|
+
try {
|
|
367
|
+
this.#ws?.close(4000, "sem sinal");
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
/* it had already dropped */
|
|
371
|
+
}
|
|
372
|
+
}, SEM_SINAL_MS);
|
|
373
|
+
this.#vigia.unref?.();
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Applies the close policy: stop for good or let the caller reconnect.
|
|
377
|
+
*
|
|
378
|
+
* @param codigo WebSocket close code.
|
|
379
|
+
* @param motivo Close reason, used in the log and in the state detail.
|
|
380
|
+
* @returns `true` when the bot must stop; `false` when a retry makes sense.
|
|
381
|
+
*/
|
|
382
|
+
#aoFechar(codigo, motivo) {
|
|
383
|
+
this.#limpar();
|
|
384
|
+
this.#ws = null;
|
|
385
|
+
if (this.#encerrado)
|
|
386
|
+
return true;
|
|
387
|
+
if (DEFINITIVOS.has(codigo)) {
|
|
388
|
+
this.#mudar("recusado", `${codigo}: ${motivo}`);
|
|
389
|
+
this.#encerrado = true;
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (codigo === OUTRA_CONEXAO) {
|
|
393
|
+
this.#mudar("recusado", "outra conexão assumiu este bot");
|
|
394
|
+
this.#encerrado = true;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
if (codigo === SESSAO_ENCERRADA) {
|
|
398
|
+
this.#mudar("recusado", "a sessão foi encerrada (token girado ou bot desativado)");
|
|
399
|
+
this.#encerrado = true;
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
// 4002 (expired session) and network drops: renew the session and come back.
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Clears the timers of a live connection (heartbeat, silence watch, attempt
|
|
407
|
+
* deadline), so a closed gateway leaves no handles behind.
|
|
408
|
+
*
|
|
409
|
+
* The backoff timer is not touched here: it belongs to {@link #esperarRecuo},
|
|
410
|
+
* which is woken by {@link fechar}.
|
|
411
|
+
*/
|
|
412
|
+
#limpar() {
|
|
413
|
+
if (this.#batida)
|
|
414
|
+
clearInterval(this.#batida);
|
|
415
|
+
if (this.#vigia)
|
|
416
|
+
clearTimeout(this.#vigia);
|
|
417
|
+
if (this.#prazo)
|
|
418
|
+
clearTimeout(this.#prazo);
|
|
419
|
+
this.#batida = null;
|
|
420
|
+
this.#vigia = null;
|
|
421
|
+
this.#prazo = null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Turns any thrown value into a printable message.
|
|
426
|
+
*
|
|
427
|
+
* @param erro Value thrown or rejected.
|
|
428
|
+
* @returns `erro.message` for `Error`s, `String(erro)` otherwise.
|
|
429
|
+
*/
|
|
430
|
+
const mensagemDe = (erro) => erro instanceof Error ? erro.message : String(erro);
|
|
431
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAOA,iDAAiD;AACjD,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,+EAA+E;AAC/E,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,2FAA2F;AAC3F,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,qEAAqE;AACrE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,+EAA+E;AAC/E,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,sFAAsF;AACtF,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,sDAAsD;AACtD,MAAM,eAAe,GAAG,IAAI,CAAC;AA8C7B;;;;;;;;;GASG;AACH,MAAM,OAAO,OAAO;IAmBW;IAlB7B,GAAG,GAAqB,IAAI,CAAC;IAC7B,OAAO,GAAkB,IAAI,CAAC;IAC9B,IAAI,GAAG,CAAC,CAAC;IACT,OAAO,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AM,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Descoberta, Intencao, Mensagem, Sessao } from "./tipos.js";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown for every non-2xx response from the bot API.
|
|
4
|
+
*
|
|
5
|
+
* It carries the HTTP status and, when the server sends one, the machine-readable
|
|
6
|
+
* `codigo` (e.g. `"canal"`, `"voz"`), so callers can react to the cause instead
|
|
7
|
+
* of parsing the message.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ErroDaApi extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly codigo: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* @param mensagem Human-readable message taken from the server payload.
|
|
14
|
+
* @param status HTTP status code of the failed response.
|
|
15
|
+
* @param codigo Server error code, when the payload provided one.
|
|
16
|
+
*/
|
|
17
|
+
constructor(mensagem: string, status: number, codigo?: string | null);
|
|
18
|
+
}
|
|
19
|
+
/** Credentials and transport used by every {@link Http} call. */
|
|
20
|
+
export interface OpcoesHttp {
|
|
21
|
+
/** Server base URL, e.g. `https://vertice.example` (default: `http://localhost:8080`). */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/** Bot token (`vtb_…`), copied from the admin panel. */
|
|
24
|
+
token: string;
|
|
25
|
+
/** Injectable for tests; defaults to the global `fetch`. */
|
|
26
|
+
fetch?: typeof fetch;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Minimal HTTP client for the `/api/bots/*` routes.
|
|
30
|
+
*
|
|
31
|
+
* Requests authenticate as `Bot <token>` until a session exists, then as
|
|
32
|
+
* `Bearer <sessao>` — the form the server expects on message routes. There is
|
|
33
|
+
* no runtime dependency: it uses the global `fetch` from Node 22+.
|
|
34
|
+
*/
|
|
35
|
+
export declare class Http {
|
|
36
|
+
#private;
|
|
37
|
+
/**
|
|
38
|
+
* @param options Base URL, bot token and an optional `fetch` implementation.
|
|
39
|
+
* @throws {Error} When the token is missing or empty.
|
|
40
|
+
*/
|
|
41
|
+
constructor({ baseUrl, token, fetch: buscar }: OpcoesHttp);
|
|
42
|
+
/**
|
|
43
|
+
* Fetches the discovery document: what this bot may do, as configured in the panel.
|
|
44
|
+
*
|
|
45
|
+
* @returns Channels, intents, ICE servers and rate limits granted to the bot.
|
|
46
|
+
* @throws {ErroDaApi} When the token is rejected.
|
|
47
|
+
*/
|
|
48
|
+
descobrir(): Promise<Descoberta>;
|
|
49
|
+
/**
|
|
50
|
+
* Exchanges the bot token for a short-lived session (15 minutes).
|
|
51
|
+
*
|
|
52
|
+
* The SDK renews it on its own shortly before it expires.
|
|
53
|
+
*
|
|
54
|
+
* @returns The new session and its expiry.
|
|
55
|
+
* @throws {ErroDaApi} When the token is invalid or the bot is disabled.
|
|
56
|
+
*/
|
|
57
|
+
abrirSessao(): Promise<Sessao>;
|
|
58
|
+
/**
|
|
59
|
+
* Posts a text message over HTTP (the gateway can do the same over WebSocket).
|
|
60
|
+
*
|
|
61
|
+
* @param code Channel code.
|
|
62
|
+
* @param texto Message content.
|
|
63
|
+
* @param sessao Session token; when absent, the bot token is used.
|
|
64
|
+
* @returns The message the server created (id, timestamp, …).
|
|
65
|
+
* @throws {ErroDaApi} When the channel does not exist or the bot cannot post.
|
|
66
|
+
*/
|
|
67
|
+
enviar(code: string, texto: string, sessao?: string): Promise<Mensagem>;
|
|
68
|
+
/**
|
|
69
|
+
* Reads one page of channel history (up to 100 messages).
|
|
70
|
+
*
|
|
71
|
+
* @param code Channel code.
|
|
72
|
+
* @param options `antesDe` to page backwards; `sessao` to authenticate with a session.
|
|
73
|
+
* @returns The page, plus `temMais` telling whether another page exists.
|
|
74
|
+
* @throws {ErroDaApi} When the bot cannot read the channel.
|
|
75
|
+
*/
|
|
76
|
+
historico(code: string, { antesDe, sessao }?: {
|
|
77
|
+
antesDe?: number;
|
|
78
|
+
sessao?: string;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
sala: string;
|
|
81
|
+
mensagens: Mensagem[];
|
|
82
|
+
temMais: boolean;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Uploads a file (or a voice message) to a channel.
|
|
86
|
+
*
|
|
87
|
+
* The body goes raw, with the type in the headers — the same path the chat
|
|
88
|
+
* upload uses, without multipart.
|
|
89
|
+
*
|
|
90
|
+
* @param code Channel code.
|
|
91
|
+
* @param corpo File bytes.
|
|
92
|
+
* @param options File name, MIME type, whether it is a voice message, and session.
|
|
93
|
+
* @returns The message the server created.
|
|
94
|
+
* @throws {ErroDaApi} When the upload fails or the response carries no message.
|
|
95
|
+
*/
|
|
96
|
+
enviarArquivo(code: string, corpo: Uint8Array, { nome, mime, tipo, sessao, }?: {
|
|
97
|
+
nome?: string;
|
|
98
|
+
mime?: string;
|
|
99
|
+
tipo?: "arquivo" | "voz";
|
|
100
|
+
sessao?: string;
|
|
101
|
+
}): Promise<Mensagem>;
|
|
102
|
+
/**
|
|
103
|
+
* Deletes one of the bot's own messages (the server refuses anyone else's).
|
|
104
|
+
*
|
|
105
|
+
* @param code Channel code the message belongs to.
|
|
106
|
+
* @param id Message id.
|
|
107
|
+
* @param sessao Session token; when absent, the bot token is used.
|
|
108
|
+
* @throws {ErroDaApi} When the message is not the bot's or is already gone.
|
|
109
|
+
*/
|
|
110
|
+
apagar(code: string, id: string, sessao?: string): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Lists the intents the server granted, for callers that want to check before connecting.
|
|
113
|
+
*
|
|
114
|
+
* @returns The intent names granted to this bot.
|
|
115
|
+
* @throws {ErroDaApi} When discovery fails.
|
|
116
|
+
*/
|
|
117
|
+
intents(): Promise<Intencao[]>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MA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