@botozap/sdk 0.2.0 → 0.3.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/CHANGELOG.md +32 -0
- package/README.md +58 -5
- package/dist/index.cjs +63 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -2
- package/dist/index.d.ts +97 -2
- package/dist/index.js +63 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -9,6 +9,8 @@ interface SendResult {
|
|
|
9
9
|
id: string | null;
|
|
10
10
|
wamid: string;
|
|
11
11
|
to: string;
|
|
12
|
+
/** Destinatário efetivamente usado após normalização de telefone/BSUID. */
|
|
13
|
+
sent_to?: string;
|
|
12
14
|
status: MessageStatus;
|
|
13
15
|
/** Presente apenas quando a chave é do ambiente sandbox. */
|
|
14
16
|
sandbox?: boolean;
|
|
@@ -89,6 +91,14 @@ interface Contact {
|
|
|
89
91
|
}
|
|
90
92
|
interface Conversation {
|
|
91
93
|
id: string;
|
|
94
|
+
/** UUID interno do Número da própria Conversa. */
|
|
95
|
+
phone_number_id?: string;
|
|
96
|
+
contact?: {
|
|
97
|
+
/** Identidade canônica do Contato: telefone ou BSUID. */
|
|
98
|
+
wa_id?: string | null;
|
|
99
|
+
phone?: string | null;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
};
|
|
92
102
|
[key: string]: unknown;
|
|
93
103
|
}
|
|
94
104
|
interface Assignment {
|
|
@@ -125,6 +135,30 @@ interface WebhookDelivery {
|
|
|
125
135
|
id: string;
|
|
126
136
|
[key: string]: unknown;
|
|
127
137
|
}
|
|
138
|
+
/** Evento autoritativo do stream durável da Conta e ambiente autenticados. */
|
|
139
|
+
interface BotoZapEvent {
|
|
140
|
+
id: string;
|
|
141
|
+
/** Cursor monotônico e contíguo, serializado como string. */
|
|
142
|
+
cursor: string;
|
|
143
|
+
type: string;
|
|
144
|
+
/** WAMID da mensagem que originou o Evento. */
|
|
145
|
+
message_id: string;
|
|
146
|
+
/** UUID interno da Mensagem; pode ser null em status de Broadcast. */
|
|
147
|
+
message_resource_id: string | null;
|
|
148
|
+
occurred_at: string;
|
|
149
|
+
created_at: string;
|
|
150
|
+
data: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/** Paginação crescente do stream; `cursor` é seguro para o próximo `after`. */
|
|
153
|
+
interface EventPaging {
|
|
154
|
+
cursor: string;
|
|
155
|
+
next: string | null;
|
|
156
|
+
has_more: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface EventList {
|
|
159
|
+
data: BotoZapEvent[];
|
|
160
|
+
paging: EventPaging;
|
|
161
|
+
}
|
|
128
162
|
/**
|
|
129
163
|
* Retorno de POST /v1/media. A rota responde `{ ingest_id, target, resource }`:
|
|
130
164
|
* `target.kind` diz o pipeline usado (`meta_media` traz `media_id` usável em
|
|
@@ -212,14 +246,44 @@ interface SendTextParams {
|
|
|
212
246
|
to: string;
|
|
213
247
|
/** Corpo do texto. */
|
|
214
248
|
text: string;
|
|
215
|
-
/**
|
|
249
|
+
/** ID Meta ou UUID interno do Número de origem (obrigatório se houver mais de um). */
|
|
216
250
|
from?: string;
|
|
217
251
|
}
|
|
218
252
|
interface SendTemplateParams {
|
|
219
253
|
to: string;
|
|
220
254
|
template: TemplatePayload;
|
|
255
|
+
/** ID Meta ou UUID interno do Número de origem. */
|
|
221
256
|
from?: string;
|
|
222
257
|
}
|
|
258
|
+
interface SendImageParams {
|
|
259
|
+
to: string;
|
|
260
|
+
type: "image";
|
|
261
|
+
link: string;
|
|
262
|
+
caption?: string;
|
|
263
|
+
from?: string;
|
|
264
|
+
}
|
|
265
|
+
interface SendAudioParams {
|
|
266
|
+
to: string;
|
|
267
|
+
type: "audio";
|
|
268
|
+
link: string;
|
|
269
|
+
from?: string;
|
|
270
|
+
}
|
|
271
|
+
interface SendVideoParams {
|
|
272
|
+
to: string;
|
|
273
|
+
type: "video";
|
|
274
|
+
link: string;
|
|
275
|
+
caption?: string;
|
|
276
|
+
from?: string;
|
|
277
|
+
}
|
|
278
|
+
interface SendDocumentParams {
|
|
279
|
+
to: string;
|
|
280
|
+
type: "document";
|
|
281
|
+
link: string;
|
|
282
|
+
caption?: string;
|
|
283
|
+
filename?: string;
|
|
284
|
+
from?: string;
|
|
285
|
+
}
|
|
286
|
+
type SendMediaParams = SendImageParams | SendVideoParams | SendAudioParams | SendDocumentParams;
|
|
223
287
|
/** Endpoints de mensagem (POST /v1/messages, GET /v1/messages/:id). */
|
|
224
288
|
declare class Messages {
|
|
225
289
|
private readonly client;
|
|
@@ -228,6 +292,8 @@ declare class Messages {
|
|
|
228
292
|
send(params: SendTextParams): Promise<SendResult>;
|
|
229
293
|
/** Envia uma mensagem usando um template aprovado. */
|
|
230
294
|
sendTemplate(params: SendTemplateParams): Promise<SendResult>;
|
|
295
|
+
/** Envia mídia por URL pública. */
|
|
296
|
+
sendMedia(params: SendMediaParams): Promise<SendResult>;
|
|
231
297
|
/** Lista as mensagens da conta (paginação por cursor). */
|
|
232
298
|
list(params?: ListMessagesParams): Promise<CursorList<Message>>;
|
|
233
299
|
/** Busca uma mensagem pelo id interno. */
|
|
@@ -451,6 +517,10 @@ interface CreateAssignmentParams {
|
|
|
451
517
|
user_id: string;
|
|
452
518
|
notes?: string;
|
|
453
519
|
}
|
|
520
|
+
interface ReplyConversationParams {
|
|
521
|
+
/** Corpo da resposta livre dentro da janela de 24h. */
|
|
522
|
+
text: string;
|
|
523
|
+
}
|
|
454
524
|
/** Conversas (read + status) e atribuições a membros. */
|
|
455
525
|
declare class Conversations {
|
|
456
526
|
private readonly client;
|
|
@@ -458,6 +528,12 @@ declare class Conversations {
|
|
|
458
528
|
/** Lista as conversas da conta (paginação por cursor). */
|
|
459
529
|
list(params?: ListConversationsParams): Promise<CursorList<Conversation>>;
|
|
460
530
|
get(id: string): Promise<Conversation>;
|
|
531
|
+
/**
|
|
532
|
+
* Responde uma Conversa sem o chamador precisar combinar Contato e Número.
|
|
533
|
+
* A leitura e o envio usam a mesma chave; o POST /messages revalida Conta,
|
|
534
|
+
* ambiente, identidade, janela, quota e billing antes de chamar a Meta.
|
|
535
|
+
*/
|
|
536
|
+
reply(id: string, params: ReplyConversationParams): Promise<SendResult>;
|
|
461
537
|
update(id: string, params: Record<string, unknown>): Promise<Conversation>;
|
|
462
538
|
/** Lista as atribuições da conversa (paginação por offset/página). */
|
|
463
539
|
listAssignments(id: string, params?: OffsetParams): Promise<OffsetList<Assignment>>;
|
|
@@ -613,6 +689,22 @@ declare class Media {
|
|
|
613
689
|
get(id: string): Promise<MediaAsset>;
|
|
614
690
|
}
|
|
615
691
|
|
|
692
|
+
/** Posição exclusiva no stream durável de Eventos. */
|
|
693
|
+
interface ListEventsParams {
|
|
694
|
+
/** Cursor retornado pela leitura anterior; omita para começar em zero. */
|
|
695
|
+
after?: string;
|
|
696
|
+
/** Quantidade máxima de Eventos na página (1..100). */
|
|
697
|
+
limit?: number;
|
|
698
|
+
/** Cancela uma leitura/tail que deixou de ser necessário. */
|
|
699
|
+
signal?: AbortSignal;
|
|
700
|
+
}
|
|
701
|
+
/** Stream durável de Eventos da Conta e ambiente derivados da chave. */
|
|
702
|
+
declare class Events {
|
|
703
|
+
private readonly client;
|
|
704
|
+
constructor(client: BotoZap);
|
|
705
|
+
list(params?: ListEventsParams): Promise<EventList>;
|
|
706
|
+
}
|
|
707
|
+
|
|
616
708
|
/** Membros da conta (somente leitura via API). */
|
|
617
709
|
declare class Users {
|
|
618
710
|
private readonly client;
|
|
@@ -660,6 +752,8 @@ interface BotoZapOptions {
|
|
|
660
752
|
interface RequestOptions {
|
|
661
753
|
query?: Record<string, string | number | undefined>;
|
|
662
754
|
body?: unknown;
|
|
755
|
+
/** Cancela o I/O HTTP sem alterar o envelope de erro do SDK. */
|
|
756
|
+
signal?: AbortSignal;
|
|
663
757
|
}
|
|
664
758
|
/**
|
|
665
759
|
* Cliente da API da BotoZap.
|
|
@@ -680,6 +774,7 @@ declare class BotoZap {
|
|
|
680
774
|
readonly phoneNumbers: PhoneNumbers;
|
|
681
775
|
readonly flows: Flows;
|
|
682
776
|
readonly media: Media;
|
|
777
|
+
readonly events: Events;
|
|
683
778
|
readonly users: Users;
|
|
684
779
|
readonly apiLogs: ApiLogs;
|
|
685
780
|
readonly webhookDeliveries: WebhookDeliveries;
|
|
@@ -721,4 +816,4 @@ declare class BotoZapError extends Error {
|
|
|
721
816
|
constructor(code: string, message: string, status: number, headers?: Record<string, string>);
|
|
722
817
|
}
|
|
723
818
|
|
|
724
|
-
export { type AddRecipientsResult, type ApiLog, type Assignment, BotoZap, BotoZapError, type BotoZapOptions, type Broadcast, type BroadcastRecipient, type Contact, type Conversation, type CreateAssignmentParams, type CreateBroadcastParams, type CreateContactParams, type CreateCustomerParams, type CreateFlowParams, type CreateFlowVersionParams, type CreateSetupLinkParams, type CreateTemplateParams, type CreateWebhookParams, type CursorList, type CursorPaging, type CursorParams, type Customer, type Flow, type FlowPhoneParams, type FlowVersion, type ListApiLogsParams, type ListBroadcastsParams, type ListContactsParams, type ListConversationsParams, type ListFlowsParams, type ListMessagesParams, type ListPhoneNumbersParams, type ListRecipientsParams, type ListTemplatesParams, type ListWebhookDeliveriesParams, type MediaAsset, type MediaUploadResult, type Message, type MessageStatus, type OffsetList, type OffsetMeta, type OffsetParams, type PhoneNumber, type RequestOptions, type ScheduleBroadcastParams, type SendResult, type SendTemplateParams, type SendTextParams, type SetFlowDataEndpointParams, type SetupLink, type Template, type TemplatePayload, type UpdateBroadcastParams, type UpdateCustomerParams, type UpdateSetupLinkParams, type UploadMediaParams, type User, type Webhook, type WebhookDelivery };
|
|
819
|
+
export { type AddRecipientsResult, type ApiLog, type Assignment, BotoZap, BotoZapError, type BotoZapEvent, type BotoZapOptions, type Broadcast, type BroadcastRecipient, type Contact, type Conversation, type CreateAssignmentParams, type CreateBroadcastParams, type CreateContactParams, type CreateCustomerParams, type CreateFlowParams, type CreateFlowVersionParams, type CreateSetupLinkParams, type CreateTemplateParams, type CreateWebhookParams, type CursorList, type CursorPaging, type CursorParams, type Customer, type EventList, type EventPaging, type Flow, type FlowPhoneParams, type FlowVersion, type ListApiLogsParams, type ListBroadcastsParams, type ListContactsParams, type ListConversationsParams, type ListEventsParams, type ListFlowsParams, type ListMessagesParams, type ListPhoneNumbersParams, type ListRecipientsParams, type ListTemplatesParams, type ListWebhookDeliveriesParams, type MediaAsset, type MediaUploadResult, type Message, type MessageStatus, type OffsetList, type OffsetMeta, type OffsetParams, type PhoneNumber, type ReplyConversationParams, type RequestOptions, type ScheduleBroadcastParams, type SendAudioParams, type SendDocumentParams, type SendImageParams, type SendMediaParams, type SendResult, type SendTemplateParams, type SendTextParams, type SendVideoParams, type SetFlowDataEndpointParams, type SetupLink, type Template, type TemplatePayload, type UpdateBroadcastParams, type UpdateCustomerParams, type UpdateSetupLinkParams, type UploadMediaParams, type User, type Webhook, type WebhookDelivery };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface SendResult {
|
|
|
9
9
|
id: string | null;
|
|
10
10
|
wamid: string;
|
|
11
11
|
to: string;
|
|
12
|
+
/** Destinatário efetivamente usado após normalização de telefone/BSUID. */
|
|
13
|
+
sent_to?: string;
|
|
12
14
|
status: MessageStatus;
|
|
13
15
|
/** Presente apenas quando a chave é do ambiente sandbox. */
|
|
14
16
|
sandbox?: boolean;
|
|
@@ -89,6 +91,14 @@ interface Contact {
|
|
|
89
91
|
}
|
|
90
92
|
interface Conversation {
|
|
91
93
|
id: string;
|
|
94
|
+
/** UUID interno do Número da própria Conversa. */
|
|
95
|
+
phone_number_id?: string;
|
|
96
|
+
contact?: {
|
|
97
|
+
/** Identidade canônica do Contato: telefone ou BSUID. */
|
|
98
|
+
wa_id?: string | null;
|
|
99
|
+
phone?: string | null;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
};
|
|
92
102
|
[key: string]: unknown;
|
|
93
103
|
}
|
|
94
104
|
interface Assignment {
|
|
@@ -125,6 +135,30 @@ interface WebhookDelivery {
|
|
|
125
135
|
id: string;
|
|
126
136
|
[key: string]: unknown;
|
|
127
137
|
}
|
|
138
|
+
/** Evento autoritativo do stream durável da Conta e ambiente autenticados. */
|
|
139
|
+
interface BotoZapEvent {
|
|
140
|
+
id: string;
|
|
141
|
+
/** Cursor monotônico e contíguo, serializado como string. */
|
|
142
|
+
cursor: string;
|
|
143
|
+
type: string;
|
|
144
|
+
/** WAMID da mensagem que originou o Evento. */
|
|
145
|
+
message_id: string;
|
|
146
|
+
/** UUID interno da Mensagem; pode ser null em status de Broadcast. */
|
|
147
|
+
message_resource_id: string | null;
|
|
148
|
+
occurred_at: string;
|
|
149
|
+
created_at: string;
|
|
150
|
+
data: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/** Paginação crescente do stream; `cursor` é seguro para o próximo `after`. */
|
|
153
|
+
interface EventPaging {
|
|
154
|
+
cursor: string;
|
|
155
|
+
next: string | null;
|
|
156
|
+
has_more: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface EventList {
|
|
159
|
+
data: BotoZapEvent[];
|
|
160
|
+
paging: EventPaging;
|
|
161
|
+
}
|
|
128
162
|
/**
|
|
129
163
|
* Retorno de POST /v1/media. A rota responde `{ ingest_id, target, resource }`:
|
|
130
164
|
* `target.kind` diz o pipeline usado (`meta_media` traz `media_id` usável em
|
|
@@ -212,14 +246,44 @@ interface SendTextParams {
|
|
|
212
246
|
to: string;
|
|
213
247
|
/** Corpo do texto. */
|
|
214
248
|
text: string;
|
|
215
|
-
/**
|
|
249
|
+
/** ID Meta ou UUID interno do Número de origem (obrigatório se houver mais de um). */
|
|
216
250
|
from?: string;
|
|
217
251
|
}
|
|
218
252
|
interface SendTemplateParams {
|
|
219
253
|
to: string;
|
|
220
254
|
template: TemplatePayload;
|
|
255
|
+
/** ID Meta ou UUID interno do Número de origem. */
|
|
221
256
|
from?: string;
|
|
222
257
|
}
|
|
258
|
+
interface SendImageParams {
|
|
259
|
+
to: string;
|
|
260
|
+
type: "image";
|
|
261
|
+
link: string;
|
|
262
|
+
caption?: string;
|
|
263
|
+
from?: string;
|
|
264
|
+
}
|
|
265
|
+
interface SendAudioParams {
|
|
266
|
+
to: string;
|
|
267
|
+
type: "audio";
|
|
268
|
+
link: string;
|
|
269
|
+
from?: string;
|
|
270
|
+
}
|
|
271
|
+
interface SendVideoParams {
|
|
272
|
+
to: string;
|
|
273
|
+
type: "video";
|
|
274
|
+
link: string;
|
|
275
|
+
caption?: string;
|
|
276
|
+
from?: string;
|
|
277
|
+
}
|
|
278
|
+
interface SendDocumentParams {
|
|
279
|
+
to: string;
|
|
280
|
+
type: "document";
|
|
281
|
+
link: string;
|
|
282
|
+
caption?: string;
|
|
283
|
+
filename?: string;
|
|
284
|
+
from?: string;
|
|
285
|
+
}
|
|
286
|
+
type SendMediaParams = SendImageParams | SendVideoParams | SendAudioParams | SendDocumentParams;
|
|
223
287
|
/** Endpoints de mensagem (POST /v1/messages, GET /v1/messages/:id). */
|
|
224
288
|
declare class Messages {
|
|
225
289
|
private readonly client;
|
|
@@ -228,6 +292,8 @@ declare class Messages {
|
|
|
228
292
|
send(params: SendTextParams): Promise<SendResult>;
|
|
229
293
|
/** Envia uma mensagem usando um template aprovado. */
|
|
230
294
|
sendTemplate(params: SendTemplateParams): Promise<SendResult>;
|
|
295
|
+
/** Envia mídia por URL pública. */
|
|
296
|
+
sendMedia(params: SendMediaParams): Promise<SendResult>;
|
|
231
297
|
/** Lista as mensagens da conta (paginação por cursor). */
|
|
232
298
|
list(params?: ListMessagesParams): Promise<CursorList<Message>>;
|
|
233
299
|
/** Busca uma mensagem pelo id interno. */
|
|
@@ -451,6 +517,10 @@ interface CreateAssignmentParams {
|
|
|
451
517
|
user_id: string;
|
|
452
518
|
notes?: string;
|
|
453
519
|
}
|
|
520
|
+
interface ReplyConversationParams {
|
|
521
|
+
/** Corpo da resposta livre dentro da janela de 24h. */
|
|
522
|
+
text: string;
|
|
523
|
+
}
|
|
454
524
|
/** Conversas (read + status) e atribuições a membros. */
|
|
455
525
|
declare class Conversations {
|
|
456
526
|
private readonly client;
|
|
@@ -458,6 +528,12 @@ declare class Conversations {
|
|
|
458
528
|
/** Lista as conversas da conta (paginação por cursor). */
|
|
459
529
|
list(params?: ListConversationsParams): Promise<CursorList<Conversation>>;
|
|
460
530
|
get(id: string): Promise<Conversation>;
|
|
531
|
+
/**
|
|
532
|
+
* Responde uma Conversa sem o chamador precisar combinar Contato e Número.
|
|
533
|
+
* A leitura e o envio usam a mesma chave; o POST /messages revalida Conta,
|
|
534
|
+
* ambiente, identidade, janela, quota e billing antes de chamar a Meta.
|
|
535
|
+
*/
|
|
536
|
+
reply(id: string, params: ReplyConversationParams): Promise<SendResult>;
|
|
461
537
|
update(id: string, params: Record<string, unknown>): Promise<Conversation>;
|
|
462
538
|
/** Lista as atribuições da conversa (paginação por offset/página). */
|
|
463
539
|
listAssignments(id: string, params?: OffsetParams): Promise<OffsetList<Assignment>>;
|
|
@@ -613,6 +689,22 @@ declare class Media {
|
|
|
613
689
|
get(id: string): Promise<MediaAsset>;
|
|
614
690
|
}
|
|
615
691
|
|
|
692
|
+
/** Posição exclusiva no stream durável de Eventos. */
|
|
693
|
+
interface ListEventsParams {
|
|
694
|
+
/** Cursor retornado pela leitura anterior; omita para começar em zero. */
|
|
695
|
+
after?: string;
|
|
696
|
+
/** Quantidade máxima de Eventos na página (1..100). */
|
|
697
|
+
limit?: number;
|
|
698
|
+
/** Cancela uma leitura/tail que deixou de ser necessário. */
|
|
699
|
+
signal?: AbortSignal;
|
|
700
|
+
}
|
|
701
|
+
/** Stream durável de Eventos da Conta e ambiente derivados da chave. */
|
|
702
|
+
declare class Events {
|
|
703
|
+
private readonly client;
|
|
704
|
+
constructor(client: BotoZap);
|
|
705
|
+
list(params?: ListEventsParams): Promise<EventList>;
|
|
706
|
+
}
|
|
707
|
+
|
|
616
708
|
/** Membros da conta (somente leitura via API). */
|
|
617
709
|
declare class Users {
|
|
618
710
|
private readonly client;
|
|
@@ -660,6 +752,8 @@ interface BotoZapOptions {
|
|
|
660
752
|
interface RequestOptions {
|
|
661
753
|
query?: Record<string, string | number | undefined>;
|
|
662
754
|
body?: unknown;
|
|
755
|
+
/** Cancela o I/O HTTP sem alterar o envelope de erro do SDK. */
|
|
756
|
+
signal?: AbortSignal;
|
|
663
757
|
}
|
|
664
758
|
/**
|
|
665
759
|
* Cliente da API da BotoZap.
|
|
@@ -680,6 +774,7 @@ declare class BotoZap {
|
|
|
680
774
|
readonly phoneNumbers: PhoneNumbers;
|
|
681
775
|
readonly flows: Flows;
|
|
682
776
|
readonly media: Media;
|
|
777
|
+
readonly events: Events;
|
|
683
778
|
readonly users: Users;
|
|
684
779
|
readonly apiLogs: ApiLogs;
|
|
685
780
|
readonly webhookDeliveries: WebhookDeliveries;
|
|
@@ -721,4 +816,4 @@ declare class BotoZapError extends Error {
|
|
|
721
816
|
constructor(code: string, message: string, status: number, headers?: Record<string, string>);
|
|
722
817
|
}
|
|
723
818
|
|
|
724
|
-
export { type AddRecipientsResult, type ApiLog, type Assignment, BotoZap, BotoZapError, type BotoZapOptions, type Broadcast, type BroadcastRecipient, type Contact, type Conversation, type CreateAssignmentParams, type CreateBroadcastParams, type CreateContactParams, type CreateCustomerParams, type CreateFlowParams, type CreateFlowVersionParams, type CreateSetupLinkParams, type CreateTemplateParams, type CreateWebhookParams, type CursorList, type CursorPaging, type CursorParams, type Customer, type Flow, type FlowPhoneParams, type FlowVersion, type ListApiLogsParams, type ListBroadcastsParams, type ListContactsParams, type ListConversationsParams, type ListFlowsParams, type ListMessagesParams, type ListPhoneNumbersParams, type ListRecipientsParams, type ListTemplatesParams, type ListWebhookDeliveriesParams, type MediaAsset, type MediaUploadResult, type Message, type MessageStatus, type OffsetList, type OffsetMeta, type OffsetParams, type PhoneNumber, type RequestOptions, type ScheduleBroadcastParams, type SendResult, type SendTemplateParams, type SendTextParams, type SetFlowDataEndpointParams, type SetupLink, type Template, type TemplatePayload, type UpdateBroadcastParams, type UpdateCustomerParams, type UpdateSetupLinkParams, type UploadMediaParams, type User, type Webhook, type WebhookDelivery };
|
|
819
|
+
export { type AddRecipientsResult, type ApiLog, type Assignment, BotoZap, BotoZapError, type BotoZapEvent, type BotoZapOptions, type Broadcast, type BroadcastRecipient, type Contact, type Conversation, type CreateAssignmentParams, type CreateBroadcastParams, type CreateContactParams, type CreateCustomerParams, type CreateFlowParams, type CreateFlowVersionParams, type CreateSetupLinkParams, type CreateTemplateParams, type CreateWebhookParams, type CursorList, type CursorPaging, type CursorParams, type Customer, type EventList, type EventPaging, type Flow, type FlowPhoneParams, type FlowVersion, type ListApiLogsParams, type ListBroadcastsParams, type ListContactsParams, type ListConversationsParams, type ListEventsParams, type ListFlowsParams, type ListMessagesParams, type ListPhoneNumbersParams, type ListRecipientsParams, type ListTemplatesParams, type ListWebhookDeliveriesParams, type MediaAsset, type MediaUploadResult, type Message, type MessageStatus, type OffsetList, type OffsetMeta, type OffsetParams, type PhoneNumber, type ReplyConversationParams, type RequestOptions, type ScheduleBroadcastParams, type SendAudioParams, type SendDocumentParams, type SendImageParams, type SendMediaParams, type SendResult, type SendTemplateParams, type SendTextParams, type SendVideoParams, type SetFlowDataEndpointParams, type SetupLink, type Template, type TemplatePayload, type UpdateBroadcastParams, type UpdateCustomerParams, type UpdateSetupLinkParams, type UploadMediaParams, type User, type Webhook, type WebhookDelivery };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,25 @@ var Messages = class {
|
|
|
43
43
|
});
|
|
44
44
|
return assertSendResult(result);
|
|
45
45
|
}
|
|
46
|
+
/** Envia mídia por URL pública. */
|
|
47
|
+
async sendMedia(params) {
|
|
48
|
+
const media = { link: params.link };
|
|
49
|
+
if ("caption" in params && params.caption !== void 0) {
|
|
50
|
+
media.caption = params.caption;
|
|
51
|
+
}
|
|
52
|
+
if ("filename" in params && params.filename !== void 0) {
|
|
53
|
+
media.filename = params.filename;
|
|
54
|
+
}
|
|
55
|
+
const result = await this.client.requestObject("POST", "/messages", {
|
|
56
|
+
body: {
|
|
57
|
+
to: params.to,
|
|
58
|
+
from: params.from,
|
|
59
|
+
type: params.type,
|
|
60
|
+
[params.type]: media
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return assertSendResult(result);
|
|
64
|
+
}
|
|
46
65
|
/** Lista as mensagens da conta (paginação por cursor). */
|
|
47
66
|
list(params = {}) {
|
|
48
67
|
return this.client.requestCursorList("GET", "/messages", {
|
|
@@ -334,6 +353,32 @@ var Conversations = class {
|
|
|
334
353
|
`/conversations/${enc4(id)}`
|
|
335
354
|
);
|
|
336
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Responde uma Conversa sem o chamador precisar combinar Contato e Número.
|
|
358
|
+
* A leitura e o envio usam a mesma chave; o POST /messages revalida Conta,
|
|
359
|
+
* ambiente, identidade, janela, quota e billing antes de chamar a Meta.
|
|
360
|
+
*/
|
|
361
|
+
async reply(id, params) {
|
|
362
|
+
const conversation = await this.get(id);
|
|
363
|
+
const from = conversation.phone_number_id;
|
|
364
|
+
if (typeof from !== "string" || !from.trim()) {
|
|
365
|
+
throw new BotoZapError(
|
|
366
|
+
"malformed_response",
|
|
367
|
+
"Conversa sem UUID interno do N\xFAmero de origem.",
|
|
368
|
+
0
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
const contact = conversation.contact;
|
|
372
|
+
const to = typeof contact?.wa_id === "string" && contact.wa_id.trim() ? contact.wa_id : typeof contact?.phone === "string" && contact.phone.trim() ? contact.phone : null;
|
|
373
|
+
if (!to) {
|
|
374
|
+
throw new BotoZapError(
|
|
375
|
+
"conversation_recipient_unavailable",
|
|
376
|
+
"Conversa sem destinat\xE1rio utiliz\xE1vel no Contato.",
|
|
377
|
+
422
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
return this.client.messages.send({ to, text: params.text, from });
|
|
381
|
+
}
|
|
337
382
|
update(id, params) {
|
|
338
383
|
return this.client.requestItem(
|
|
339
384
|
"PATCH",
|
|
@@ -589,6 +634,20 @@ var Media = class {
|
|
|
589
634
|
}
|
|
590
635
|
};
|
|
591
636
|
|
|
637
|
+
// src/resources/events.ts
|
|
638
|
+
var Events = class {
|
|
639
|
+
constructor(client) {
|
|
640
|
+
this.client = client;
|
|
641
|
+
}
|
|
642
|
+
client;
|
|
643
|
+
list(params = {}) {
|
|
644
|
+
return this.client.requestCursorList("GET", "/events", {
|
|
645
|
+
query: { after: params.after, limit: params.limit },
|
|
646
|
+
signal: params.signal
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
592
651
|
// src/resources/read-only.ts
|
|
593
652
|
var Users = class {
|
|
594
653
|
constructor(client) {
|
|
@@ -656,6 +715,7 @@ var BotoZap = class {
|
|
|
656
715
|
phoneNumbers;
|
|
657
716
|
flows;
|
|
658
717
|
media;
|
|
718
|
+
events;
|
|
659
719
|
users;
|
|
660
720
|
apiLogs;
|
|
661
721
|
webhookDeliveries;
|
|
@@ -685,6 +745,7 @@ var BotoZap = class {
|
|
|
685
745
|
this.phoneNumbers = new PhoneNumbers(this);
|
|
686
746
|
this.flows = new Flows(this);
|
|
687
747
|
this.media = new Media(this);
|
|
748
|
+
this.events = new Events(this);
|
|
688
749
|
this.users = new Users(this);
|
|
689
750
|
this.apiLogs = new ApiLogs(this);
|
|
690
751
|
this.webhookDeliveries = new WebhookDeliveries(this);
|
|
@@ -706,7 +767,8 @@ var BotoZap = class {
|
|
|
706
767
|
"Content-Type": "application/json",
|
|
707
768
|
Accept: "application/json"
|
|
708
769
|
},
|
|
709
|
-
body: opts.body === void 0 ? void 0 : JSON.stringify(opts.body)
|
|
770
|
+
body: opts.body === void 0 ? void 0 : JSON.stringify(opts.body),
|
|
771
|
+
signal: opts.signal
|
|
710
772
|
});
|
|
711
773
|
} catch (cause) {
|
|
712
774
|
const detail = cause instanceof Error ? cause.message : String(cause);
|