@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/dist/index.js CHANGED
@@ -5100,7 +5100,8 @@ var Messages = class {
5100
5100
  to: params.to,
5101
5101
  type: "text",
5102
5102
  text: { body: params.text },
5103
- from: params.from
5103
+ from: params.from,
5104
+ ...params.quick_replies !== void 0 ? { quick_replies: params.quick_replies } : {}
5104
5105
  }
5105
5106
  });
5106
5107
  return assertSendResult(result);
@@ -5139,13 +5140,19 @@ var Messages = class {
5139
5140
  return assertSendResult(result);
5140
5141
  }
5141
5142
  /**
5142
- * Envia botões de resposta, lista ou botão de link (WhatsApp; mensagem livre,
5143
- * exige janela de 24h aberta).
5143
+ * Envia button/list/cta_url no WhatsApp ou button/generic no Instagram.
5144
+ * Mensagem livre sujeita à janela do canal.
5144
5145
  */
5145
5146
  async sendInteractive(params, options = {}) {
5146
5147
  return postMessage(
5147
5148
  this.client,
5148
- { to: params.to, from: params.from, type: "interactive", interactive: params.interactive },
5149
+ {
5150
+ to: params.to,
5151
+ from: params.from,
5152
+ type: "interactive",
5153
+ interactive: params.interactive,
5154
+ ...params.tag !== void 0 ? { tag: params.tag } : {}
5155
+ },
5149
5156
  options
5150
5157
  );
5151
5158
  }
@@ -5164,8 +5171,8 @@ var Messages = class {
5164
5171
  );
5165
5172
  }
5166
5173
  /**
5167
- * Reage a uma mensagem recebida (WhatsApp). `emoji: ""` retira a reação.
5168
- * O retorno traz `reaction` com o alvo e a ação.
5174
+ * Reage a uma mensagem recebida (WhatsApp ou Instagram). `emoji: ""` retira
5175
+ * a reação. O retorno traz `reaction` com o alvo e a ação.
5169
5176
  */
5170
5177
  async sendReaction(params, options = {}) {
5171
5178
  return postMessage(
@@ -5212,10 +5219,12 @@ async function postMessage(client, body, options) {
5212
5219
  return assertSendResult(result);
5213
5220
  }
5214
5221
  function assertSendResult(value) {
5215
- if (typeof value.wamid !== "string" || typeof value.to !== "string" || typeof value.status !== "string" || value.id !== null && typeof value.id !== "string") {
5222
+ const hasWamid = typeof value?.wamid === "string";
5223
+ const hasExternalId = value?.wamid === null && typeof value.external_id === "string" && value.external_id !== "";
5224
+ if (!value || !(hasWamid || hasExternalId) || typeof value.to !== "string" || typeof value.status !== "string" || value.id !== null && typeof value.id !== "string") {
5216
5225
  throw new BotoZapError(
5217
5226
  "malformed_response",
5218
- "resposta de envio sem id/wamid/to/status v\xE1lidos",
5227
+ "resposta de envio sem id/wamid (ou external_id)/to/status v\xE1lidos",
5219
5228
  0
5220
5229
  );
5221
5230
  }
@@ -5487,7 +5496,9 @@ var Conversations = class {
5487
5496
  phone_number_id: params.phone_number_id,
5488
5497
  status: params.status,
5489
5498
  contact: params.contact,
5490
- phone_number: params.phone_number
5499
+ phone_number: params.phone_number,
5500
+ channel: params.channel,
5501
+ channel_account_id: params.channel_account_id
5491
5502
  }
5492
5503
  }
5493
5504
  );
@@ -5499,17 +5510,19 @@ var Conversations = class {
5499
5510
  );
5500
5511
  }
5501
5512
  /**
5502
- * Responde uma Conversa sem o chamador precisar combinar Contato e Número.
5503
- * A leitura e o envio usam a mesma chave; o POST /messages revalida Conta,
5504
- * ambiente, identidade, janela, quota e billing antes de chamar a Meta.
5513
+ * Responde uma Conversa sem o chamador precisar combinar Contato e origem.
5514
+ * No WhatsApp a origem é o Número da Conversa; no Instagram, a Conta de
5515
+ * canal (`channel_account.id`). A leitura e o envio usam a mesma chave; o
5516
+ * POST /messages revalida Conta, ambiente, identidade, janela, quota e
5517
+ * billing antes de chamar a Meta.
5505
5518
  */
5506
5519
  async reply(id, params, options = {}) {
5507
5520
  const conversation = await this.get(id);
5508
- const from = conversation.phone_number_id;
5521
+ const from = conversation.channel === "instagram" ? conversation.channel_account?.id : conversation.phone_number_id;
5509
5522
  if (typeof from !== "string" || !from.trim()) {
5510
5523
  throw new BotoZapError(
5511
5524
  "malformed_response",
5512
- "Conversa sem UUID interno do N\xFAmero de origem.",
5525
+ conversation.channel === "instagram" ? "Conversa do Instagram sem UUID da Conta de canal de origem." : "Conversa sem UUID interno do N\xFAmero de origem.",
5513
5526
  0
5514
5527
  );
5515
5528
  }
@@ -5522,7 +5535,15 @@ var Conversations = class {
5522
5535
  422
5523
5536
  );
5524
5537
  }
5525
- return this.client.messages.send({ to, text: params.text, from }, options);
5538
+ return this.client.messages.send(
5539
+ {
5540
+ to,
5541
+ text: params.text,
5542
+ from,
5543
+ ...params.quick_replies !== void 0 ? { quick_replies: params.quick_replies } : {}
5544
+ },
5545
+ options
5546
+ );
5526
5547
  }
5527
5548
  update(id, params) {
5528
5549
  return this.client.requestItem(
@@ -5664,6 +5685,135 @@ function enc6(id) {
5664
5685
  return encodeURIComponent(id);
5665
5686
  }
5666
5687
 
5688
+ // src/resources/channel-accounts.ts
5689
+ var ChannelAccounts = class {
5690
+ constructor(client) {
5691
+ this.client = client;
5692
+ }
5693
+ client;
5694
+ /** Lista as Contas de canal da conta (paginação por offset/página). numbers:read. */
5695
+ list(params = {}) {
5696
+ return this.client.requestOffsetList(
5697
+ "GET",
5698
+ "/channel_accounts",
5699
+ {
5700
+ query: {
5701
+ page: params.page,
5702
+ per_page: params.per_page,
5703
+ channel: params.channel,
5704
+ customer_id: params.customer_id
5705
+ }
5706
+ }
5707
+ );
5708
+ }
5709
+ /** Busca uma Conta de canal pelo UUID interno ou pelo id na Meta (`external_id`). numbers:read. */
5710
+ get(id) {
5711
+ return this.client.requestItem("GET", `/channel_accounts/${enc7(id)}`);
5712
+ }
5713
+ /** Lista as Regras de comentário de uma Conta do Instagram (UUID). comment-rules:read. */
5714
+ listCommentRules(channelAccountId, params = {}) {
5715
+ return this.client.requestOffsetList(
5716
+ "GET",
5717
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules`,
5718
+ { query: { page: params.page, per_page: params.per_page } }
5719
+ );
5720
+ }
5721
+ /** Busca uma Regra de comentário. comment-rules:read. */
5722
+ getCommentRule(channelAccountId, ruleId) {
5723
+ return this.client.requestItem(
5724
+ "GET",
5725
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`
5726
+ );
5727
+ }
5728
+ /**
5729
+ * Cria uma Regra de comentário. comment-rules:write. Exige plano que inclua
5730
+ * Regras de comentário (senão 422 `plan_restricted`); palavra-chave repetida
5731
+ * para o mesmo alvo é 409 `duplicate_rule`.
5732
+ */
5733
+ createCommentRule(channelAccountId, params) {
5734
+ return this.client.requestItem(
5735
+ "POST",
5736
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules`,
5737
+ { body: params }
5738
+ );
5739
+ }
5740
+ /**
5741
+ * Altera uma Regra de comentário (só os campos enviados). comment-rules:write.
5742
+ * `is_active: false` desliga a regra.
5743
+ */
5744
+ updateCommentRule(channelAccountId, ruleId, params) {
5745
+ return this.client.requestItem(
5746
+ "PATCH",
5747
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`,
5748
+ { body: params }
5749
+ );
5750
+ }
5751
+ /** Exclui uma Regra de comentário. comment-rules:write. */
5752
+ deleteCommentRule(channelAccountId, ruleId) {
5753
+ return this.client.requestItem(
5754
+ "DELETE",
5755
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}`
5756
+ );
5757
+ }
5758
+ /** Resultados da Regra por período e post. comment-rules:read. */
5759
+ getCommentRuleMetrics(channelAccountId, ruleId, params) {
5760
+ return this.client.requestItem(
5761
+ "GET",
5762
+ `/channel_accounts/${enc7(channelAccountId)}/comment-rules/${enc7(ruleId)}/metrics`,
5763
+ { query: { from: params.from, to: params.to } }
5764
+ );
5765
+ }
5766
+ /** Lista Regras de mensagem com paginação offset. message-rules:read. */
5767
+ listMessageRules(channelAccountId, params = {}) {
5768
+ return this.client.requestOffsetList(
5769
+ "GET",
5770
+ messageRulesPath(channelAccountId),
5771
+ { query: { page: params.page, per_page: params.per_page } }
5772
+ );
5773
+ }
5774
+ /** Busca uma Regra de mensagem. message-rules:read. */
5775
+ getMessageRule(channelAccountId, ruleId) {
5776
+ return this.client.requestItem("GET", messageRulesPath(channelAccountId, ruleId));
5777
+ }
5778
+ /** Cria uma Regra de mensagem. message-rules:write. */
5779
+ createMessageRule(channelAccountId, params) {
5780
+ return this.client.requestItem("POST", messageRulesPath(channelAccountId), { body: params });
5781
+ }
5782
+ /** PATCH parcial; a API valida o estado final. message-rules:write. */
5783
+ updateMessageRule(channelAccountId, ruleId, params) {
5784
+ return this.client.requestItem("PATCH", messageRulesPath(channelAccountId, ruleId), { body: params });
5785
+ }
5786
+ /** Exclui a Regra preservando Disparos e Eventos. message-rules:write. */
5787
+ deleteMessageRule(channelAccountId, ruleId) {
5788
+ return this.client.requestItem("DELETE", messageRulesPath(channelAccountId, ruleId));
5789
+ }
5790
+ /** Lê o espelho salvo (sem consultar a Meta). messenger-profile:read; sem sandbox. */
5791
+ getMessengerProfile(channelAccountId) {
5792
+ return this.client.requestItem("GET", profilePath(channelAccountId));
5793
+ }
5794
+ /** Salva/aplica apenas as seções enviadas. messenger-profile:write; sem sandbox. */
5795
+ updateMessengerProfile(channelAccountId, params) {
5796
+ return this.client.requestItem("PATCH", profilePath(channelAccountId), { body: params });
5797
+ }
5798
+ /** Remove perguntas e menu, conservando configuração vazia. messenger-profile:write. */
5799
+ deleteMessengerProfile(channelAccountId) {
5800
+ return this.client.requestItem("DELETE", profilePath(channelAccountId));
5801
+ }
5802
+ /** Verifica/reaplica explicitamente o desejado salvo. messenger-profile:write. */
5803
+ syncMessengerProfile(channelAccountId) {
5804
+ return this.client.requestItem("POST", `${profilePath(channelAccountId)}/sync`);
5805
+ }
5806
+ };
5807
+ function profilePath(id) {
5808
+ return `/channel_accounts/${enc7(id)}/messenger-profile`;
5809
+ }
5810
+ function enc7(id) {
5811
+ return encodeURIComponent(id);
5812
+ }
5813
+ function messageRulesPath(id, ruleId) {
5814
+ return `/channel_accounts/${enc7(id)}/message-rules${ruleId === void 0 ? "" : `/${enc7(ruleId)}`}`;
5815
+ }
5816
+
5667
5817
  // src/resources/media.ts
5668
5818
  var Media = class {
5669
5819
  constructor(client) {
@@ -5822,6 +5972,8 @@ var BotoZap = class {
5822
5972
  conversations;
5823
5973
  webhooks;
5824
5974
  phoneNumbers;
5975
+ /** Contas de canal (WhatsApp e Instagram) e Regras de comentário do Instagram. */
5976
+ channelAccounts;
5825
5977
  contactStages;
5826
5978
  contactFields;
5827
5979
  calendar;
@@ -5875,6 +6027,7 @@ var BotoZap = class {
5875
6027
  this.conversations = new Conversations(this);
5876
6028
  this.webhooks = new Webhooks(this);
5877
6029
  this.phoneNumbers = new PhoneNumbers(this);
6030
+ this.channelAccounts = new ChannelAccounts(this);
5878
6031
  this.media = new Media(this);
5879
6032
  this.events = new Events(this);
5880
6033
  this.usage = new Usage(this);
@@ -6073,6 +6226,7 @@ export {
6073
6226
  BotoZap,
6074
6227
  BotoZapError,
6075
6228
  Calendar,
6229
+ ChannelAccounts,
6076
6230
  ContactFields,
6077
6231
  ContactStages,
6078
6232
  CrmResource,