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.
- package/CHANGELOG.md +6 -0
- package/agent_docs/INCOMING_MESSAGES_BRAINSTORM.md +500 -0
- package/cloud-api-docs/webhooks/endpoint.md +112 -0
- package/cloud-api-docs/webhooks/overview.md +154 -0
- package/package.json +6 -2
- package/src/client/HttpClient.ts +43 -6
- package/src/client/WhatsAppClient.ts +3 -0
- package/src/examples/main.ts +9 -0
- package/src/examples/template.ts +134 -0
- package/src/schemas/client.ts +2 -2
- package/src/schemas/index.ts +1 -0
- package/src/schemas/templates/component.ts +145 -0
- package/src/schemas/templates/index.ts +4 -0
- package/src/schemas/templates/request.ts +78 -0
- package/src/schemas/templates/response.ts +64 -0
- package/src/services/accounts/AccountsClient.ts +6 -14
- package/src/services/accounts/AccountsService.ts +19 -21
- package/src/services/accounts/methods/list-phone-numbers.ts +1 -2
- package/src/services/business/BusinessClient.ts +1 -9
- package/src/services/business/BusinessService.ts +19 -21
- package/src/services/business/methods/list-accounts.ts +1 -2
- package/src/services/messages/MessagesClient.ts +2 -6
- package/src/services/messages/MessagesService.ts +42 -22
- package/src/services/templates/TemplatesClient.ts +35 -0
- package/src/services/templates/TemplatesService.ts +117 -0
- package/src/services/templates/index.ts +3 -0
- package/src/services/templates/methods/create.ts +27 -0
- package/src/services/templates/methods/delete.ts +38 -0
- package/src/services/templates/methods/get.ts +23 -0
- package/src/services/templates/methods/list.ts +36 -0
- package/src/services/templates/methods/update.ts +35 -0
- package/src/types/index.ts +1 -0
- package/src/types/templates/component.ts +33 -0
- package/src/types/templates/index.ts +4 -0
- package/src/types/templates/request.ts +28 -0
- package/src/types/templates/response.ts +34 -0
- 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
|
+
|
package/src/types/index.ts
CHANGED
|
@@ -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,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
|
-
|
|
18
|
-
|
|
16
|
+
"lib": ["esnext"],
|
|
17
|
+
"types": ["node"],
|
|
19
18
|
// and npm install -D @types/node
|
|
20
19
|
|
|
21
20
|
// Other Outputs
|