whatsapp-cloud 0.0.4 → 0.0.5

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 (37) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/agent_docs/INCOMING_MESSAGES_BRAINSTORM.md +500 -0
  3. package/cloud-api-docs/webhooks/endpoint.md +112 -0
  4. package/cloud-api-docs/webhooks/overview.md +154 -0
  5. package/package.json +6 -2
  6. package/src/client/HttpClient.ts +43 -6
  7. package/src/client/WhatsAppClient.ts +3 -0
  8. package/src/examples/main.ts +9 -0
  9. package/src/examples/template.ts +134 -0
  10. package/src/schemas/client.ts +2 -2
  11. package/src/schemas/index.ts +1 -0
  12. package/src/schemas/templates/component.ts +145 -0
  13. package/src/schemas/templates/index.ts +4 -0
  14. package/src/schemas/templates/request.ts +78 -0
  15. package/src/schemas/templates/response.ts +64 -0
  16. package/src/services/accounts/AccountsClient.ts +6 -14
  17. package/src/services/accounts/AccountsService.ts +19 -21
  18. package/src/services/accounts/methods/list-phone-numbers.ts +1 -2
  19. package/src/services/business/BusinessClient.ts +1 -9
  20. package/src/services/business/BusinessService.ts +19 -21
  21. package/src/services/business/methods/list-accounts.ts +1 -2
  22. package/src/services/messages/MessagesClient.ts +2 -6
  23. package/src/services/messages/MessagesService.ts +42 -22
  24. package/src/services/templates/TemplatesClient.ts +35 -0
  25. package/src/services/templates/TemplatesService.ts +117 -0
  26. package/src/services/templates/index.ts +3 -0
  27. package/src/services/templates/methods/create.ts +27 -0
  28. package/src/services/templates/methods/delete.ts +38 -0
  29. package/src/services/templates/methods/get.ts +23 -0
  30. package/src/services/templates/methods/list.ts +36 -0
  31. package/src/services/templates/methods/update.ts +35 -0
  32. package/src/types/index.ts +1 -0
  33. package/src/types/templates/component.ts +33 -0
  34. package/src/types/templates/index.ts +4 -0
  35. package/src/types/templates/request.ts +28 -0
  36. package/src/types/templates/response.ts +34 -0
  37. package/tsconfig.json +2 -3
@@ -0,0 +1,36 @@
1
+ import type { TemplatesClient } from "../TemplatesClient";
2
+ import { listTemplatesRequestSchema } from "../../../schemas/templates/request";
3
+ import type { ListTemplatesRequest } from "../../../types/templates/request";
4
+ import type { ListTemplatesResponse } from "../../../types/templates/response";
5
+ import { transformZodError } from "../../../utils/zod-error";
6
+
7
+ /**
8
+ * List message templates
9
+ *
10
+ * @param templatesClient - Templates client with WABA ID baked in
11
+ * @param options - Optional filter options (name)
12
+ */
13
+ export async function listTemplates(
14
+ templatesClient: TemplatesClient,
15
+ options?: ListTemplatesRequest
16
+ ): Promise<ListTemplatesResponse> {
17
+ // Validate options if provided
18
+ if (options) {
19
+ const result = listTemplatesRequestSchema.safeParse(options);
20
+ if (!result.success) {
21
+ throw transformZodError(result.error);
22
+ }
23
+ }
24
+
25
+ // Build query string
26
+ const params = new URLSearchParams();
27
+ if (options?.name) {
28
+ params.append("name", options.name);
29
+ }
30
+ const queryString = params.toString();
31
+ const path = queryString ? `/message_templates?${queryString}` : "/message_templates";
32
+
33
+ // Make API request - templatesClient handles the WABA ID prefix automatically
34
+ return templatesClient.get<ListTemplatesResponse>(path);
35
+ }
36
+
@@ -0,0 +1,35 @@
1
+ import type { HttpClient } from "../../../client/HttpClient";
2
+ import { updateTemplateRequestSchema } from "../../../schemas/templates/request";
3
+ import type { UpdateTemplateRequest } from "../../../types/templates/request";
4
+ import type { UpdateTemplateResponse } from "../../../types/templates/response";
5
+ import { transformZodError } from "../../../utils/zod-error";
6
+
7
+ /**
8
+ * Update a template
9
+ *
10
+ * Note: This uses the template ID directly (no WABA prefix needed)
11
+ *
12
+ * @param httpClient - HTTP client
13
+ * @param templateId - Template ID
14
+ * @param request - Template update request
15
+ */
16
+ export async function updateTemplate(
17
+ httpClient: HttpClient,
18
+ templateId: string,
19
+ request: UpdateTemplateRequest
20
+ ): Promise<UpdateTemplateResponse> {
21
+ if (!templateId || templateId.trim().length === 0) {
22
+ throw new Error("Template ID is required");
23
+ }
24
+
25
+ // Validate request with schema - throws WhatsAppValidationError if invalid
26
+ const result = updateTemplateRequestSchema.safeParse(request);
27
+ if (!result.success) {
28
+ throw transformZodError(result.error);
29
+ }
30
+ const data = result.data;
31
+
32
+ // Make API request - template ID is used directly, no WABA prefix
33
+ return httpClient.post<UpdateTemplateResponse>(`/${templateId}`, data);
34
+ }
35
+
@@ -2,4 +2,5 @@ export type * from "./client";
2
2
  export type * from "./messages/index";
3
3
  export type * from "./accounts/index";
4
4
  export type * from "./business/index";
5
+ export type * from "./templates/index";
5
6
  export type * from "./debug";
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ import {
3
+ buttonSchema,
4
+ componentSchema,
5
+ quickReplyButtonSchema,
6
+ urlButtonSchema,
7
+ phoneNumberButtonSchema,
8
+ copyCodeButtonSchema,
9
+ flowButtonSchema,
10
+ headerComponentSchema,
11
+ bodyComponentSchema,
12
+ footerComponentSchema,
13
+ buttonsComponentSchema,
14
+ } from "../../schemas/templates/component";
15
+
16
+ /**
17
+ * Button types
18
+ */
19
+ export type QuickReplyButton = z.infer<typeof quickReplyButtonSchema>;
20
+ export type UrlButton = z.infer<typeof urlButtonSchema>;
21
+ export type PhoneNumberButton = z.infer<typeof phoneNumberButtonSchema>;
22
+ export type CopyCodeButton = z.infer<typeof copyCodeButtonSchema>;
23
+ export type FlowButton = z.infer<typeof flowButtonSchema>;
24
+ export type Button = z.infer<typeof buttonSchema>;
25
+
26
+ /**
27
+ * Component types
28
+ */
29
+ export type HeaderComponent = z.infer<typeof headerComponentSchema>;
30
+ export type BodyComponent = z.infer<typeof bodyComponentSchema>;
31
+ export type FooterComponent = z.infer<typeof footerComponentSchema>;
32
+ export type ButtonsComponent = z.infer<typeof buttonsComponentSchema>;
33
+ export type Component = z.infer<typeof componentSchema>;
@@ -0,0 +1,4 @@
1
+ export * from "./component";
2
+ export * from "./request";
3
+ export * from "./response";
4
+
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import {
3
+ createTemplateRequestSchema,
4
+ updateTemplateRequestSchema,
5
+ listTemplatesRequestSchema,
6
+ deleteTemplateRequestSchema,
7
+ } from "../../schemas/templates/request";
8
+
9
+ /**
10
+ * Type for creating a template
11
+ */
12
+ export type CreateTemplateRequest = z.infer<typeof createTemplateRequestSchema>;
13
+
14
+ /**
15
+ * Type for updating a template
16
+ */
17
+ export type UpdateTemplateRequest = z.infer<typeof updateTemplateRequestSchema>;
18
+
19
+ /**
20
+ * Type for listing templates
21
+ */
22
+ export type ListTemplatesRequest = z.infer<typeof listTemplatesRequestSchema>;
23
+
24
+ /**
25
+ * Type for deleting a template
26
+ */
27
+ export type DeleteTemplateRequest = z.infer<typeof deleteTemplateRequestSchema>;
28
+
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ import {
3
+ templateResponseSchema,
4
+ createTemplateResponseSchema,
5
+ listTemplatesResponseSchema,
6
+ updateTemplateResponseSchema,
7
+ deleteTemplateResponseSchema,
8
+ } from "../../schemas/templates/response";
9
+
10
+ /**
11
+ * Type for a single template
12
+ */
13
+ export type TemplateResponse = z.infer<typeof templateResponseSchema>;
14
+
15
+ /**
16
+ * Type for create template response
17
+ */
18
+ export type CreateTemplateResponse = z.infer<typeof createTemplateResponseSchema>;
19
+
20
+ /**
21
+ * Type for list templates response
22
+ */
23
+ export type ListTemplatesResponse = z.infer<typeof listTemplatesResponseSchema>;
24
+
25
+ /**
26
+ * Type for update template response
27
+ */
28
+ export type UpdateTemplateResponse = z.infer<typeof updateTemplateResponseSchema>;
29
+
30
+ /**
31
+ * Type for delete template response
32
+ */
33
+ export type DeleteTemplateResponse = z.infer<typeof deleteTemplateResponseSchema>;
34
+
package/tsconfig.json CHANGED
@@ -12,10 +12,9 @@
12
12
  "module": "esnext",
13
13
  "moduleResolution": "bundler",
14
14
  "target": "esnext",
15
- "types": [],
16
15
  // For nodejs:
17
- // "lib": ["esnext"],
18
- // "types": ["node"],
16
+ "lib": ["esnext"],
17
+ "types": ["node"],
19
18
  // and npm install -D @types/node
20
19
 
21
20
  // Other Outputs