@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.
Files changed (62) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +202 -0
  3. package/README.md +592 -2
  4. package/dist/cjs/client.d.ts +20 -0
  5. package/dist/cjs/client.js +32 -0
  6. package/dist/cjs/core/errors.d.ts +101 -0
  7. package/dist/cjs/core/errors.js +143 -0
  8. package/dist/cjs/core/http.d.ts +87 -0
  9. package/dist/cjs/core/http.js +360 -0
  10. package/dist/cjs/core/pagination.d.ts +35 -0
  11. package/dist/cjs/core/pagination.js +101 -0
  12. package/dist/cjs/generated/types.d.ts +1017 -0
  13. package/dist/cjs/generated/types.js +3 -0
  14. package/dist/cjs/index.d.ts +15 -0
  15. package/dist/cjs/index.js +26 -0
  16. package/dist/cjs/package.json +1 -0
  17. package/dist/cjs/resources/conversations.d.ts +20 -0
  18. package/dist/cjs/resources/conversations.js +32 -0
  19. package/dist/cjs/resources/messages.d.ts +104 -0
  20. package/dist/cjs/resources/messages.js +112 -0
  21. package/dist/cjs/resources/webhook-deliveries.d.ts +27 -0
  22. package/dist/cjs/resources/webhook-deliveries.js +42 -0
  23. package/dist/cjs/resources/webhook-endpoints.d.ts +54 -0
  24. package/dist/cjs/resources/webhook-endpoints.js +82 -0
  25. package/dist/cjs/resources/webhook-event-types.d.ts +13 -0
  26. package/dist/cjs/resources/webhook-event-types.js +22 -0
  27. package/dist/cjs/resources/whatsapp-templates.d.ts +48 -0
  28. package/dist/cjs/resources/whatsapp-templates.js +71 -0
  29. package/dist/cjs/version.d.ts +2 -0
  30. package/dist/cjs/version.js +5 -0
  31. package/dist/cjs/webhooks.d.ts +74 -0
  32. package/dist/cjs/webhooks.js +123 -0
  33. package/dist/esm/client.d.ts +20 -0
  34. package/dist/esm/client.js +28 -0
  35. package/dist/esm/core/errors.d.ts +101 -0
  36. package/dist/esm/core/errors.js +124 -0
  37. package/dist/esm/core/http.d.ts +87 -0
  38. package/dist/esm/core/http.js +356 -0
  39. package/dist/esm/core/pagination.d.ts +35 -0
  40. package/dist/esm/core/pagination.js +95 -0
  41. package/dist/esm/generated/types.d.ts +1017 -0
  42. package/dist/esm/generated/types.js +2 -0
  43. package/dist/esm/index.d.ts +15 -0
  44. package/dist/esm/index.js +4 -0
  45. package/dist/esm/package.json +1 -0
  46. package/dist/esm/resources/conversations.d.ts +20 -0
  47. package/dist/esm/resources/conversations.js +28 -0
  48. package/dist/esm/resources/messages.d.ts +104 -0
  49. package/dist/esm/resources/messages.js +108 -0
  50. package/dist/esm/resources/webhook-deliveries.d.ts +27 -0
  51. package/dist/esm/resources/webhook-deliveries.js +38 -0
  52. package/dist/esm/resources/webhook-endpoints.d.ts +54 -0
  53. package/dist/esm/resources/webhook-endpoints.js +78 -0
  54. package/dist/esm/resources/webhook-event-types.d.ts +13 -0
  55. package/dist/esm/resources/webhook-event-types.js +18 -0
  56. package/dist/esm/resources/whatsapp-templates.d.ts +48 -0
  57. package/dist/esm/resources/whatsapp-templates.js +67 -0
  58. package/dist/esm/version.d.ts +2 -0
  59. package/dist/esm/version.js +2 -0
  60. package/dist/esm/webhooks.d.ts +74 -0
  61. package/dist/esm/webhooks.js +118 -0
  62. package/package.json +79 -4
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // Generated by `npm run generate` from spec/openapi.json. Don't edit.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = exports.WebhookVerificationError = exports.verifyWebhook = exports.UnprocessableEntityError = exports.ServerError = exports.RequestTimeoutError = exports.RequestAbortedError = exports.RateLimitError = exports.PermissionDeniedError = exports.PaymentRequiredError = exports.PayloadTooLargeError = exports.NotFoundError = exports.ConnectionError = exports.ConflictError = exports.ChatwiseError = exports.BadRequestError = exports.AuthenticationError = exports.APIError = exports.Chatwise = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "Chatwise", { enumerable: true, get: function () { return client_js_1.Chatwise; } });
6
+ var errors_js_1 = require("./core/errors.js");
7
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
8
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
9
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
10
+ Object.defineProperty(exports, "ChatwiseError", { enumerable: true, get: function () { return errors_js_1.ChatwiseError; } });
11
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
12
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
13
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
14
+ Object.defineProperty(exports, "PayloadTooLargeError", { enumerable: true, get: function () { return errors_js_1.PayloadTooLargeError; } });
15
+ Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return errors_js_1.PaymentRequiredError; } });
16
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return errors_js_1.PermissionDeniedError; } });
17
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
18
+ Object.defineProperty(exports, "RequestAbortedError", { enumerable: true, get: function () { return errors_js_1.RequestAbortedError; } });
19
+ Object.defineProperty(exports, "RequestTimeoutError", { enumerable: true, get: function () { return errors_js_1.RequestTimeoutError; } });
20
+ Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_js_1.ServerError; } });
21
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return errors_js_1.UnprocessableEntityError; } });
22
+ var webhooks_js_1 = require("./webhooks.js");
23
+ Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_js_1.verifyWebhook; } });
24
+ Object.defineProperty(exports, "WebhookVerificationError", { enumerable: true, get: function () { return webhooks_js_1.WebhookVerificationError; } });
25
+ var version_js_1 = require("./version.js");
26
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -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,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Conversations = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ const pagination_js_1 = require("../core/pagination.js");
6
+ /** The conversations in the workspace's inbox. */
7
+ class Conversations {
8
+ #request;
9
+ /** @internal */
10
+ constructor(request) {
11
+ this.#request = request;
12
+ }
13
+ /**
14
+ * Lists conversations, or finds them by customer. The latest activity comes first. One that gets a
15
+ * message while you read the pages moves to the top, so you can miss it.
16
+ *
17
+ * Scope: `conversations:read`.
18
+ */
19
+ list(params = {}, options) {
20
+ return (0, pagination_js_1.list)(this.#request, () => '/v1/conversations', params, options);
21
+ }
22
+ /**
23
+ * Reads one conversation: its channel, status and customer.
24
+ *
25
+ * Scope: `conversations:read`.
26
+ */
27
+ async get(conversationId, options) {
28
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/conversations/${conversationId}` }, options);
29
+ return data;
30
+ }
31
+ }
32
+ exports.Conversations = Conversations;
@@ -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,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Messages = void 0;
4
+ const errors_js_1 = require("../core/errors.js");
5
+ const http_js_1 = require("../core/http.js");
6
+ const pagination_js_1 = require("../core/pagination.js");
7
+ /** Messages on every channel. */
8
+ class Messages {
9
+ #request;
10
+ /** @internal */
11
+ constructor(request) {
12
+ this.#request = request;
13
+ }
14
+ /**
15
+ * Lists messages across the workspace, or searches their text. Deleted and hidden messages are left out.
16
+ *
17
+ * Scope: `messages:read`.
18
+ */
19
+ list(params = {}, options) {
20
+ return (0, pagination_js_1.list)(this.#request, () => '/v1/messages', params, options);
21
+ }
22
+ /**
23
+ * Lists one conversation's messages. Deleted and hidden messages are left out.
24
+ *
25
+ * Scope: `messages:read`.
26
+ */
27
+ listInConversation(conversationId, params = {}, options) {
28
+ return (0, pagination_js_1.list)(this.#request, () => (0, http_js_1.path) `/v1/conversations/${conversationId}/messages`, params, options);
29
+ }
30
+ /**
31
+ * Reads one message. A deleted or hidden message is not found.
32
+ *
33
+ * Scope: `messages:read`.
34
+ */
35
+ async get(conversationId, messageId, options) {
36
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/conversations/${conversationId}/messages/${messageId}` }, options);
37
+ return data;
38
+ }
39
+ /**
40
+ * Lists a message's files, at most 20. One that is `available` has a `url` that works for 5 minutes,
41
+ * without an API key: don't send yours with it. List the files again for a new one.
42
+ *
43
+ * On WhatsApp, Instagram and Messenger. A file on Instagram or Messenger can be `pending` for a moment
44
+ * after the message arrives, and a story that a message replies to or mentions the account in isn't
45
+ * listed until it is copied.
46
+ *
47
+ * Scope: `messages:read`.
48
+ */
49
+ async listFiles(conversationId, messageId, options) {
50
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/conversations/${conversationId}/messages/${messageId}/files` }, options);
51
+ return data;
52
+ }
53
+ /**
54
+ * Replies in a WhatsApp, Instagram or Messenger conversation, with a text or a file. The answer means the
55
+ * channel accepted the message, not that it was delivered.
56
+ *
57
+ * The route recognizes a repeat by `idempotencyKey`, so this is retried like a read, and after
58
+ * `SEND_IN_PROGRESS`. If it still fails with one of these, with no answer, or with `MEDIA_PROCESSING`,
59
+ * `MEDIA_DOWNLOAD_FAILED` or `Invalid API key`, call it again later, with the same key, content and API
60
+ * key. Any other 4xx comes back until you fix what it names. A video on Messenger can take longer to send
61
+ * than the retries last: after `SEND_IN_PROGRESS`, call again within a minute, or you can miss that it was
62
+ * refused, and send it again.
63
+ *
64
+ * After `SEND_OUTCOME_UNKNOWN` a repeat sends nothing. The message may have been sent, also if the
65
+ * conversation doesn't show it, so let a person decide whether to send it again with a new key.
66
+ *
67
+ * An error is about the last request. If an earlier one got no answer, 401, 403, 404 and 429 don't say
68
+ * that nothing was sent, and with a file no error does while that one is still running. So don't go on with
69
+ * another `idempotencyKey` or API key.
70
+ *
71
+ * Scope: `messages:reply`.
72
+ */
73
+ async reply(conversationId, params, options) {
74
+ const { idempotencyKey, mediaTimeoutMs, ...rest } = options ?? {};
75
+ // Without one the header would be "undefined", which is a key the API takes, and the same for every reply.
76
+ // Other characters can't be in a header. The rest is for the API to check.
77
+ if (typeof idempotencyKey !== 'string' || !/^[\x21-\x7e]+$/.test(idempotencyKey)) {
78
+ throw new errors_js_1.ChatwiseError('messages.reply needs an idempotencyKey: 8 to 128 letters, digits, dots, underscores, hyphens or colons.');
79
+ }
80
+ const { data } = await this.#request({
81
+ method: 'POST',
82
+ path: (0, http_js_1.path) `/v1/conversations/${conversationId}/messages`,
83
+ body: params,
84
+ headers: { 'Idempotency-Key': idempotencyKey },
85
+ // Not after SEND_OUTCOME_UNKNOWN, which a repeat only answers again.
86
+ repeatAfter: ({ status, code }) => (status >= 500 ? code !== 'SEND_OUTCOME_UNKNOWN' : status === 409 && code === 'SEND_IN_PROGRESS'),
87
+ pending: { codes: ['MEDIA_PROCESSING', 'MEDIA_BUSY'], timeoutMs: mediaTimeoutMs },
88
+ }, rest);
89
+ return data;
90
+ }
91
+ /**
92
+ * Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not
93
+ * that it was delivered. To send one by its name, use `whatsappTemplates.send`.
94
+ *
95
+ * Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
96
+ * (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
97
+ * doesn't show it, so check before you send again.
98
+ *
99
+ * Scope: `messages:send`.
100
+ */
101
+ async send(params, options) {
102
+ const channel = params?.channel ?? 'WHATSAPP';
103
+ // The API answers 201 to these too, and sends nothing.
104
+ if (!params?.templateId)
105
+ throw new errors_js_1.ChatwiseError('messages.send needs a templateId: without one nothing would be sent.');
106
+ if (channel !== 'WHATSAPP')
107
+ throw new errors_js_1.ChatwiseError('messages.send can only send on WHATSAPP: on another channel nothing would be sent.');
108
+ const { data } = await this.#request({ method: 'POST', path: '/v1/messages', body: { ...params, channel } }, options);
109
+ return data;
110
+ }
111
+ }
112
+ exports.Messages = Messages;
@@ -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,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookDeliveries = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ const pagination_js_1 = require("../core/pagination.js");
6
+ /** What was sent to an endpoint. Deliveries are kept for 30 days. */
7
+ class WebhookDeliveries {
8
+ #request;
9
+ /** @internal */
10
+ constructor(request) {
11
+ this.#request = request;
12
+ }
13
+ /**
14
+ * Lists an endpoint's deliveries, newest first.
15
+ *
16
+ * Scope: `webhooks:read`.
17
+ */
18
+ list(endpointId, params = {}, options) {
19
+ return (0, pagination_js_1.list)(this.#request, () => (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/deliveries`, params, options);
20
+ }
21
+ /**
22
+ * Reads one delivery, with the payload it sends and its attempts.
23
+ *
24
+ * Scope: `webhooks:read`, and `messages:read` if it is for a `message.*` event.
25
+ */
26
+ async get(deliveryId, options) {
27
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/webhook-deliveries/${deliveryId}` }, options);
28
+ return data;
29
+ }
30
+ /**
31
+ * Sends a delivery again, with the same event id, starting from its first attempt. If Chatwise was
32
+ * waiting before it tries the endpoint again, the wait ends. A `BadRequestError` says that it can't be
33
+ * sent again: its message was unsent, deleted or hidden, or its comment hidden or no longer stored.
34
+ *
35
+ * Scope: `webhooks:write`, and `messages:read` if it is for a `message.*` event.
36
+ */
37
+ async redeliver(deliveryId, options) {
38
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-deliveries/${deliveryId}/redeliver` }, options);
39
+ return data;
40
+ }
41
+ }
42
+ exports.WebhookDeliveries = WebhookDeliveries;
@@ -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,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookEndpoints = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ /** Where Chatwise sends events. */
6
+ class WebhookEndpoints {
7
+ #request;
8
+ /** @internal */
9
+ constructor(request) {
10
+ this.#request = request;
11
+ }
12
+ /**
13
+ * Lists the workspace's webhook endpoints, oldest first. There are at most 10, so there are no pages.
14
+ *
15
+ * Scope: `webhooks:read`.
16
+ */
17
+ async list(options) {
18
+ const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-endpoints' }, options);
19
+ return data;
20
+ }
21
+ /**
22
+ * Creates an endpoint. Store `signingSecret` right away: it is returned only here.
23
+ *
24
+ * Scope: `webhooks:write`, and `messages:read` to subscribe to `message.*` events.
25
+ */
26
+ async create(params, options) {
27
+ const { data } = await this.#request({ method: 'POST', path: '/v1/webhook-endpoints', body: params }, options);
28
+ return data;
29
+ }
30
+ /**
31
+ * Reads one endpoint and how its deliveries are going.
32
+ *
33
+ * Scope: `webhooks:read`.
34
+ */
35
+ async get(endpointId, options) {
36
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}` }, options);
37
+ return data;
38
+ }
39
+ /**
40
+ * Changes an endpoint: only the fields you pass, at least one. `status: 'PAUSED'` stops new
41
+ * deliveries, and `status: 'ACTIVE'` resumes them, also after Chatwise disabled the endpoint. It clears
42
+ * the endpoint's failures and any wait (`health.backoffUntil`), and so does a new `url`, which also
43
+ * receives the deliveries that were already waiting.
44
+ *
45
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events before or after the change.
46
+ */
47
+ async update(endpointId, params, options) {
48
+ const { data } = await this.#request({ method: 'PATCH', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}`, body: params }, options);
49
+ return data;
50
+ }
51
+ /**
52
+ * Deletes an endpoint and cancels its deliveries that weren't sent yet.
53
+ *
54
+ * Scope: `webhooks:write`.
55
+ */
56
+ async delete(endpointId, options) {
57
+ const { data } = await this.#request({ method: 'DELETE', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}` }, options);
58
+ return data;
59
+ }
60
+ /**
61
+ * Sends a signed `webhook.test` event now, also to a paused endpoint, and returns what your endpoint
62
+ * answered. Check `delivered`: this doesn't throw when your endpoint failed. If Chatwise is waiting
63
+ * before it tries the endpoint again (`health.backoffUntil`), a test that succeeds ends the wait.
64
+ *
65
+ * Scope: `webhooks:write`.
66
+ */
67
+ async test(endpointId, options) {
68
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/test` }, options);
69
+ return data;
70
+ }
71
+ /**
72
+ * Replaces the signing secret. Store it right away: it is returned only here. For 24 hours deliveries
73
+ * are signed with the previous secret too.
74
+ *
75
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events.
76
+ */
77
+ async rotateSecret(endpointId, options) {
78
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/rotate-secret` }, options);
79
+ return data;
80
+ }
81
+ }
82
+ exports.WebhookEndpoints = WebhookEndpoints;
@@ -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,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookEventTypes = void 0;
4
+ /** The events a webhook endpoint can subscribe to. */
5
+ class WebhookEventTypes {
6
+ #request;
7
+ /** @internal */
8
+ constructor(request) {
9
+ this.#request = request;
10
+ }
11
+ /**
12
+ * Lists the events an endpoint can subscribe to and the channels each covers. Some are listed before
13
+ * they are sent: today Chatwise sends only `message.received`.
14
+ *
15
+ * Scope: `webhooks:read`.
16
+ */
17
+ async list(options) {
18
+ const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-event-types' }, options);
19
+ return data;
20
+ }
21
+ }
22
+ exports.WebhookEventTypes = WebhookEventTypes;
@@ -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
+ }