@botozap/sdk 0.10.0 → 0.12.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/CHANGELOG.md +37 -0
- package/README.md +130 -5
- package/dist/index.cjs +170 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +490 -22
- package/dist/index.d.ts +490 -22
- package/dist/index.js +169 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @botozap/sdk
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ab0ddbc: Add Instagram interactive button/card/gallery sends with human_agent and channel receipts, extended comment-rule fields and deletion, and messenger-profile read/update/delete/sync across SDK, CLI and MCP. Preserve WhatsApp interactive formats and partial PATCH semantics, and expose messenger-profile scopes and structured results.
|
|
8
|
+
- df51d96: Add Instagram comment-rule button and delivery fields, message-rule CRUD with trigger/action types and message-rules scopes, and comment-rule metrics by period across SDK, CLI and MCP. Preserve nullable fields and partial PATCH bodies, advertise typed MCP results, and support JSON input for comment and message rules in the CLI.
|
|
9
|
+
|
|
10
|
+
## 0.11.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 0df58da: Instagram nas ferramentas públicas.
|
|
15
|
+
|
|
16
|
+
SDK: `SendResult.wamid` passa a ser `string | null` e ganha `external_id` e
|
|
17
|
+
`channel` — no Instagram a API devolve `wamid: null` com o `mid` em
|
|
18
|
+
`external_id`, e o SDK deixava de aceitar esse recibo (`malformed_response`) em
|
|
19
|
+
`send`, `sendMedia` e `sendReaction`. `messages.send` e `conversations.reply`
|
|
20
|
+
aceitam `quick_replies`; `conversations.reply` usa a Conta de canal como origem
|
|
21
|
+
em Conversas do Instagram; `conversations.list` filtra por `channel` e
|
|
22
|
+
`channel_account_id`. Novo recurso `channelAccounts` (`list`, `get` e Regras de
|
|
23
|
+
comentário: `listCommentRules`, `getCommentRule`, `createCommentRule`,
|
|
24
|
+
`updateCommentRule`). `ChannelAccount.instagram` traz a saúde da conexão
|
|
25
|
+
(`token_status`, `token_expires_at`, `token_refreshed_at`); `Message` tipa
|
|
26
|
+
`content.edited` (`{ count, at }`), `revoked_at`, `channel` e `external_id`.
|
|
27
|
+
|
|
28
|
+
CLI: `messages send --quick-reply`/`--quick-replies-json`, novo
|
|
29
|
+
`messages send-media` (WhatsApp ou Instagram), `conversations list --channel
|
|
30
|
+
--channel-account-id` e o comando `channel-accounts` (com `comment-rules`).
|
|
31
|
+
|
|
32
|
+
MCP: o output schema de envio aceita o recibo do Instagram (antes
|
|
33
|
+
`send_message`, `send_media_message` e `reply_to_conversation` devolviam erro
|
|
34
|
+
em envio entregue) e as telas reconhecem o recibo por `external_id`. Tools
|
|
35
|
+
novas no catálogo completo: `list_channel_accounts`, `list_comment_rules`,
|
|
36
|
+
`get_comment_rule`, `create_comment_rule`, `update_comment_rule`;
|
|
37
|
+
`get_channel_account` fica disponível sem UI no catálogo completo. O perfil
|
|
38
|
+
`assistant` não muda.
|
|
39
|
+
|
|
3
40
|
## 0.10.0
|
|
4
41
|
|
|
5
42
|
### Novidades
|
package/README.md
CHANGED
|
@@ -61,6 +61,10 @@ const result = await boto.messages.send({
|
|
|
61
61
|
console.log(result.wamid, result.status);
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
No Instagram o recibo traz `wamid: null`, `channel: "instagram"` e o `mid` da
|
|
65
|
+
Meta em `external_id`. Para correlacionar envios de qualquer canal, use
|
|
66
|
+
`result.external_id ?? result.wamid`.
|
|
67
|
+
|
|
64
68
|
A conta é derivada da chave de API. Você nunca passa um id de conta: o isolamento multi-tenant é garantido no servidor.
|
|
65
69
|
|
|
66
70
|
## Mensagens
|
|
@@ -91,7 +95,8 @@ await boto.messages.send({
|
|
|
91
95
|
from: "uuid-ou-phone_number_id",
|
|
92
96
|
});
|
|
93
97
|
|
|
94
|
-
// Responder sem combinar manualmente Contato e
|
|
98
|
+
// Responder sem combinar manualmente Contato e origem: no WhatsApp sai pelo
|
|
99
|
+
// Número da Conversa; no Instagram, pela Conta de canal (channel_account.id).
|
|
95
100
|
await boto.conversations.reply("uuid-da-conversa", {
|
|
96
101
|
text: "Resposta do agente",
|
|
97
102
|
});
|
|
@@ -127,6 +132,20 @@ const r = await boto.messages.sendReaction({
|
|
|
127
132
|
});
|
|
128
133
|
r.reaction?.action; // "react" | "unreact"
|
|
129
134
|
|
|
135
|
+
// Instagram: o mesmo endpoint, com o IGSID do contato em `to`. `from` aceita o
|
|
136
|
+
// id da conta na Meta ou o UUID da Conta de canal (channelAccounts.list).
|
|
137
|
+
const ig = await boto.messages.send({
|
|
138
|
+
to: "17841400000000123",
|
|
139
|
+
text: "Tenho estes horários no sábado:",
|
|
140
|
+
// Opções de resposta: só Instagram, só com texto, até 13 (título ≤ 20).
|
|
141
|
+
quick_replies: [
|
|
142
|
+
{ title: "9h", payload: "sabado_09" },
|
|
143
|
+
{ title: "10h30", payload: "sabado_1030" },
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
ig.wamid; // null
|
|
147
|
+
ig.external_id; // "aWdEZ...mlk" (mid)
|
|
148
|
+
|
|
130
149
|
// Listar na ordem real das mensagens (histórico importado incluído)
|
|
131
150
|
const page = await boto.messages.list({ sort: "event_at", limit: 50 });
|
|
132
151
|
page.data[0]?.source; // "api" | "app" | "history" | "broadcast"
|
|
@@ -138,6 +157,104 @@ invalid_request`; reação recusa com `invalid_reaction`, `missing_reaction_targ
|
|
|
138
157
|
`reaction_target_not_found`, `reaction_target_invalid` ou `reaction_target_expired`.
|
|
139
158
|
O cursor de `messages.list` vale só para o `sort` que o gerou.
|
|
140
159
|
|
|
160
|
+
`quick_replies` só existe no Instagram e só com texto, dentro da janela de 24h:
|
|
161
|
+
no WhatsApp a API recusa com `channel_not_supported`; acima de 13 opções,
|
|
162
|
+
`too_many_quick_replies`; título acima de 20 caracteres,
|
|
163
|
+
`quick_reply_title_too_long`; fora da janela, `quick_replies_window_closed`.
|
|
164
|
+
No Instagram não existe `caption` em mídia (`unsupported_caption`).
|
|
165
|
+
|
|
166
|
+
### Botões e cards no Instagram
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
await boto.messages.sendInteractive({
|
|
170
|
+
to: "17841400000000123", from: contaInstagramId,
|
|
171
|
+
interactive: { type: "button", body: { text: "Como posso ajudar?" }, action: { buttons: [
|
|
172
|
+
{ type: "web_url", title: "Ver loja", url: "https://exemplo.com" },
|
|
173
|
+
{ type: "postback", title: "Horários", payload: "horarios" },
|
|
174
|
+
] } },
|
|
175
|
+
}, { idempotencyKey: chaveDaIntencao });
|
|
176
|
+
await boto.messages.sendInteractive({
|
|
177
|
+
to: "17841400000000123", from: contaInstagramId,
|
|
178
|
+
interactive: { type: "generic", elements: [{
|
|
179
|
+
title: "Produto", subtitle: "Disponível na loja",
|
|
180
|
+
image_url: "https://exemplo.com/foto.jpg",
|
|
181
|
+
default_action: { type: "web_url", url: "https://exemplo.com/produto" },
|
|
182
|
+
buttons: [{ type: "postback", title: "Quero saber mais", payload: "produto" }],
|
|
183
|
+
}] },
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`button` aceita 1–3 botões e texto até 640 caracteres; `generic` aceita 1–10
|
|
188
|
+
cards com título (até 80 caracteres) e ao menos uma propriedade adicional.
|
|
189
|
+
Subtítulo: até 80 caracteres; até 3 botões por card. Botões usam título de até
|
|
190
|
+
20 caracteres e postback de até 1000 caracteres; links são HTTPS. A API valida
|
|
191
|
+
os limites (`422`). `tag: "human_agent"` é opcional e depende da flag e da
|
|
192
|
+
janela autorizada pela API. O recibo traz `wamid: null`, `external_id`,
|
|
193
|
+
`channel: "instagram"` e `type: "interactive"`. Os formatos WhatsApp
|
|
194
|
+
`button` com `reply`, `list` e `cta_url` continuam disponíveis.
|
|
195
|
+
|
|
196
|
+
## Contas de canal e Regras de comentário
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
// Números do WhatsApp e Contas do Instagram lado a lado
|
|
200
|
+
const { data: contas } = await boto.channelAccounts.list({ channel: "instagram" });
|
|
201
|
+
const conta = await boto.channelAccounts.get(contas[0]!.id); // UUID ou id na Meta
|
|
202
|
+
// Saúde da conexão do Instagram (o token nunca é exposto)
|
|
203
|
+
conta.instagram?.token_status; // "ok" | "expiring" | "expired" | "invalid" | "revoked" | "unknown"
|
|
204
|
+
|
|
205
|
+
// Conversas de uma origem específica
|
|
206
|
+
await boto.conversations.list({ channel: "instagram", channel_account_id: conta.id });
|
|
207
|
+
|
|
208
|
+
// Regras de comentário (comment-rules:read / comment-rules:write)
|
|
209
|
+
const regra = await boto.channelAccounts.createCommentRule(conta.id, {
|
|
210
|
+
keyword: "preço",
|
|
211
|
+
dm_text: "Oi! Te mandei os valores por aqui.",
|
|
212
|
+
reply_text: "Te chamei no direct!",
|
|
213
|
+
});
|
|
214
|
+
await boto.channelAccounts.listCommentRules(conta.id);
|
|
215
|
+
await boto.channelAccounts.updateCommentRule(conta.id, regra.id, { is_active: false });
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`keyword` vazia vale para qualquer comentário e `media_id` vazio para todos os
|
|
219
|
+
posts. Criar ou ativar exige plano com Regras de comentário (`422
|
|
220
|
+
plan_restricted`); a mesma palavra-chave no mesmo alvo é `409 duplicate_rule`.
|
|
221
|
+
`deleteCommentRule(conta.id, regra.id)` exclui e retorna `{ id, deleted: true }`.
|
|
222
|
+
`keywords` (até 20 expressões), `excluded_keywords` (até 20 exclusões),
|
|
223
|
+
`reply_variations` (até 10 respostas públicas) e `next_post` estão disponíveis
|
|
224
|
+
na criação, leitura e atualização. `keywords` prevalece sobre `keyword`, e
|
|
225
|
+
`reply_variations` sobre `reply_text`; `[]` limpa a lista. `next_post: true`
|
|
226
|
+
aguarda o próximo post e não deve ser combinado com `media_id` explícito.
|
|
227
|
+
|
|
228
|
+
Com `token_status` `expired`, `invalid` ou `revoked`, os envios pela conta
|
|
229
|
+
falham até reconectá-la em Canais. Mensagens do Instagram editadas pelo contato
|
|
230
|
+
trazem o conteúdo atualizado com `content.edited` (`{ count, at }`); as apagadas,
|
|
231
|
+
`revoked_at`. Os Eventos `instagram.message.edited` e `instagram.message.revoked`
|
|
232
|
+
chegam pelo webhook e por `events.list`.
|
|
233
|
+
|
|
234
|
+
### Perguntas e menu do Instagram
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const perfil = await boto.channelAccounts.getMessengerProfile(conta.id);
|
|
238
|
+
await boto.channelAccounts.updateMessengerProfile(conta.id, {
|
|
239
|
+
ice_breakers: [{ question: "Quais os horários?", payload: "horarios" }],
|
|
240
|
+
persistent_menu: [{ type: "web_url", title: "Ver loja", url: "https://exemplo.com" }],
|
|
241
|
+
});
|
|
242
|
+
await boto.channelAccounts.updateMessengerProfile(conta.id, { ice_breakers: null });
|
|
243
|
+
await boto.channelAccounts.syncMessengerProfile(conta.id);
|
|
244
|
+
await boto.channelAccounts.deleteMessengerProfile(conta.id);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
GET usa `messenger-profile:read`; PATCH, DELETE e sync usam
|
|
248
|
+
`messenger-profile:write`. Sem sandbox. PATCH preserva seções ausentes;
|
|
249
|
+
`null` ou `[]` remove a seção. Até 4 perguntas e 5 itens de menu (`postback`
|
|
250
|
+
ou `web_url`). Perguntas: 80 caracteres; títulos: 20; payloads: 1000; URLs
|
|
251
|
+
http/https: 2000. Os quatro métodos retornam o snapshot com
|
|
252
|
+
`channel_account_id`, `config`, `revision`, `sync_status`, `synced_at`,
|
|
253
|
+
`last_error_code` e `updated_at`. GET lê o espelho salvo; sync verifica/reaplica
|
|
254
|
+
explicitamente o desejado. Falhas de aplicação conservam a configuração para
|
|
255
|
+
retry; `profile_busy` e `profile_sync_unconfirmed` pedem reconciliar após um
|
|
256
|
+
minuto. Sync sem configuração salva retorna `profile_not_configured`.
|
|
257
|
+
|
|
141
258
|
## Clientes e templates
|
|
142
259
|
|
|
143
260
|
```ts
|
|
@@ -215,8 +332,8 @@ if (page.paging.next) {
|
|
|
215
332
|
page = await boto.contacts.list({ limit: 50, after: page.paging.next });
|
|
216
333
|
}
|
|
217
334
|
|
|
218
|
-
// Offset/página (customers, templates, broadcasts, phoneNumbers,
|
|
219
|
-
// conversations.listAssignments): params { page, per_page }.
|
|
335
|
+
// Offset/página (customers, templates, broadcasts, phoneNumbers,
|
|
336
|
+
// channelAccounts, users, conversations.listAssignments): params { page, per_page }.
|
|
220
337
|
const { data, meta } = await boto.templates.list({ page: 2, per_page: 20 });
|
|
221
338
|
console.log(meta.total_count, meta.total_pages);
|
|
222
339
|
```
|
|
@@ -295,13 +412,14 @@ new BotoZap({
|
|
|
295
412
|
|
|
296
413
|
O SDK cobre os recursos da API `/v1`:
|
|
297
414
|
|
|
298
|
-
- `messages` — enviar texto, template e mídia por link, **listar** e buscar por id
|
|
415
|
+
- `messages` — enviar texto (com `quick_replies` no Instagram), template e mídia por link, **listar** e buscar por id
|
|
299
416
|
- `customers` — listar, buscar, criar, **atualizar**, **remover**, e **links de setup** (listar/criar/atualizar)
|
|
300
417
|
- `templates` — listar, buscar, **criar**
|
|
301
418
|
- `broadcasts` — criar, destinatários, agendar, enviar, cancelar
|
|
302
419
|
- `contacts` — listar, buscar, criar, atualizar, remover; `display_name` é o nome que a empresa dá ao Contato (1–200 caracteres; `null` limpa), separado do `profile_name` que vem do canal
|
|
303
|
-
- `conversations` — listar, buscar, atualizar, atribuições; leituras trazem `entry_point` (`ctwa`/`organic`/`null`), `referral` do último clique em anúncio Click-to-WhatsApp, `fep_expires_at` (fim da janela grátis informado pela Meta) e `fep_reply_by` (estimativa do prazo para responder)
|
|
420
|
+
- `conversations` — listar (filtros `channel` e `channel_account_id`), buscar, atualizar, responder, atribuições; leituras trazem `entry_point` (`ctwa`/`organic`/`null`), `referral` do último clique em anúncio Click-to-WhatsApp, `fep_expires_at` (fim da janela grátis informado pela Meta) e `fep_reply_by` (estimativa do prazo para responder)
|
|
304
421
|
- `webhooks` — CRUD e teste; `customer_id` opcional limita as entregas a um Cliente da Conta (`null` no update remove o filtro)
|
|
422
|
+
- `channelAccounts` — listar e buscar Contas de canal (WhatsApp e Instagram); **Regras de comentário** do Instagram (listar, buscar, criar, atualizar, excluir) e **Perguntas e menu** (ler, salvar/aplicar, remover, verificar/reaplicar)
|
|
305
423
|
- `phoneNumbers` — listar, buscar, **atualizar o `label`** (nome local, até 100 caracteres; `null` limpa), remover, saúde
|
|
306
424
|
- `media` — subir arquivo (obter um media_id) e **buscar metadados + URL de download** de uma mídia recebida
|
|
307
425
|
- `events` — reler inbound e mudanças de status pelo cursor durável da Conta/ambiente
|
|
@@ -502,3 +620,10 @@ nova intenção. `unknown` ou `accepted` exigem conciliação antes de considera
|
|
|
502
620
|
outro envio. SDK e MCP preservam `outcome` e `retry` da API. Resultados concluídos
|
|
503
621
|
vencidos são removidos pelo cron a cada minuto; claims incertas não são removidas
|
|
504
622
|
por tempo, conforme o runbook `botozap/docs/ops/message-send-receipts.md`.
|
|
623
|
+
|
|
624
|
+
## Instagram — onda 2
|
|
625
|
+
|
|
626
|
+
Regras de comentário incluem `dm_button_title`, `delivery_text` e `delivery_media`.
|
|
627
|
+
Regras de mensagem têm CRUD com gatilhos e ações tipados (`message-rules:read/write`);
|
|
628
|
+
métricas de comentário recebem `from`/`to` (`comment-rules:read`).
|
|
629
|
+
[Contrato e exemplos de SDK, CLI e MCP](../../docs/instagram-wave-two.md).
|
package/dist/index.cjs
CHANGED
|
@@ -53,6 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
BotoZap: () => BotoZap,
|
|
54
54
|
BotoZapError: () => BotoZapError,
|
|
55
55
|
Calendar: () => Calendar,
|
|
56
|
+
ChannelAccounts: () => ChannelAccounts,
|
|
56
57
|
ContactFields: () => ContactFields,
|
|
57
58
|
ContactStages: () => ContactStages,
|
|
58
59
|
CrmResource: () => CrmResource,
|
|
@@ -5168,7 +5169,8 @@ var Messages = class {
|
|
|
5168
5169
|
to: params.to,
|
|
5169
5170
|
type: "text",
|
|
5170
5171
|
text: { body: params.text },
|
|
5171
|
-
from: params.from
|
|
5172
|
+
from: params.from,
|
|
5173
|
+
...params.quick_replies !== void 0 ? { quick_replies: params.quick_replies } : {}
|
|
5172
5174
|
}
|
|
5173
5175
|
});
|
|
5174
5176
|
return assertSendResult(result);
|
|
@@ -5207,13 +5209,19 @@ var Messages = class {
|
|
|
5207
5209
|
return assertSendResult(result);
|
|
5208
5210
|
}
|
|
5209
5211
|
/**
|
|
5210
|
-
* Envia
|
|
5211
|
-
*
|
|
5212
|
+
* Envia button/list/cta_url no WhatsApp ou button/generic no Instagram.
|
|
5213
|
+
* Mensagem livre sujeita à janela do canal.
|
|
5212
5214
|
*/
|
|
5213
5215
|
async sendInteractive(params, options = {}) {
|
|
5214
5216
|
return postMessage(
|
|
5215
5217
|
this.client,
|
|
5216
|
-
{
|
|
5218
|
+
{
|
|
5219
|
+
to: params.to,
|
|
5220
|
+
from: params.from,
|
|
5221
|
+
type: "interactive",
|
|
5222
|
+
interactive: params.interactive,
|
|
5223
|
+
...params.tag !== void 0 ? { tag: params.tag } : {}
|
|
5224
|
+
},
|
|
5217
5225
|
options
|
|
5218
5226
|
);
|
|
5219
5227
|
}
|
|
@@ -5232,8 +5240,8 @@ var Messages = class {
|
|
|
5232
5240
|
);
|
|
5233
5241
|
}
|
|
5234
5242
|
/**
|
|
5235
|
-
* Reage a uma mensagem recebida (WhatsApp). `emoji: ""` retira
|
|
5236
|
-
* O retorno traz `reaction` com o alvo e a ação.
|
|
5243
|
+
* Reage a uma mensagem recebida (WhatsApp ou Instagram). `emoji: ""` retira
|
|
5244
|
+
* a reação. O retorno traz `reaction` com o alvo e a ação.
|
|
5237
5245
|
*/
|
|
5238
5246
|
async sendReaction(params, options = {}) {
|
|
5239
5247
|
return postMessage(
|
|
@@ -5280,10 +5288,12 @@ async function postMessage(client, body, options) {
|
|
|
5280
5288
|
return assertSendResult(result);
|
|
5281
5289
|
}
|
|
5282
5290
|
function assertSendResult(value) {
|
|
5283
|
-
|
|
5291
|
+
const hasWamid = typeof value?.wamid === "string";
|
|
5292
|
+
const hasExternalId = value?.wamid === null && typeof value.external_id === "string" && value.external_id !== "";
|
|
5293
|
+
if (!value || !(hasWamid || hasExternalId) || typeof value.to !== "string" || typeof value.status !== "string" || value.id !== null && typeof value.id !== "string") {
|
|
5284
5294
|
throw new BotoZapError(
|
|
5285
5295
|
"malformed_response",
|
|
5286
|
-
"resposta de envio sem id/wamid/to/status v\xE1lidos",
|
|
5296
|
+
"resposta de envio sem id/wamid (ou external_id)/to/status v\xE1lidos",
|
|
5287
5297
|
0
|
|
5288
5298
|
);
|
|
5289
5299
|
}
|
|
@@ -5555,7 +5565,9 @@ var Conversations = class {
|
|
|
5555
5565
|
phone_number_id: params.phone_number_id,
|
|
5556
5566
|
status: params.status,
|
|
5557
5567
|
contact: params.contact,
|
|
5558
|
-
phone_number: params.phone_number
|
|
5568
|
+
phone_number: params.phone_number,
|
|
5569
|
+
channel: params.channel,
|
|
5570
|
+
channel_account_id: params.channel_account_id
|
|
5559
5571
|
}
|
|
5560
5572
|
}
|
|
5561
5573
|
);
|
|
@@ -5567,17 +5579,19 @@ var Conversations = class {
|
|
|
5567
5579
|
);
|
|
5568
5580
|
}
|
|
5569
5581
|
/**
|
|
5570
|
-
* Responde uma Conversa sem o chamador precisar combinar Contato e
|
|
5571
|
-
*
|
|
5572
|
-
*
|
|
5582
|
+
* Responde uma Conversa sem o chamador precisar combinar Contato e origem.
|
|
5583
|
+
* No WhatsApp a origem é o Número da Conversa; no Instagram, a Conta de
|
|
5584
|
+
* canal (`channel_account.id`). A leitura e o envio usam a mesma chave; o
|
|
5585
|
+
* POST /messages revalida Conta, ambiente, identidade, janela, quota e
|
|
5586
|
+
* billing antes de chamar a Meta.
|
|
5573
5587
|
*/
|
|
5574
5588
|
async reply(id, params, options = {}) {
|
|
5575
5589
|
const conversation = await this.get(id);
|
|
5576
|
-
const from = conversation.phone_number_id;
|
|
5590
|
+
const from = conversation.channel === "instagram" ? conversation.channel_account?.id : conversation.phone_number_id;
|
|
5577
5591
|
if (typeof from !== "string" || !from.trim()) {
|
|
5578
5592
|
throw new BotoZapError(
|
|
5579
5593
|
"malformed_response",
|
|
5580
|
-
"Conversa sem UUID interno do N\xFAmero de origem.",
|
|
5594
|
+
conversation.channel === "instagram" ? "Conversa do Instagram sem UUID da Conta de canal de origem." : "Conversa sem UUID interno do N\xFAmero de origem.",
|
|
5581
5595
|
0
|
|
5582
5596
|
);
|
|
5583
5597
|
}
|
|
@@ -5590,7 +5604,15 @@ var Conversations = class {
|
|
|
5590
5604
|
422
|
|
5591
5605
|
);
|
|
5592
5606
|
}
|
|
5593
|
-
return this.client.messages.send(
|
|
5607
|
+
return this.client.messages.send(
|
|
5608
|
+
{
|
|
5609
|
+
to,
|
|
5610
|
+
text: params.text,
|
|
5611
|
+
from,
|
|
5612
|
+
...params.quick_replies !== void 0 ? { quick_replies: params.quick_replies } : {}
|
|
5613
|
+
},
|
|
5614
|
+
options
|
|
5615
|
+
);
|
|
5594
5616
|
}
|
|
5595
5617
|
update(id, params) {
|
|
5596
5618
|
return this.client.requestItem(
|
|
@@ -5732,6 +5754,135 @@ function enc6(id) {
|
|
|
5732
5754
|
return encodeURIComponent(id);
|
|
5733
5755
|
}
|
|
5734
5756
|
|
|
5757
|
+
// src/resources/channel-accounts.ts
|
|
5758
|
+
var ChannelAccounts = class {
|
|
5759
|
+
constructor(client) {
|
|
5760
|
+
this.client = client;
|
|
5761
|
+
}
|
|
5762
|
+
client;
|
|
5763
|
+
/** Lista as Contas de canal da conta (paginação por offset/página). numbers:read. */
|
|
5764
|
+
list(params = {}) {
|
|
5765
|
+
return this.client.requestOffsetList(
|
|
5766
|
+
"GET",
|
|
5767
|
+
"/channel_accounts",
|
|
5768
|
+
{
|
|
5769
|
+
query: {
|
|
5770
|
+
page: params.page,
|
|
5771
|
+
per_page: params.per_page,
|
|
5772
|
+
channel: params.channel,
|
|
5773
|
+
customer_id: params.customer_id
|
|
5774
|
+
}
|
|
5775
|
+
}
|
|
5776
|
+
);
|
|
5777
|
+
}
|
|
5778
|
+
/** Busca uma Conta de canal pelo UUID interno ou pelo id na Meta (`external_id`). numbers:read. */
|
|
5779
|
+
get(id) {
|
|
5780
|
+
return this.client.requestItem("GET", `/channel_accounts/${enc7(id)}`);
|
|
5781
|
+
}
|
|
5782
|
+
/** Lista as Regras de comentário de uma Conta do Instagram (UUID). comment-rules:read. */
|
|
5783
|
+
listCommentRules(channelAccountId, params = {}) {
|
|
5784
|
+
return this.client.requestOffsetList(
|
|
5785
|
+
"GET",
|
|
5786
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules`,
|
|
5787
|
+
{ query: { page: params.page, per_page: params.per_page } }
|
|
5788
|
+
);
|
|
5789
|
+
}
|
|
5790
|
+
/** Busca uma Regra de comentário. comment-rules:read. */
|
|
5791
|
+
getCommentRule(channelAccountId, ruleId) {
|
|
5792
|
+
return this.client.requestItem(
|
|
5793
|
+
"GET",
|
|
5794
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`
|
|
5795
|
+
);
|
|
5796
|
+
}
|
|
5797
|
+
/**
|
|
5798
|
+
* Cria uma Regra de comentário. comment-rules:write. Exige plano que inclua
|
|
5799
|
+
* Regras de comentário (senão 422 `plan_restricted`); palavra-chave repetida
|
|
5800
|
+
* para o mesmo alvo é 409 `duplicate_rule`.
|
|
5801
|
+
*/
|
|
5802
|
+
createCommentRule(channelAccountId, params) {
|
|
5803
|
+
return this.client.requestItem(
|
|
5804
|
+
"POST",
|
|
5805
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules`,
|
|
5806
|
+
{ body: params }
|
|
5807
|
+
);
|
|
5808
|
+
}
|
|
5809
|
+
/**
|
|
5810
|
+
* Altera uma Regra de comentário (só os campos enviados). comment-rules:write.
|
|
5811
|
+
* `is_active: false` desliga a regra.
|
|
5812
|
+
*/
|
|
5813
|
+
updateCommentRule(channelAccountId, ruleId, params) {
|
|
5814
|
+
return this.client.requestItem(
|
|
5815
|
+
"PATCH",
|
|
5816
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`,
|
|
5817
|
+
{ body: params }
|
|
5818
|
+
);
|
|
5819
|
+
}
|
|
5820
|
+
/** Exclui uma Regra de comentário. comment-rules:write. */
|
|
5821
|
+
deleteCommentRule(channelAccountId, ruleId) {
|
|
5822
|
+
return this.client.requestItem(
|
|
5823
|
+
"DELETE",
|
|
5824
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
/** Resultados da Regra por período e post. comment-rules:read. */
|
|
5828
|
+
getCommentRuleMetrics(channelAccountId, ruleId, params) {
|
|
5829
|
+
return this.client.requestItem(
|
|
5830
|
+
"GET",
|
|
5831
|
+
`/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}/metrics`,
|
|
5832
|
+
{ query: { from: params.from, to: params.to } }
|
|
5833
|
+
);
|
|
5834
|
+
}
|
|
5835
|
+
/** Lista Regras de mensagem com paginação offset. message-rules:read. */
|
|
5836
|
+
listMessageRules(channelAccountId, params = {}) {
|
|
5837
|
+
return this.client.requestOffsetList(
|
|
5838
|
+
"GET",
|
|
5839
|
+
messageRulesPath(channelAccountId),
|
|
5840
|
+
{ query: { page: params.page, per_page: params.per_page } }
|
|
5841
|
+
);
|
|
5842
|
+
}
|
|
5843
|
+
/** Busca uma Regra de mensagem. message-rules:read. */
|
|
5844
|
+
getMessageRule(channelAccountId, ruleId) {
|
|
5845
|
+
return this.client.requestItem("GET", messageRulesPath(channelAccountId, ruleId));
|
|
5846
|
+
}
|
|
5847
|
+
/** Cria uma Regra de mensagem. message-rules:write. */
|
|
5848
|
+
createMessageRule(channelAccountId, params) {
|
|
5849
|
+
return this.client.requestItem("POST", messageRulesPath(channelAccountId), { body: params });
|
|
5850
|
+
}
|
|
5851
|
+
/** PATCH parcial; a API valida o estado final. message-rules:write. */
|
|
5852
|
+
updateMessageRule(channelAccountId, ruleId, params) {
|
|
5853
|
+
return this.client.requestItem("PATCH", messageRulesPath(channelAccountId, ruleId), { body: params });
|
|
5854
|
+
}
|
|
5855
|
+
/** Exclui a Regra preservando Disparos e Eventos. message-rules:write. */
|
|
5856
|
+
deleteMessageRule(channelAccountId, ruleId) {
|
|
5857
|
+
return this.client.requestItem("DELETE", messageRulesPath(channelAccountId, ruleId));
|
|
5858
|
+
}
|
|
5859
|
+
/** Lê o espelho salvo (sem consultar a Meta). messenger-profile:read; sem sandbox. */
|
|
5860
|
+
getMessengerProfile(channelAccountId) {
|
|
5861
|
+
return this.client.requestItem("GET", profilePath(channelAccountId));
|
|
5862
|
+
}
|
|
5863
|
+
/** Salva/aplica apenas as seções enviadas. messenger-profile:write; sem sandbox. */
|
|
5864
|
+
updateMessengerProfile(channelAccountId, params) {
|
|
5865
|
+
return this.client.requestItem("PATCH", profilePath(channelAccountId), { body: params });
|
|
5866
|
+
}
|
|
5867
|
+
/** Remove perguntas e menu, conservando configuração vazia. messenger-profile:write. */
|
|
5868
|
+
deleteMessengerProfile(channelAccountId) {
|
|
5869
|
+
return this.client.requestItem("DELETE", profilePath(channelAccountId));
|
|
5870
|
+
}
|
|
5871
|
+
/** Verifica/reaplica explicitamente o desejado salvo. messenger-profile:write. */
|
|
5872
|
+
syncMessengerProfile(channelAccountId) {
|
|
5873
|
+
return this.client.requestItem("POST", `${profilePath(channelAccountId)}/sync`);
|
|
5874
|
+
}
|
|
5875
|
+
};
|
|
5876
|
+
function profilePath(id) {
|
|
5877
|
+
return `/channel_accounts/${enc7(id)}/messenger-profile`;
|
|
5878
|
+
}
|
|
5879
|
+
function enc7(id) {
|
|
5880
|
+
return encodeURIComponent(id);
|
|
5881
|
+
}
|
|
5882
|
+
function messageRulesPath(id, ruleId) {
|
|
5883
|
+
return `/channel_accounts/${enc7(id)}/message-rules${ruleId === void 0 ? "" : `/${enc7(ruleId)}`}`;
|
|
5884
|
+
}
|
|
5885
|
+
|
|
5735
5886
|
// src/resources/media.ts
|
|
5736
5887
|
var Media = class {
|
|
5737
5888
|
constructor(client) {
|
|
@@ -5890,6 +6041,8 @@ var BotoZap = class {
|
|
|
5890
6041
|
conversations;
|
|
5891
6042
|
webhooks;
|
|
5892
6043
|
phoneNumbers;
|
|
6044
|
+
/** Contas de canal (WhatsApp e Instagram) e Regras de comentário do Instagram. */
|
|
6045
|
+
channelAccounts;
|
|
5893
6046
|
contactStages;
|
|
5894
6047
|
contactFields;
|
|
5895
6048
|
calendar;
|
|
@@ -5943,6 +6096,7 @@ var BotoZap = class {
|
|
|
5943
6096
|
this.conversations = new Conversations(this);
|
|
5944
6097
|
this.webhooks = new Webhooks(this);
|
|
5945
6098
|
this.phoneNumbers = new PhoneNumbers(this);
|
|
6099
|
+
this.channelAccounts = new ChannelAccounts(this);
|
|
5946
6100
|
this.media = new Media(this);
|
|
5947
6101
|
this.events = new Events(this);
|
|
5948
6102
|
this.usage = new Usage(this);
|
|
@@ -6142,6 +6296,7 @@ var WEBHOOK_CATEGORIES = [
|
|
|
6142
6296
|
BotoZap,
|
|
6143
6297
|
BotoZapError,
|
|
6144
6298
|
Calendar,
|
|
6299
|
+
ChannelAccounts,
|
|
6145
6300
|
ContactFields,
|
|
6146
6301
|
ContactStages,
|
|
6147
6302
|
CrmResource,
|