@chatwise/node 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/CHANGELOG.md +19 -0
- package/LICENSE +202 -0
- package/README.md +592 -2
- package/dist/cjs/client.d.ts +20 -0
- package/dist/cjs/client.js +32 -0
- package/dist/cjs/core/errors.d.ts +101 -0
- package/dist/cjs/core/errors.js +143 -0
- package/dist/cjs/core/http.d.ts +87 -0
- package/dist/cjs/core/http.js +360 -0
- package/dist/cjs/core/pagination.d.ts +35 -0
- package/dist/cjs/core/pagination.js +101 -0
- package/dist/cjs/generated/types.d.ts +1017 -0
- package/dist/cjs/generated/types.js +3 -0
- package/dist/cjs/index.d.ts +15 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/conversations.d.ts +20 -0
- package/dist/cjs/resources/conversations.js +32 -0
- package/dist/cjs/resources/messages.d.ts +104 -0
- package/dist/cjs/resources/messages.js +112 -0
- package/dist/cjs/resources/webhook-deliveries.d.ts +27 -0
- package/dist/cjs/resources/webhook-deliveries.js +42 -0
- package/dist/cjs/resources/webhook-endpoints.d.ts +54 -0
- package/dist/cjs/resources/webhook-endpoints.js +82 -0
- package/dist/cjs/resources/webhook-event-types.d.ts +13 -0
- package/dist/cjs/resources/webhook-event-types.js +22 -0
- package/dist/cjs/resources/whatsapp-templates.d.ts +48 -0
- package/dist/cjs/resources/whatsapp-templates.js +71 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/webhooks.d.ts +74 -0
- package/dist/cjs/webhooks.js +123 -0
- package/dist/esm/client.d.ts +20 -0
- package/dist/esm/client.js +28 -0
- package/dist/esm/core/errors.d.ts +101 -0
- package/dist/esm/core/errors.js +124 -0
- package/dist/esm/core/http.d.ts +87 -0
- package/dist/esm/core/http.js +356 -0
- package/dist/esm/core/pagination.d.ts +35 -0
- package/dist/esm/core/pagination.js +95 -0
- package/dist/esm/generated/types.d.ts +1017 -0
- package/dist/esm/generated/types.js +2 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/resources/conversations.d.ts +20 -0
- package/dist/esm/resources/conversations.js +28 -0
- package/dist/esm/resources/messages.d.ts +104 -0
- package/dist/esm/resources/messages.js +108 -0
- package/dist/esm/resources/webhook-deliveries.d.ts +27 -0
- package/dist/esm/resources/webhook-deliveries.js +38 -0
- package/dist/esm/resources/webhook-endpoints.d.ts +54 -0
- package/dist/esm/resources/webhook-endpoints.js +78 -0
- package/dist/esm/resources/webhook-event-types.d.ts +13 -0
- package/dist/esm/resources/webhook-event-types.js +18 -0
- package/dist/esm/resources/whatsapp-templates.d.ts +48 -0
- package/dist/esm/resources/whatsapp-templates.js +67 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/webhooks.d.ts +74 -0
- package/dist/esm/webhooks.js +118 -0
- package/package.json +79 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { Chatwise } from './client.js';
|
|
2
|
+
export type { AbortSignalLike, ChatwiseOptions, FetchLike, RequestOptions, ResponseLike } from './core/http.js';
|
|
3
|
+
export type { Page, PagePromise } from './core/pagination.js';
|
|
4
|
+
export { APIError, AuthenticationError, BadRequestError, ChatwiseError, ConflictError, ConnectionError, NotFoundError, PayloadTooLargeError, PaymentRequiredError, PermissionDeniedError, RateLimitError, RequestAbortedError, RequestTimeoutError, ServerError, UnprocessableEntityError, } from './core/errors.js';
|
|
5
|
+
export type { APIErrorDetails, FieldError } from './core/errors.js';
|
|
6
|
+
export { verifyWebhook, WebhookVerificationError } from './webhooks.js';
|
|
7
|
+
export type { UnknownWebhookEvent, UnknownWebhookEventType, VerifyWebhookOptions, WebhookEvent, WebhookHeaders, WebhookVerificationErrorCode } from './webhooks.js';
|
|
8
|
+
export { VERSION } from './version.js';
|
|
9
|
+
export type { Conversations } from './resources/conversations.js';
|
|
10
|
+
export type { Messages, SendMessageParams, SendReplyOptions, SendReplyParams } from './resources/messages.js';
|
|
11
|
+
export type { WebhookDeliveries } from './resources/webhook-deliveries.js';
|
|
12
|
+
export type { WebhookEndpoints } from './resources/webhook-endpoints.js';
|
|
13
|
+
export type { WebhookEventTypes } from './resources/webhook-event-types.js';
|
|
14
|
+
export type { CreateWhatsappTemplateOptions, WhatsappTemplates } from './resources/whatsapp-templates.js';
|
|
15
|
+
export type { Channel, CommentReceivedEvent, CommentReceivedEventData, Conversation, ConversationStatus, CreateWebhookEndpointParams, CreateWhatsappTemplateParams, DeleteWebhookEndpointResult, KnownWebhookEvent, KnownWebhookEventType, ListConversationMessagesParams, ListConversationsParams, ListMessagesParams, ListWebhookDeliveriesParams, ListWhatsappTemplatesParams, Message, MessageDeliveredEvent, MessageDirection, MessageEventData, MessageFailedEvent, MessageFailedEventData, MessageFile, MessageReadEvent, MessageReceivedEvent, MessageSentEvent, Open, ReplyMedia, RotateWebhookSecretResult, SendMessageResult, SendReplyResult, SendWhatsappTemplateParams, SendWhatsappTemplateResult, TestWebhookEndpointResult, UpdateWebhookEndpointParams, WebhookDelivery, WebhookDeliveryDetails, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointStatus, WebhookEndpointWithSecret, WebhookEventType, WebhookEventTypeInfo, WebhookTestEvent, WebhookTestEventData, WhatsappTemplate, WhatsappTemplateCategory, WhatsappTemplateComponent, WhatsappTemplateParam, } from './generated/types.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Chatwise } from './client.js';
|
|
2
|
+
export { APIError, AuthenticationError, BadRequestError, ChatwiseError, ConflictError, ConnectionError, NotFoundError, PayloadTooLargeError, PaymentRequiredError, PermissionDeniedError, RateLimitError, RequestAbortedError, RequestTimeoutError, ServerError, UnprocessableEntityError, } from './core/errors.js';
|
|
3
|
+
export { verifyWebhook, WebhookVerificationError } from './webhooks.js';
|
|
4
|
+
export { VERSION } from './version.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import { type PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { Conversation, ListConversationsParams } from '../generated/types.js';
|
|
4
|
+
/** The conversations in the workspace's inbox. */
|
|
5
|
+
export declare class Conversations {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Lists conversations, or finds them by customer. The latest activity comes first. One that gets a
|
|
9
|
+
* message while you read the pages moves to the top, so you can miss it.
|
|
10
|
+
*
|
|
11
|
+
* Scope: `conversations:read`.
|
|
12
|
+
*/
|
|
13
|
+
list(params?: ListConversationsParams, options?: RequestOptions): PagePromise<Conversation>;
|
|
14
|
+
/**
|
|
15
|
+
* Reads one conversation: its channel, status and customer.
|
|
16
|
+
*
|
|
17
|
+
* Scope: `conversations:read`.
|
|
18
|
+
*/
|
|
19
|
+
get(conversationId: string, options?: RequestOptions): Promise<Conversation>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { path } from '../core/http.js';
|
|
2
|
+
import { list } from '../core/pagination.js';
|
|
3
|
+
/** The conversations in the workspace's inbox. */
|
|
4
|
+
export class Conversations {
|
|
5
|
+
#request;
|
|
6
|
+
/** @internal */
|
|
7
|
+
constructor(request) {
|
|
8
|
+
this.#request = request;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lists conversations, or finds them by customer. The latest activity comes first. One that gets a
|
|
12
|
+
* message while you read the pages moves to the top, so you can miss it.
|
|
13
|
+
*
|
|
14
|
+
* Scope: `conversations:read`.
|
|
15
|
+
*/
|
|
16
|
+
list(params = {}, options) {
|
|
17
|
+
return list(this.#request, () => '/v1/conversations', params, options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads one conversation: its channel, status and customer.
|
|
21
|
+
*
|
|
22
|
+
* Scope: `conversations:read`.
|
|
23
|
+
*/
|
|
24
|
+
async get(conversationId, options) {
|
|
25
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/conversations/${conversationId}` }, options);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import { type PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { ListConversationMessagesParams, ListMessagesParams, Message, MessageFile, ReplyMedia, SendMessageParams as SendMessageBody, SendMessageResult, SendReplyParams as SendReplyBody, SendReplyResult } from '../generated/types.js';
|
|
4
|
+
/** A template to send by id, and its values. */
|
|
5
|
+
export type SendMessageParams = Omit<SendMessageBody, 'channel' | 'templateId'> & {
|
|
6
|
+
/** The template's `id`. */
|
|
7
|
+
templateId: string;
|
|
8
|
+
/**
|
|
9
|
+
* The channel to send on. Only WhatsApp templates can be sent.
|
|
10
|
+
* @defaultValue 'WHATSAPP'
|
|
11
|
+
*/
|
|
12
|
+
channel?: 'WHATSAPP' | undefined;
|
|
13
|
+
};
|
|
14
|
+
/** What to reply: a text, or a file. Not both, because a reply is one message. */
|
|
15
|
+
export type SendReplyParams = Omit<SendReplyBody, 'text' | 'media'> & ({
|
|
16
|
+
/** The message. At most 4,096 characters on WhatsApp, 2,000 on Messenger, and 1,000 bytes of UTF-8 on Instagram. */
|
|
17
|
+
text: string;
|
|
18
|
+
media?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
/** A file to send, which Chatwise downloads from its address. On WhatsApp, Instagram and Messenger. */
|
|
21
|
+
media: ReplyMedia;
|
|
22
|
+
text?: undefined;
|
|
23
|
+
});
|
|
24
|
+
export interface SendReplyOptions extends RequestOptions {
|
|
25
|
+
/**
|
|
26
|
+
* A key you choose for this message, 8 to 128 letters, digits, dots, underscores, hyphens or colons. A new
|
|
27
|
+
* one for each message, and the same one, with the same conversation, content and API key, when you repeat
|
|
28
|
+
* the call: for 30 days a repeat doesn't send the message again. Make it from what you answer, such as an
|
|
29
|
+
* event's id. With another API key the same call sends another message.
|
|
30
|
+
*/
|
|
31
|
+
idempotencyKey: string;
|
|
32
|
+
/**
|
|
33
|
+
* How long to wait for a file that takes longer to prepare, in milliseconds. A request answered
|
|
34
|
+
* `MEDIA_PROCESSING` or `MEDIA_BUSY` is repeated as `Retry-After` says, if that is within this time after
|
|
35
|
+
* the call began. These don't count as retries, which start again from 0 after each.
|
|
36
|
+
* @defaultValue 600000, or 0 with `maxRetries: 0`
|
|
37
|
+
*/
|
|
38
|
+
mediaTimeoutMs?: number | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** Messages on every channel. */
|
|
41
|
+
export declare class Messages {
|
|
42
|
+
#private;
|
|
43
|
+
/**
|
|
44
|
+
* Lists messages across the workspace, or searches their text. Deleted and hidden messages are left out.
|
|
45
|
+
*
|
|
46
|
+
* Scope: `messages:read`.
|
|
47
|
+
*/
|
|
48
|
+
list(params?: ListMessagesParams, options?: RequestOptions): PagePromise<Message>;
|
|
49
|
+
/**
|
|
50
|
+
* Lists one conversation's messages. Deleted and hidden messages are left out.
|
|
51
|
+
*
|
|
52
|
+
* Scope: `messages:read`.
|
|
53
|
+
*/
|
|
54
|
+
listInConversation(conversationId: string, params?: ListConversationMessagesParams, options?: RequestOptions): PagePromise<Message>;
|
|
55
|
+
/**
|
|
56
|
+
* Reads one message. A deleted or hidden message is not found.
|
|
57
|
+
*
|
|
58
|
+
* Scope: `messages:read`.
|
|
59
|
+
*/
|
|
60
|
+
get(conversationId: string, messageId: string, options?: RequestOptions): Promise<Message>;
|
|
61
|
+
/**
|
|
62
|
+
* Lists a message's files, at most 20. One that is `available` has a `url` that works for 5 minutes,
|
|
63
|
+
* without an API key: don't send yours with it. List the files again for a new one.
|
|
64
|
+
*
|
|
65
|
+
* On WhatsApp, Instagram and Messenger. A file on Instagram or Messenger can be `pending` for a moment
|
|
66
|
+
* after the message arrives, and a story that a message replies to or mentions the account in isn't
|
|
67
|
+
* listed until it is copied.
|
|
68
|
+
*
|
|
69
|
+
* Scope: `messages:read`.
|
|
70
|
+
*/
|
|
71
|
+
listFiles(conversationId: string, messageId: string, options?: RequestOptions): Promise<MessageFile[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Replies in a WhatsApp, Instagram or Messenger conversation, with a text or a file. The answer means the
|
|
74
|
+
* channel accepted the message, not that it was delivered.
|
|
75
|
+
*
|
|
76
|
+
* The route recognizes a repeat by `idempotencyKey`, so this is retried like a read, and after
|
|
77
|
+
* `SEND_IN_PROGRESS`. If it still fails with one of these, with no answer, or with `MEDIA_PROCESSING`,
|
|
78
|
+
* `MEDIA_DOWNLOAD_FAILED` or `Invalid API key`, call it again later, with the same key, content and API
|
|
79
|
+
* key. Any other 4xx comes back until you fix what it names. A video on Messenger can take longer to send
|
|
80
|
+
* than the retries last: after `SEND_IN_PROGRESS`, call again within a minute, or you can miss that it was
|
|
81
|
+
* refused, and send it again.
|
|
82
|
+
*
|
|
83
|
+
* After `SEND_OUTCOME_UNKNOWN` a repeat sends nothing. The message may have been sent, also if the
|
|
84
|
+
* conversation doesn't show it, so let a person decide whether to send it again with a new key.
|
|
85
|
+
*
|
|
86
|
+
* An error is about the last request. If an earlier one got no answer, 401, 403, 404 and 429 don't say
|
|
87
|
+
* that nothing was sent, and with a file no error does while that one is still running. So don't go on with
|
|
88
|
+
* another `idempotencyKey` or API key.
|
|
89
|
+
*
|
|
90
|
+
* Scope: `messages:reply`.
|
|
91
|
+
*/
|
|
92
|
+
reply(conversationId: string, params: SendReplyParams, options: SendReplyOptions): Promise<SendReplyResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not
|
|
95
|
+
* that it was delivered. To send one by its name, use `whatsappTemplates.send`.
|
|
96
|
+
*
|
|
97
|
+
* Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
|
|
98
|
+
* (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
|
|
99
|
+
* doesn't show it, so check before you send again.
|
|
100
|
+
*
|
|
101
|
+
* Scope: `messages:send`.
|
|
102
|
+
*/
|
|
103
|
+
send(params: SendMessageParams, options?: RequestOptions): Promise<SendMessageResult>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ChatwiseError } from '../core/errors.js';
|
|
2
|
+
import { path } from '../core/http.js';
|
|
3
|
+
import { list } from '../core/pagination.js';
|
|
4
|
+
/** Messages on every channel. */
|
|
5
|
+
export class Messages {
|
|
6
|
+
#request;
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(request) {
|
|
9
|
+
this.#request = request;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Lists messages across the workspace, or searches their text. Deleted and hidden messages are left out.
|
|
13
|
+
*
|
|
14
|
+
* Scope: `messages:read`.
|
|
15
|
+
*/
|
|
16
|
+
list(params = {}, options) {
|
|
17
|
+
return list(this.#request, () => '/v1/messages', params, options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Lists one conversation's messages. Deleted and hidden messages are left out.
|
|
21
|
+
*
|
|
22
|
+
* Scope: `messages:read`.
|
|
23
|
+
*/
|
|
24
|
+
listInConversation(conversationId, params = {}, options) {
|
|
25
|
+
return list(this.#request, () => path `/v1/conversations/${conversationId}/messages`, params, options);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reads one message. A deleted or hidden message is not found.
|
|
29
|
+
*
|
|
30
|
+
* Scope: `messages:read`.
|
|
31
|
+
*/
|
|
32
|
+
async get(conversationId, messageId, options) {
|
|
33
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/conversations/${conversationId}/messages/${messageId}` }, options);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Lists a message's files, at most 20. One that is `available` has a `url` that works for 5 minutes,
|
|
38
|
+
* without an API key: don't send yours with it. List the files again for a new one.
|
|
39
|
+
*
|
|
40
|
+
* On WhatsApp, Instagram and Messenger. A file on Instagram or Messenger can be `pending` for a moment
|
|
41
|
+
* after the message arrives, and a story that a message replies to or mentions the account in isn't
|
|
42
|
+
* listed until it is copied.
|
|
43
|
+
*
|
|
44
|
+
* Scope: `messages:read`.
|
|
45
|
+
*/
|
|
46
|
+
async listFiles(conversationId, messageId, options) {
|
|
47
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/conversations/${conversationId}/messages/${messageId}/files` }, options);
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Replies in a WhatsApp, Instagram or Messenger conversation, with a text or a file. The answer means the
|
|
52
|
+
* channel accepted the message, not that it was delivered.
|
|
53
|
+
*
|
|
54
|
+
* The route recognizes a repeat by `idempotencyKey`, so this is retried like a read, and after
|
|
55
|
+
* `SEND_IN_PROGRESS`. If it still fails with one of these, with no answer, or with `MEDIA_PROCESSING`,
|
|
56
|
+
* `MEDIA_DOWNLOAD_FAILED` or `Invalid API key`, call it again later, with the same key, content and API
|
|
57
|
+
* key. Any other 4xx comes back until you fix what it names. A video on Messenger can take longer to send
|
|
58
|
+
* than the retries last: after `SEND_IN_PROGRESS`, call again within a minute, or you can miss that it was
|
|
59
|
+
* refused, and send it again.
|
|
60
|
+
*
|
|
61
|
+
* After `SEND_OUTCOME_UNKNOWN` a repeat sends nothing. The message may have been sent, also if the
|
|
62
|
+
* conversation doesn't show it, so let a person decide whether to send it again with a new key.
|
|
63
|
+
*
|
|
64
|
+
* An error is about the last request. If an earlier one got no answer, 401, 403, 404 and 429 don't say
|
|
65
|
+
* that nothing was sent, and with a file no error does while that one is still running. So don't go on with
|
|
66
|
+
* another `idempotencyKey` or API key.
|
|
67
|
+
*
|
|
68
|
+
* Scope: `messages:reply`.
|
|
69
|
+
*/
|
|
70
|
+
async reply(conversationId, params, options) {
|
|
71
|
+
const { idempotencyKey, mediaTimeoutMs, ...rest } = options ?? {};
|
|
72
|
+
// Without one the header would be "undefined", which is a key the API takes, and the same for every reply.
|
|
73
|
+
// Other characters can't be in a header. The rest is for the API to check.
|
|
74
|
+
if (typeof idempotencyKey !== 'string' || !/^[\x21-\x7e]+$/.test(idempotencyKey)) {
|
|
75
|
+
throw new ChatwiseError('messages.reply needs an idempotencyKey: 8 to 128 letters, digits, dots, underscores, hyphens or colons.');
|
|
76
|
+
}
|
|
77
|
+
const { data } = await this.#request({
|
|
78
|
+
method: 'POST',
|
|
79
|
+
path: path `/v1/conversations/${conversationId}/messages`,
|
|
80
|
+
body: params,
|
|
81
|
+
headers: { 'Idempotency-Key': idempotencyKey },
|
|
82
|
+
// Not after SEND_OUTCOME_UNKNOWN, which a repeat only answers again.
|
|
83
|
+
repeatAfter: ({ status, code }) => (status >= 500 ? code !== 'SEND_OUTCOME_UNKNOWN' : status === 409 && code === 'SEND_IN_PROGRESS'),
|
|
84
|
+
pending: { codes: ['MEDIA_PROCESSING', 'MEDIA_BUSY'], timeoutMs: mediaTimeoutMs },
|
|
85
|
+
}, rest);
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not
|
|
90
|
+
* that it was delivered. To send one by its name, use `whatsappTemplates.send`.
|
|
91
|
+
*
|
|
92
|
+
* Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
|
|
93
|
+
* (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
|
|
94
|
+
* doesn't show it, so check before you send again.
|
|
95
|
+
*
|
|
96
|
+
* Scope: `messages:send`.
|
|
97
|
+
*/
|
|
98
|
+
async send(params, options) {
|
|
99
|
+
const channel = params?.channel ?? 'WHATSAPP';
|
|
100
|
+
// The API answers 201 to these too, and sends nothing.
|
|
101
|
+
if (!params?.templateId)
|
|
102
|
+
throw new ChatwiseError('messages.send needs a templateId: without one nothing would be sent.');
|
|
103
|
+
if (channel !== 'WHATSAPP')
|
|
104
|
+
throw new ChatwiseError('messages.send can only send on WHATSAPP: on another channel nothing would be sent.');
|
|
105
|
+
const { data } = await this.#request({ method: 'POST', path: '/v1/messages', body: { ...params, channel } }, options);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import { type PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { ListWebhookDeliveriesParams, WebhookDelivery, WebhookDeliveryDetails } from '../generated/types.js';
|
|
4
|
+
/** What was sent to an endpoint. Deliveries are kept for 30 days. */
|
|
5
|
+
export declare class WebhookDeliveries {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Lists an endpoint's deliveries, newest first.
|
|
9
|
+
*
|
|
10
|
+
* Scope: `webhooks:read`.
|
|
11
|
+
*/
|
|
12
|
+
list(endpointId: string, params?: ListWebhookDeliveriesParams, options?: RequestOptions): PagePromise<WebhookDelivery>;
|
|
13
|
+
/**
|
|
14
|
+
* Reads one delivery, with the payload it sends and its attempts.
|
|
15
|
+
*
|
|
16
|
+
* Scope: `webhooks:read`, and `messages:read` if it is for a `message.*` event.
|
|
17
|
+
*/
|
|
18
|
+
get(deliveryId: string, options?: RequestOptions): Promise<WebhookDeliveryDetails>;
|
|
19
|
+
/**
|
|
20
|
+
* Sends a delivery again, with the same event id, starting from its first attempt. If Chatwise was
|
|
21
|
+
* waiting before it tries the endpoint again, the wait ends. A `BadRequestError` says that it can't be
|
|
22
|
+
* sent again: its message was unsent, deleted or hidden, or its comment hidden or no longer stored.
|
|
23
|
+
*
|
|
24
|
+
* Scope: `webhooks:write`, and `messages:read` if it is for a `message.*` event.
|
|
25
|
+
*/
|
|
26
|
+
redeliver(deliveryId: string, options?: RequestOptions): Promise<WebhookDeliveryDetails>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { path } from '../core/http.js';
|
|
2
|
+
import { list } from '../core/pagination.js';
|
|
3
|
+
/** What was sent to an endpoint. Deliveries are kept for 30 days. */
|
|
4
|
+
export class WebhookDeliveries {
|
|
5
|
+
#request;
|
|
6
|
+
/** @internal */
|
|
7
|
+
constructor(request) {
|
|
8
|
+
this.#request = request;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lists an endpoint's deliveries, newest first.
|
|
12
|
+
*
|
|
13
|
+
* Scope: `webhooks:read`.
|
|
14
|
+
*/
|
|
15
|
+
list(endpointId, params = {}, options) {
|
|
16
|
+
return list(this.#request, () => path `/v1/webhook-endpoints/${endpointId}/deliveries`, params, options);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads one delivery, with the payload it sends and its attempts.
|
|
20
|
+
*
|
|
21
|
+
* Scope: `webhooks:read`, and `messages:read` if it is for a `message.*` event.
|
|
22
|
+
*/
|
|
23
|
+
async get(deliveryId, options) {
|
|
24
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/webhook-deliveries/${deliveryId}` }, options);
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sends a delivery again, with the same event id, starting from its first attempt. If Chatwise was
|
|
29
|
+
* waiting before it tries the endpoint again, the wait ends. A `BadRequestError` says that it can't be
|
|
30
|
+
* sent again: its message was unsent, deleted or hidden, or its comment hidden or no longer stored.
|
|
31
|
+
*
|
|
32
|
+
* Scope: `webhooks:write`, and `messages:read` if it is for a `message.*` event.
|
|
33
|
+
*/
|
|
34
|
+
async redeliver(deliveryId, options) {
|
|
35
|
+
const { data } = await this.#request({ method: 'POST', path: path `/v1/webhook-deliveries/${deliveryId}/redeliver` }, options);
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import type { CreateWebhookEndpointParams, DeleteWebhookEndpointResult, RotateWebhookSecretResult, TestWebhookEndpointResult, UpdateWebhookEndpointParams, WebhookEndpoint, WebhookEndpointWithSecret } from '../generated/types.js';
|
|
3
|
+
/** Where Chatwise sends events. */
|
|
4
|
+
export declare class WebhookEndpoints {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Lists the workspace's webhook endpoints, oldest first. There are at most 10, so there are no pages.
|
|
8
|
+
*
|
|
9
|
+
* Scope: `webhooks:read`.
|
|
10
|
+
*/
|
|
11
|
+
list(options?: RequestOptions): Promise<WebhookEndpoint[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an endpoint. Store `signingSecret` right away: it is returned only here.
|
|
14
|
+
*
|
|
15
|
+
* Scope: `webhooks:write`, and `messages:read` to subscribe to `message.*` events.
|
|
16
|
+
*/
|
|
17
|
+
create(params: CreateWebhookEndpointParams, options?: RequestOptions): Promise<WebhookEndpointWithSecret>;
|
|
18
|
+
/**
|
|
19
|
+
* Reads one endpoint and how its deliveries are going.
|
|
20
|
+
*
|
|
21
|
+
* Scope: `webhooks:read`.
|
|
22
|
+
*/
|
|
23
|
+
get(endpointId: string, options?: RequestOptions): Promise<WebhookEndpoint>;
|
|
24
|
+
/**
|
|
25
|
+
* Changes an endpoint: only the fields you pass, at least one. `status: 'PAUSED'` stops new
|
|
26
|
+
* deliveries, and `status: 'ACTIVE'` resumes them, also after Chatwise disabled the endpoint. It clears
|
|
27
|
+
* the endpoint's failures and any wait (`health.backoffUntil`), and so does a new `url`, which also
|
|
28
|
+
* receives the deliveries that were already waiting.
|
|
29
|
+
*
|
|
30
|
+
* Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events before or after the change.
|
|
31
|
+
*/
|
|
32
|
+
update(endpointId: string, params: UpdateWebhookEndpointParams, options?: RequestOptions): Promise<WebhookEndpoint>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes an endpoint and cancels its deliveries that weren't sent yet.
|
|
35
|
+
*
|
|
36
|
+
* Scope: `webhooks:write`.
|
|
37
|
+
*/
|
|
38
|
+
delete(endpointId: string, options?: RequestOptions): Promise<DeleteWebhookEndpointResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Sends a signed `webhook.test` event now, also to a paused endpoint, and returns what your endpoint
|
|
41
|
+
* answered. Check `delivered`: this doesn't throw when your endpoint failed. If Chatwise is waiting
|
|
42
|
+
* before it tries the endpoint again (`health.backoffUntil`), a test that succeeds ends the wait.
|
|
43
|
+
*
|
|
44
|
+
* Scope: `webhooks:write`.
|
|
45
|
+
*/
|
|
46
|
+
test(endpointId: string, options?: RequestOptions): Promise<TestWebhookEndpointResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Replaces the signing secret. Store it right away: it is returned only here. For 24 hours deliveries
|
|
49
|
+
* are signed with the previous secret too.
|
|
50
|
+
*
|
|
51
|
+
* Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events.
|
|
52
|
+
*/
|
|
53
|
+
rotateSecret(endpointId: string, options?: RequestOptions): Promise<RotateWebhookSecretResult>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { path } from '../core/http.js';
|
|
2
|
+
/** Where Chatwise sends events. */
|
|
3
|
+
export class WebhookEndpoints {
|
|
4
|
+
#request;
|
|
5
|
+
/** @internal */
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.#request = request;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Lists the workspace's webhook endpoints, oldest first. There are at most 10, so there are no pages.
|
|
11
|
+
*
|
|
12
|
+
* Scope: `webhooks:read`.
|
|
13
|
+
*/
|
|
14
|
+
async list(options) {
|
|
15
|
+
const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-endpoints' }, options);
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates an endpoint. Store `signingSecret` right away: it is returned only here.
|
|
20
|
+
*
|
|
21
|
+
* Scope: `webhooks:write`, and `messages:read` to subscribe to `message.*` events.
|
|
22
|
+
*/
|
|
23
|
+
async create(params, options) {
|
|
24
|
+
const { data } = await this.#request({ method: 'POST', path: '/v1/webhook-endpoints', body: params }, options);
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reads one endpoint and how its deliveries are going.
|
|
29
|
+
*
|
|
30
|
+
* Scope: `webhooks:read`.
|
|
31
|
+
*/
|
|
32
|
+
async get(endpointId, options) {
|
|
33
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/webhook-endpoints/${endpointId}` }, options);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Changes an endpoint: only the fields you pass, at least one. `status: 'PAUSED'` stops new
|
|
38
|
+
* deliveries, and `status: 'ACTIVE'` resumes them, also after Chatwise disabled the endpoint. It clears
|
|
39
|
+
* the endpoint's failures and any wait (`health.backoffUntil`), and so does a new `url`, which also
|
|
40
|
+
* receives the deliveries that were already waiting.
|
|
41
|
+
*
|
|
42
|
+
* Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events before or after the change.
|
|
43
|
+
*/
|
|
44
|
+
async update(endpointId, params, options) {
|
|
45
|
+
const { data } = await this.#request({ method: 'PATCH', path: path `/v1/webhook-endpoints/${endpointId}`, body: params }, options);
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Deletes an endpoint and cancels its deliveries that weren't sent yet.
|
|
50
|
+
*
|
|
51
|
+
* Scope: `webhooks:write`.
|
|
52
|
+
*/
|
|
53
|
+
async delete(endpointId, options) {
|
|
54
|
+
const { data } = await this.#request({ method: 'DELETE', path: path `/v1/webhook-endpoints/${endpointId}` }, options);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sends a signed `webhook.test` event now, also to a paused endpoint, and returns what your endpoint
|
|
59
|
+
* answered. Check `delivered`: this doesn't throw when your endpoint failed. If Chatwise is waiting
|
|
60
|
+
* before it tries the endpoint again (`health.backoffUntil`), a test that succeeds ends the wait.
|
|
61
|
+
*
|
|
62
|
+
* Scope: `webhooks:write`.
|
|
63
|
+
*/
|
|
64
|
+
async test(endpointId, options) {
|
|
65
|
+
const { data } = await this.#request({ method: 'POST', path: path `/v1/webhook-endpoints/${endpointId}/test` }, options);
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Replaces the signing secret. Store it right away: it is returned only here. For 24 hours deliveries
|
|
70
|
+
* are signed with the previous secret too.
|
|
71
|
+
*
|
|
72
|
+
* Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events.
|
|
73
|
+
*/
|
|
74
|
+
async rotateSecret(endpointId, options) {
|
|
75
|
+
const { data } = await this.#request({ method: 'POST', path: path `/v1/webhook-endpoints/${endpointId}/rotate-secret` }, options);
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RequestOptions } from '../core/http.js';
|
|
2
|
+
import type { WebhookEventTypeInfo } from '../generated/types.js';
|
|
3
|
+
/** The events a webhook endpoint can subscribe to. */
|
|
4
|
+
export declare class WebhookEventTypes {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Lists the events an endpoint can subscribe to and the channels each covers. Some are listed before
|
|
8
|
+
* they are sent: today Chatwise sends only `message.received`.
|
|
9
|
+
*
|
|
10
|
+
* Scope: `webhooks:read`.
|
|
11
|
+
*/
|
|
12
|
+
list(options?: RequestOptions): Promise<WebhookEventTypeInfo[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The events a webhook endpoint can subscribe to. */
|
|
2
|
+
export class WebhookEventTypes {
|
|
3
|
+
#request;
|
|
4
|
+
/** @internal */
|
|
5
|
+
constructor(request) {
|
|
6
|
+
this.#request = request;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lists the events an endpoint can subscribe to and the channels each covers. Some are listed before
|
|
10
|
+
* they are sent: today Chatwise sends only `message.received`.
|
|
11
|
+
*
|
|
12
|
+
* Scope: `webhooks:read`.
|
|
13
|
+
*/
|
|
14
|
+
async list(options) {
|
|
15
|
+
const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-event-types' }, options);
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import { type PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { CreateWhatsappTemplateParams, ListWhatsappTemplatesParams, SendWhatsappTemplateParams, SendWhatsappTemplateResult, WhatsappTemplate } from '../generated/types.js';
|
|
4
|
+
export interface CreateWhatsappTemplateOptions extends RequestOptions {
|
|
5
|
+
/**
|
|
6
|
+
* A key you choose for this template, 1 to 128 letters, digits, dots, underscores, hyphens or colons.
|
|
7
|
+
* Use the same one, with the same template, when you repeat the call: you get the same template back.
|
|
8
|
+
* Without it, two identical submissions count as a repeat too.
|
|
9
|
+
*/
|
|
10
|
+
idempotencyKey?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** WhatsApp message templates. */
|
|
13
|
+
export declare class WhatsappTemplates {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Lists the workspace's WhatsApp templates, newest first, with the variables and buttons each takes.
|
|
17
|
+
*
|
|
18
|
+
* Scope: `templates:read`.
|
|
19
|
+
*/
|
|
20
|
+
list(params?: ListWhatsappTemplatesParams, options?: RequestOptions): PagePromise<WhatsappTemplate>;
|
|
21
|
+
/**
|
|
22
|
+
* Reads one WhatsApp template. After creating one, poll it until `status` is no longer `PENDING`.
|
|
23
|
+
* `sendable` then says whether it can be sent.
|
|
24
|
+
*
|
|
25
|
+
* Scope: `templates:read`.
|
|
26
|
+
*/
|
|
27
|
+
get(templateId: string, options?: RequestOptions): Promise<WhatsappTemplate>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a WhatsApp template and submits it to Meta for review. The route recognizes a repeat, by
|
|
30
|
+
* `idempotencyKey` or by the template itself, so this is retried like a read. Only an answer with a
|
|
31
|
+
* `code` isn't. `TEMPLATE_SUBMISSION_IN_PROGRESS`, which a retry can end with, and
|
|
32
|
+
* `TEMPLATE_SUBMISSION_UNCONFIRMED` mean to repeat the call later, with the same key and template.
|
|
33
|
+
*
|
|
34
|
+
* Scope: `templates:write`.
|
|
35
|
+
*/
|
|
36
|
+
create(params: CreateWhatsappTemplateParams, options?: CreateWhatsappTemplateOptions): Promise<WhatsappTemplate>;
|
|
37
|
+
/**
|
|
38
|
+
* Sends an approved WhatsApp template by its name. The answer means WhatsApp accepted the message,
|
|
39
|
+
* not that it was delivered. To send one by its id, use `messages.send`.
|
|
40
|
+
*
|
|
41
|
+
* Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
|
|
42
|
+
* (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
|
|
43
|
+
* doesn't show it, so check before you send again.
|
|
44
|
+
*
|
|
45
|
+
* Scope: `messages:send`.
|
|
46
|
+
*/
|
|
47
|
+
send(params: SendWhatsappTemplateParams, options?: RequestOptions): Promise<SendWhatsappTemplateResult>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ChatwiseError } from '../core/errors.js';
|
|
2
|
+
import { path } from '../core/http.js';
|
|
3
|
+
import { list } from '../core/pagination.js';
|
|
4
|
+
/** WhatsApp message templates. */
|
|
5
|
+
export class WhatsappTemplates {
|
|
6
|
+
#request;
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(request) {
|
|
9
|
+
this.#request = request;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Lists the workspace's WhatsApp templates, newest first, with the variables and buttons each takes.
|
|
13
|
+
*
|
|
14
|
+
* Scope: `templates:read`.
|
|
15
|
+
*/
|
|
16
|
+
list(params = {}, options) {
|
|
17
|
+
return list(this.#request, () => '/v1/whatsapp/templates', params, options);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads one WhatsApp template. After creating one, poll it until `status` is no longer `PENDING`.
|
|
21
|
+
* `sendable` then says whether it can be sent.
|
|
22
|
+
*
|
|
23
|
+
* Scope: `templates:read`.
|
|
24
|
+
*/
|
|
25
|
+
async get(templateId, options) {
|
|
26
|
+
const { data } = await this.#request({ method: 'GET', path: path `/v1/whatsapp/templates/${templateId}` }, options);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a WhatsApp template and submits it to Meta for review. The route recognizes a repeat, by
|
|
31
|
+
* `idempotencyKey` or by the template itself, so this is retried like a read. Only an answer with a
|
|
32
|
+
* `code` isn't. `TEMPLATE_SUBMISSION_IN_PROGRESS`, which a retry can end with, and
|
|
33
|
+
* `TEMPLATE_SUBMISSION_UNCONFIRMED` mean to repeat the call later, with the same key and template.
|
|
34
|
+
*
|
|
35
|
+
* Scope: `templates:write`.
|
|
36
|
+
*/
|
|
37
|
+
async create(params, options) {
|
|
38
|
+
const { idempotencyKey, ...rest } = options ?? {};
|
|
39
|
+
if (idempotencyKey !== undefined && !/^[\x21-\x7e]+$/.test(idempotencyKey)) {
|
|
40
|
+
throw new ChatwiseError('idempotencyKey must be 1 to 128 letters, digits, dots, underscores, hyphens or colons.');
|
|
41
|
+
}
|
|
42
|
+
const { data } = await this.#request({
|
|
43
|
+
method: 'POST',
|
|
44
|
+
path: '/v1/whatsapp/templates',
|
|
45
|
+
body: params,
|
|
46
|
+
headers: idempotencyKey === undefined ? undefined : { 'Idempotency-Key': idempotencyKey },
|
|
47
|
+
// An answer with a code says what to do about a template that was submitted, such as to wait for
|
|
48
|
+
// Meta. Asking again right away would only replace it with "already in progress".
|
|
49
|
+
repeatAfter: ({ status, code }) => status >= 500 && code === undefined,
|
|
50
|
+
}, rest);
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sends an approved WhatsApp template by its name. The answer means WhatsApp accepted the message,
|
|
55
|
+
* not that it was delivered. To send one by its id, use `messages.send`.
|
|
56
|
+
*
|
|
57
|
+
* Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
|
|
58
|
+
* (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
|
|
59
|
+
* doesn't show it, so check before you send again.
|
|
60
|
+
*
|
|
61
|
+
* Scope: `messages:send`.
|
|
62
|
+
*/
|
|
63
|
+
async send(params, options) {
|
|
64
|
+
const { data } = await this.#request({ method: 'POST', path: '/v1/template/whatsapp', body: params }, options);
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
}
|