@botozap/sdk 0.18.0 → 0.20.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 +56 -0
- package/README.md +122 -11
- package/dist/index.cjs +222 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +556 -31
- package/dist/index.d.ts +556 -31
- package/dist/index.js +217 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -56,7 +56,8 @@ var BotoZapError = class extends Error {
|
|
|
56
56
|
var PLAN_ERROR_CODES = [
|
|
57
57
|
"plan_restricted",
|
|
58
58
|
"free_form_limit_reached",
|
|
59
|
-
"free_number_cap"
|
|
59
|
+
"free_number_cap",
|
|
60
|
+
"free_cap"
|
|
60
61
|
];
|
|
61
62
|
function isPlanError(error) {
|
|
62
63
|
return error instanceof BotoZapError && PLAN_ERROR_CODES.includes(error.code);
|
|
@@ -64,6 +65,21 @@ function isPlanError(error) {
|
|
|
64
65
|
function isBusinessPaymentRequired(error) {
|
|
65
66
|
return error instanceof BotoZapError && error.code === "business_payment_required";
|
|
66
67
|
}
|
|
68
|
+
function isFreeCap(error) {
|
|
69
|
+
return error instanceof BotoZapError && error.code === "free_cap";
|
|
70
|
+
}
|
|
71
|
+
function isFreeNumberCap(error) {
|
|
72
|
+
return error instanceof BotoZapError && error.code === "free_number_cap";
|
|
73
|
+
}
|
|
74
|
+
function isConsentOptedOut(error) {
|
|
75
|
+
return error instanceof BotoZapError && error.code === "consent_opted_out";
|
|
76
|
+
}
|
|
77
|
+
function isConsentRevoked(error) {
|
|
78
|
+
return error instanceof BotoZapError && error.code === "consent_revoked";
|
|
79
|
+
}
|
|
80
|
+
function isNotConnected(error) {
|
|
81
|
+
return error instanceof BotoZapError && error.code === "not_connected";
|
|
82
|
+
}
|
|
67
83
|
|
|
68
84
|
// src/resources/ai/upload.ts
|
|
69
85
|
var receipts = /* @__PURE__ */ new WeakMap();
|
|
@@ -3952,7 +3968,7 @@ var AiCredentialsResource = class {
|
|
|
3952
3968
|
get(input) {
|
|
3953
3969
|
return request(this.client, AI_OPERATIONS[11], input);
|
|
3954
3970
|
}
|
|
3955
|
-
/** Cria credencial própria no Vault; a resposta nunca contém a chave. Só `AI_CREDENTIAL_PROVIDERS` (openai/anthropic); os demais: 422 `provider_not_enabled
|
|
3971
|
+
/** Cria credencial própria no Vault; a resposta nunca contém a chave. Só `AI_CREDENTIAL_PROVIDERS` (openai/anthropic); os demais: 422 `provider_not_enabled`, o mesmo erro de reativar (`update` com `active: true`), trocar a chave, `revalidate` e vincular um provedor descontinuado. */
|
|
3956
3972
|
create(input) {
|
|
3957
3973
|
return request(this.client, AI_OPERATIONS[12], input);
|
|
3958
3974
|
}
|
|
@@ -3974,7 +3990,12 @@ var AiProvidersResource = class {
|
|
|
3974
3990
|
this.client = client;
|
|
3975
3991
|
}
|
|
3976
3992
|
client;
|
|
3977
|
-
/**
|
|
3993
|
+
/**
|
|
3994
|
+
* GET /ai/providers. A lista `providers` traz só `openai` e `anthropic`;
|
|
3995
|
+
* `credentials` e `bindings` podem trazer, desativados, os de provedores
|
|
3996
|
+
* antigos. Salvar vínculo ou agente com provedor descontinuado: 422
|
|
3997
|
+
* `provider_not_enabled`.
|
|
3998
|
+
*/
|
|
3978
3999
|
get(input) {
|
|
3979
4000
|
return request(this.client, AI_OPERATIONS[16], input);
|
|
3980
4001
|
}
|
|
@@ -5117,7 +5138,8 @@ var Messages = class {
|
|
|
5117
5138
|
to: params.to,
|
|
5118
5139
|
type: "template",
|
|
5119
5140
|
template: params.template,
|
|
5120
|
-
from: params.from
|
|
5141
|
+
from: params.from,
|
|
5142
|
+
...params.consent_basis !== void 0 ? { consent_basis: params.consent_basis } : {}
|
|
5121
5143
|
}
|
|
5122
5144
|
});
|
|
5123
5145
|
return assertSendResult(result);
|
|
@@ -5253,13 +5275,20 @@ var Customers = class {
|
|
|
5253
5275
|
get(id) {
|
|
5254
5276
|
return this.client.requestItem("GET", `/customers/${enc(id)}`);
|
|
5255
5277
|
}
|
|
5256
|
-
/**
|
|
5278
|
+
/**
|
|
5279
|
+
* Cria um cliente. No plano Free, que permite 1 Cliente (com canal ou não), o
|
|
5280
|
+
* segundo responde 402 `free_cap` (veja `isFreeCap`).
|
|
5281
|
+
*/
|
|
5257
5282
|
create(params) {
|
|
5258
5283
|
return this.client.requestItem("POST", "/customers", {
|
|
5259
5284
|
body: params
|
|
5260
5285
|
});
|
|
5261
5286
|
}
|
|
5262
|
-
/**
|
|
5287
|
+
/**
|
|
5288
|
+
* Atualiza `name` / `external_customer_id` de um cliente e as Palavras de saída
|
|
5289
|
+
* e de volta com os textos de confirmação. Palavra repetida entre saída e volta
|
|
5290
|
+
* responde 422 `invalid_request`.
|
|
5291
|
+
*/
|
|
5263
5292
|
update(id, params) {
|
|
5264
5293
|
return this.client.requestItem("PATCH", `/customers/${enc(id)}`, {
|
|
5265
5294
|
body: params
|
|
@@ -5333,6 +5362,19 @@ var Templates = class {
|
|
|
5333
5362
|
body: params
|
|
5334
5363
|
});
|
|
5335
5364
|
}
|
|
5365
|
+
/**
|
|
5366
|
+
* Marca quais botões de resposta rápida são de saída (`opt_out_buttons`). O toque
|
|
5367
|
+
* num botão marcado grava a recusa da finalidade do template; botão não marcado
|
|
5368
|
+
* não muda nada, qualquer que seja o texto. Não altera o template na Meta.
|
|
5369
|
+
* Scope `templates:write`.
|
|
5370
|
+
*/
|
|
5371
|
+
update(id, params) {
|
|
5372
|
+
return this.client.requestItem(
|
|
5373
|
+
"PATCH",
|
|
5374
|
+
`/templates/${encodeURIComponent(id)}`,
|
|
5375
|
+
{ body: params }
|
|
5376
|
+
);
|
|
5377
|
+
}
|
|
5336
5378
|
};
|
|
5337
5379
|
|
|
5338
5380
|
// src/resources/broadcasts.ts
|
|
@@ -5453,6 +5495,12 @@ var Contacts = class {
|
|
|
5453
5495
|
get(id) {
|
|
5454
5496
|
return this.client.requestItem("GET", `/contacts/${enc3(id)}`);
|
|
5455
5497
|
}
|
|
5498
|
+
/**
|
|
5499
|
+
* Cria um contato. A resposta (201) pode trazer `warnings` por canal e
|
|
5500
|
+
* finalidade: `consent_opted_out` (o contato já recusou; o aceite pedido em
|
|
5501
|
+
* `consents` não foi gravado) ou `consent_unconfirmed` (não foi possível
|
|
5502
|
+
* confirmar o consentimento vigente).
|
|
5503
|
+
*/
|
|
5456
5504
|
create(params) {
|
|
5457
5505
|
return this.client.requestItem("POST", "/contacts", {
|
|
5458
5506
|
body: params
|
|
@@ -5463,10 +5511,38 @@ var Contacts = class {
|
|
|
5463
5511
|
body: params
|
|
5464
5512
|
});
|
|
5465
5513
|
}
|
|
5466
|
-
/**
|
|
5514
|
+
/**
|
|
5515
|
+
* Remove um contato e o que é dele (conversas, mensagens, CRM, compromissos e
|
|
5516
|
+
* Consentimentos); a mídia dele é apagada. A recusa não se perde: fica guardada
|
|
5517
|
+
* como código cifrado (hash) na lista de recusa da Conta e vale se o contato
|
|
5518
|
+
* voltar, que nasce como Recusou. Responde 204 (sem corpo).
|
|
5519
|
+
*/
|
|
5467
5520
|
delete(id) {
|
|
5468
5521
|
return this.client.request("DELETE", `/contacts/${enc3(id)}`);
|
|
5469
5522
|
}
|
|
5523
|
+
/**
|
|
5524
|
+
* Consentimentos do contato: `current` (o vigente por canal e finalidade) e
|
|
5525
|
+
* `history` (todos, do mais novo ao mais antigo). Scope `contacts:read`.
|
|
5526
|
+
*/
|
|
5527
|
+
listConsents(id) {
|
|
5528
|
+
return this.client.requestItem(
|
|
5529
|
+
"GET",
|
|
5530
|
+
`/contacts/${enc3(id)}/consents`
|
|
5531
|
+
);
|
|
5532
|
+
}
|
|
5533
|
+
/**
|
|
5534
|
+
* Registra um Consentimento do contato (origem `api`). Scope `contacts:write`.
|
|
5535
|
+
* Sobre uma recusa do próprio contato responde `409 consent_opted_out` e nada é
|
|
5536
|
+
* gravado: só ele volta a aceitar (botão do pedido de consentimento ou Palavra
|
|
5537
|
+
* de volta). Para recusar, registre `state: "revoked"`.
|
|
5538
|
+
*/
|
|
5539
|
+
recordConsent(id, params) {
|
|
5540
|
+
return this.client.requestItem(
|
|
5541
|
+
"POST",
|
|
5542
|
+
`/contacts/${enc3(id)}/consents`,
|
|
5543
|
+
{ body: params }
|
|
5544
|
+
);
|
|
5545
|
+
}
|
|
5470
5546
|
};
|
|
5471
5547
|
function enc3(id) {
|
|
5472
5548
|
return encodeURIComponent(id);
|
|
@@ -5551,6 +5627,39 @@ var Conversations = class {
|
|
|
5551
5627
|
options
|
|
5552
5628
|
);
|
|
5553
5629
|
}
|
|
5630
|
+
/**
|
|
5631
|
+
* Envia o pedido de consentimento na conversa (o "Pedir consentimento" do
|
|
5632
|
+
* composer): botões no WhatsApp, respostas rápidas no Instagram. Só com a
|
|
5633
|
+
* janela de 24h aberta, e sai também para quem recusou marketing: é o caminho
|
|
5634
|
+
* de volta. O toque do contato grava o aceite (origem `conversation_button`).
|
|
5635
|
+
* Scope `messages:send`. Responde 201 com o `channel` do envio; `warnings` com
|
|
5636
|
+
* `send_unrecorded` significa que a Meta aceitou e a gravação falhou: não
|
|
5637
|
+
* reenvie, o pedido já saiu.
|
|
5638
|
+
*
|
|
5639
|
+
* Recusas: `outside_window` (WhatsApp) ou `window_closed` (Instagram) com a
|
|
5640
|
+
* janela fechada, `channel_not_supported` (canal sem botões), `no_phone`,
|
|
5641
|
+
* `not_connected` (número desconectado ou sem token), `invalid_recipient`.
|
|
5642
|
+
* Não há chave de idempotência: não repita um pedido de resultado incerto sem
|
|
5643
|
+
* conferir o histórico da conversa.
|
|
5644
|
+
*/
|
|
5645
|
+
requestConsent(id, params = {}) {
|
|
5646
|
+
return this.client.requestItem(
|
|
5647
|
+
"POST",
|
|
5648
|
+
`/conversations/${enc4(id)}/consent-request`,
|
|
5649
|
+
{ body: params }
|
|
5650
|
+
);
|
|
5651
|
+
}
|
|
5652
|
+
/**
|
|
5653
|
+
* Exclui a conversa, com efeito imediato e sem volta: mensagens, notas,
|
|
5654
|
+
* atribuições, vínculos com oportunidades e demandas e o que a IA guardou
|
|
5655
|
+
* dela saem juntos, e os arquivos de mídia são apagados. O contato fica, com a
|
|
5656
|
+
* recusa e o consentimento. Só Administrador (por OAuth, papel de
|
|
5657
|
+
* administrador). Responde 204; id inexistente, de outra Conta ou já excluído
|
|
5658
|
+
* é 404. Scope `conversations:write`.
|
|
5659
|
+
*/
|
|
5660
|
+
delete(id) {
|
|
5661
|
+
return this.client.request("DELETE", `/conversations/${enc4(id)}`);
|
|
5662
|
+
}
|
|
5554
5663
|
update(id, params) {
|
|
5555
5664
|
return this.client.requestItem(
|
|
5556
5665
|
"PATCH",
|
|
@@ -5817,11 +5926,18 @@ var ChannelAccounts = class {
|
|
|
5817
5926
|
getMessageRule(channelAccountId, ruleId) {
|
|
5818
5927
|
return this.client.requestItem("GET", messageRulesPath(channelAccountId, ruleId));
|
|
5819
5928
|
}
|
|
5820
|
-
/**
|
|
5929
|
+
/**
|
|
5930
|
+
* Cria uma Regra de mensagem. message-rules:write. Fora do plano (Free)
|
|
5931
|
+
* responde 403 `plan_restricted`.
|
|
5932
|
+
*/
|
|
5821
5933
|
createMessageRule(channelAccountId, params) {
|
|
5822
5934
|
return this.client.requestItem("POST", messageRulesPath(channelAccountId), { body: params });
|
|
5823
5935
|
}
|
|
5824
|
-
/**
|
|
5936
|
+
/**
|
|
5937
|
+
* PATCH parcial; a API valida o estado final. message-rules:write. No Free,
|
|
5938
|
+
* só `{ is_active: false }` (pausar) passa; o resto responde 403
|
|
5939
|
+
* `plan_restricted`.
|
|
5940
|
+
*/
|
|
5825
5941
|
updateMessageRule(channelAccountId, ruleId, params) {
|
|
5826
5942
|
return this.client.requestItem("PATCH", messageRulesPath(channelAccountId, ruleId), { body: params });
|
|
5827
5943
|
}
|
|
@@ -5833,7 +5949,11 @@ var ChannelAccounts = class {
|
|
|
5833
5949
|
getMessengerProfile(channelAccountId) {
|
|
5834
5950
|
return this.client.requestItem("GET", profilePath(channelAccountId));
|
|
5835
5951
|
}
|
|
5836
|
-
/**
|
|
5952
|
+
/**
|
|
5953
|
+
* Salva/aplica apenas as seções enviadas. messenger-profile:write; sem
|
|
5954
|
+
* sandbox. No Free, só remover seções passa; salvar conteúdo responde 403
|
|
5955
|
+
* `plan_restricted`.
|
|
5956
|
+
*/
|
|
5837
5957
|
updateMessengerProfile(channelAccountId, params) {
|
|
5838
5958
|
return this.client.requestItem("PATCH", profilePath(channelAccountId), { body: params });
|
|
5839
5959
|
}
|
|
@@ -5841,7 +5961,11 @@ var ChannelAccounts = class {
|
|
|
5841
5961
|
deleteMessengerProfile(channelAccountId) {
|
|
5842
5962
|
return this.client.requestItem("DELETE", profilePath(channelAccountId));
|
|
5843
5963
|
}
|
|
5844
|
-
/**
|
|
5964
|
+
/**
|
|
5965
|
+
* Verifica/reaplica explicitamente o desejado salvo. messenger-profile:write.
|
|
5966
|
+
* No Free, reaplicar uma configuração com conteúdo responde 403
|
|
5967
|
+
* `plan_restricted`.
|
|
5968
|
+
*/
|
|
5845
5969
|
syncMessengerProfile(channelAccountId) {
|
|
5846
5970
|
return this.client.requestItem("POST", `${profilePath(channelAccountId)}/sync`);
|
|
5847
5971
|
}
|
|
@@ -5981,6 +6105,77 @@ var BillingResource = class {
|
|
|
5981
6105
|
}
|
|
5982
6106
|
};
|
|
5983
6107
|
|
|
6108
|
+
// src/resources/exports.ts
|
|
6109
|
+
var Exports = class {
|
|
6110
|
+
constructor(client) {
|
|
6111
|
+
this.client = client;
|
|
6112
|
+
}
|
|
6113
|
+
client;
|
|
6114
|
+
/**
|
|
6115
|
+
* Pede a exportação completa da Conta, ou de um Cliente (`customer_id`). Scope
|
|
6116
|
+
* `exports:write`. Responde 202 com o pedido novo; pedido igual enquanto o
|
|
6117
|
+
* anterior ainda está na fila devolve o mesmo (200). Funciona com a Conta em
|
|
6118
|
+
* somente leitura por exclusão: é o que se faz antes da exclusão começar. Cliente
|
|
6119
|
+
* inexistente é 404 `not_found`; exclusão já iniciada, 409
|
|
6120
|
+
* `account_deletion_in_progress`; muitos pedidos seguidos, 429 `rate_limited`.
|
|
6121
|
+
*/
|
|
6122
|
+
create(params = {}) {
|
|
6123
|
+
return this.client.requestItem("POST", "/exports", {
|
|
6124
|
+
body: params
|
|
6125
|
+
});
|
|
6126
|
+
}
|
|
6127
|
+
/**
|
|
6128
|
+
* Últimos pedidos da Conta (até 50), do mais novo ao mais antigo, sem o link de
|
|
6129
|
+
* download. Scope `exports:read`.
|
|
6130
|
+
*/
|
|
6131
|
+
list() {
|
|
6132
|
+
return this.client.requestItem("GET", "/exports");
|
|
6133
|
+
}
|
|
6134
|
+
/**
|
|
6135
|
+
* Estado de um pedido e, quando pronto e dentro do prazo, `download` com um
|
|
6136
|
+
* link assinado de poucos minutos: cada consulta gera um novo. Scope
|
|
6137
|
+
* `exports:read`. Pedido de outra Conta é 404 `not_found`.
|
|
6138
|
+
*/
|
|
6139
|
+
get(id) {
|
|
6140
|
+
return this.client.requestItem(
|
|
6141
|
+
"GET",
|
|
6142
|
+
`/exports/${encodeURIComponent(id)}`
|
|
6143
|
+
);
|
|
6144
|
+
}
|
|
6145
|
+
};
|
|
6146
|
+
|
|
6147
|
+
// src/resources/team-events.ts
|
|
6148
|
+
var TeamEvents = class {
|
|
6149
|
+
constructor(client) {
|
|
6150
|
+
this.client = client;
|
|
6151
|
+
}
|
|
6152
|
+
client;
|
|
6153
|
+
/**
|
|
6154
|
+
* Lista o registro (paginação por cursor). Scope `team:read`, e só
|
|
6155
|
+
* Administrador lê: a chave vale enquanto quem a criou seguir como
|
|
6156
|
+
* Administrador da Conta (senão 403 `admin_required`). Filtro inválido é 422.
|
|
6157
|
+
*/
|
|
6158
|
+
list(params = {}) {
|
|
6159
|
+
return this.client.requestCursorList(
|
|
6160
|
+
"GET",
|
|
6161
|
+
"/team_events",
|
|
6162
|
+
{
|
|
6163
|
+
query: {
|
|
6164
|
+
limit: params.limit,
|
|
6165
|
+
after: params.after,
|
|
6166
|
+
before: params.before,
|
|
6167
|
+
since: params.since,
|
|
6168
|
+
until: params.until,
|
|
6169
|
+
actor_id: params.actor_id,
|
|
6170
|
+
action: params.action,
|
|
6171
|
+
target_type: params.target_type,
|
|
6172
|
+
target_id: params.target_id
|
|
6173
|
+
}
|
|
6174
|
+
}
|
|
6175
|
+
);
|
|
6176
|
+
}
|
|
6177
|
+
};
|
|
6178
|
+
|
|
5984
6179
|
// src/resources/read-only.ts
|
|
5985
6180
|
var Users = class {
|
|
5986
6181
|
constructor(client) {
|
|
@@ -6076,6 +6271,10 @@ var BotoZap = class {
|
|
|
6076
6271
|
usage;
|
|
6077
6272
|
/** Plano da Conta e slots adicionais (só chave de API). */
|
|
6078
6273
|
billing;
|
|
6274
|
+
/** Exportação de dados da Conta (`/v1/exports`). */
|
|
6275
|
+
exports;
|
|
6276
|
+
/** Registro de atividades da equipe (`/v1/team_events`, só Administrador). */
|
|
6277
|
+
teamEvents;
|
|
6079
6278
|
users;
|
|
6080
6279
|
apiLogs;
|
|
6081
6280
|
webhookDeliveries;
|
|
@@ -6120,6 +6319,8 @@ var BotoZap = class {
|
|
|
6120
6319
|
this.events = new Events(this);
|
|
6121
6320
|
this.usage = new Usage(this);
|
|
6122
6321
|
this.billing = new BillingResource(this);
|
|
6322
|
+
this.exports = new Exports(this);
|
|
6323
|
+
this.teamEvents = new TeamEvents(this);
|
|
6123
6324
|
this.users = new Users(this);
|
|
6124
6325
|
this.apiLogs = new ApiLogs(this);
|
|
6125
6326
|
this.webhookDeliveries = new WebhookDeliveries(this);
|
|
@@ -6337,6 +6538,11 @@ export {
|
|
|
6337
6538
|
SavedReplies,
|
|
6338
6539
|
WEBHOOK_CATEGORIES,
|
|
6339
6540
|
isBusinessPaymentRequired,
|
|
6541
|
+
isConsentOptedOut,
|
|
6542
|
+
isConsentRevoked,
|
|
6543
|
+
isFreeCap,
|
|
6544
|
+
isFreeNumberCap,
|
|
6545
|
+
isNotConnected,
|
|
6340
6546
|
isPlanError
|
|
6341
6547
|
};
|
|
6342
6548
|
//# sourceMappingURL=index.js.map
|