@wats/graph 0.3.1 → 0.3.3
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/dist/client.d.ts +2 -2
- package/dist/client.js +3 -3
- package/dist/createFetchTransport.d.ts +1 -1
- package/dist/createFetchTransport.js +1 -1
- package/dist/createMockTransport.d.ts +1 -1
- package/dist/endpoint.d.ts +1 -1
- package/dist/endpoint.js +1 -1
- package/dist/endpoints/businessManagement.d.ts +153 -9
- package/dist/endpoints/businessManagement.js +279 -7
- package/dist/endpoints/calling.d.ts +7 -7
- package/dist/endpoints/calling.js +2 -2
- package/dist/endpoints/flows/callables.d.ts +10 -10
- package/dist/endpoints/flows/callables.js +2 -2
- package/dist/endpoints/flows/dataExchange.d.ts +1 -1
- package/dist/endpoints/flows/dataExchange.js +2 -2
- package/dist/endpoints/flows/flowJson.d.ts +1 -1
- package/dist/endpoints/flows/flowJson.js +1 -1
- package/dist/endpoints/flows/index.d.ts +6 -6
- package/dist/endpoints/flows/index.js +4 -4
- package/dist/endpoints/flows/shared.d.ts +1 -1
- package/dist/endpoints/flows/shared.js +1 -1
- package/dist/endpoints/flows/types.d.ts +1 -1
- package/dist/endpoints/flows.d.ts +2 -2
- package/dist/endpoints/flows.js +1 -1
- package/dist/endpoints/media.d.ts +1 -1
- package/dist/endpoints/media.js +1 -1
- package/dist/endpoints/messages/builders-basic.d.ts +11 -0
- package/dist/endpoints/messages/builders-basic.js +272 -0
- package/dist/endpoints/messages/builders-interactive.d.ts +11 -0
- package/dist/endpoints/messages/builders-interactive.js +156 -0
- package/dist/endpoints/messages/builders-template.d.ts +3 -0
- package/dist/endpoints/messages/builders-template.js +121 -0
- package/dist/endpoints/messages/callables.d.ts +31 -0
- package/dist/endpoints/messages/callables.js +57 -0
- package/dist/endpoints/messages/index.d.ts +6 -0
- package/dist/endpoints/messages/index.js +56 -0
- package/dist/endpoints/messages/types.d.ts +363 -0
- package/dist/endpoints/messages/types.js +0 -0
- package/dist/endpoints/messages/validation.d.ts +43 -0
- package/dist/endpoints/messages/validation.js +277 -0
- package/dist/endpoints/messages.d.ts +1 -375
- package/dist/endpoints/messages.js +1 -675
- package/dist/endpoints/templates/builders.d.ts +1 -1
- package/dist/endpoints/templates/builders.js +24 -1
- package/dist/endpoints/templates/callables.d.ts +7 -6
- package/dist/endpoints/templates/callables.js +7 -5
- package/dist/endpoints/templates/groups.d.ts +126 -0
- package/dist/endpoints/templates/groups.js +156 -0
- package/dist/endpoints/templates/index.d.ts +7 -5
- package/dist/endpoints/templates/index.js +11 -3
- package/dist/endpoints/templates/shared.d.ts +2 -2
- package/dist/endpoints/templates/shared.js +1 -1
- package/dist/endpoints/templates/types.d.ts +15 -2
- package/dist/endpoints/templates/validation.d.ts +1 -1
- package/dist/endpoints/templates/validation.js +2 -2
- package/dist/endpoints/templates.d.ts +2 -2
- package/dist/endpoints/templates.js +7 -1
- package/dist/endpoints/waba/index.d.ts +4 -4
- package/dist/endpoints/waba/index.js +1 -1
- package/dist/endpoints/waba/phoneNumbers.d.ts +6 -4
- package/dist/endpoints/waba/phoneNumbers.js +3 -3
- package/dist/endpoints/wabaEndpoints.d.ts +6 -6
- package/dist/endpoints/wabaEndpoints.js +9 -3
- package/dist/errorRegistry.d.ts +1 -1
- package/dist/errorSubclasses.d.ts +30 -2
- package/dist/errorSubclasses.js +65 -2
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +15 -15
- package/dist/internal/validation/arrays.js +2 -2
- package/dist/internal/validation/errors.d.ts +1 -1
- package/dist/internal/validation/errors.js +1 -1
- package/dist/internal/validation/headers.js +3 -3
- package/dist/internal/validation/index.d.ts +8 -8
- package/dist/internal/validation/index.js +8 -8
- package/dist/internal/validation/json.js +4 -4
- package/dist/internal/validation/options.js +2 -2
- package/dist/internal/validation/paths.js +2 -2
- package/dist/internal/validation/records.js +2 -2
- package/dist/internal/validation/strings.js +1 -1
- package/dist/pagination.d.ts +2 -2
- package/dist/subclients/phoneNumberClient.d.ts +21 -5
- package/dist/subclients/phoneNumberClient.js +78 -7
- package/dist/subclients/wabaClient.d.ts +19 -5
- package/dist/subclients/wabaClient.js +39 -6
- package/package.json +10 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineEndpoint } from "../endpoint";
|
|
2
|
-
import { GraphRequestValidationError } from "../errors";
|
|
1
|
+
import { defineEndpoint } from "../endpoint.js";
|
|
2
|
+
import { GraphRequestValidationError } from "../errors.js";
|
|
3
3
|
export const CALL_BIZ_OPAQUE_CALLBACK_DATA_MAX_LENGTH = 512;
|
|
4
4
|
export const CALL_SESSION_MAX_STRING_LENGTH = 16384;
|
|
5
5
|
export const CALL_SESSION_MAX_DEPTH = 8;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CreateFlowBody, FlowAssetsResponse, FlowDetails, FlowListResponse, FlowMutationResponse, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
|
|
2
|
-
declare const listFlowsRaw: import("
|
|
1
|
+
import type { CreateFlowBody, FlowAssetsResponse, FlowDetails, FlowListResponse, FlowMutationResponse, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types.js";
|
|
2
|
+
declare const listFlowsRaw: import("../../endpoint.js").EndpointCallable<{
|
|
3
3
|
wabaId: string;
|
|
4
4
|
fields?: string;
|
|
5
5
|
status?: string;
|
|
@@ -13,7 +13,7 @@ export declare const listFlows: {
|
|
|
13
13
|
(client: Parameters<typeof listFlowsRaw>[0], params: ListFlowsInput, body?: never, opts?: Parameters<typeof listFlowsRaw>[3]): Promise<FlowListResponse>;
|
|
14
14
|
readonly definition: typeof listFlowsRaw.definition;
|
|
15
15
|
};
|
|
16
|
-
declare const getFlowRaw: import("
|
|
16
|
+
declare const getFlowRaw: import("../../endpoint.js").EndpointCallable<{
|
|
17
17
|
flowId: string;
|
|
18
18
|
fields?: string;
|
|
19
19
|
invalidate_preview?: string;
|
|
@@ -23,7 +23,7 @@ export declare const getFlow: {
|
|
|
23
23
|
(client: Parameters<typeof getFlowRaw>[0], params: GetFlowInput, body?: never, opts?: Parameters<typeof getFlowRaw>[3]): Promise<FlowDetails>;
|
|
24
24
|
readonly definition: typeof getFlowRaw.definition;
|
|
25
25
|
};
|
|
26
|
-
declare const createFlowRaw: import("
|
|
26
|
+
declare const createFlowRaw: import("../../endpoint.js").EndpointCallable<{
|
|
27
27
|
wabaId: string;
|
|
28
28
|
}, CreateFlowBody, FlowMutationResponse>;
|
|
29
29
|
export declare const createFlow: {
|
|
@@ -32,7 +32,7 @@ export declare const createFlow: {
|
|
|
32
32
|
}, body: CreateFlowBody, opts?: Parameters<typeof createFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
33
33
|
readonly definition: typeof createFlowRaw.definition;
|
|
34
34
|
};
|
|
35
|
-
declare const updateFlowMetadataRaw: import("
|
|
35
|
+
declare const updateFlowMetadataRaw: import("../../endpoint.js").EndpointCallable<{
|
|
36
36
|
flowId: string;
|
|
37
37
|
}, UpdateFlowMetadataBody, FlowMutationResponse>;
|
|
38
38
|
export declare const updateFlowMetadata: {
|
|
@@ -41,7 +41,7 @@ export declare const updateFlowMetadata: {
|
|
|
41
41
|
}, body: UpdateFlowMetadataBody, opts?: Parameters<typeof updateFlowMetadataRaw>[3]): Promise<FlowMutationResponse>;
|
|
42
42
|
readonly definition: typeof updateFlowMetadataRaw.definition;
|
|
43
43
|
};
|
|
44
|
-
declare const updateFlowJsonRaw: import("
|
|
44
|
+
declare const updateFlowJsonRaw: import("../../endpoint.js").EndpointCallable<{
|
|
45
45
|
flowId: string;
|
|
46
46
|
}, UpdateFlowJsonBody, FlowMutationResponse>;
|
|
47
47
|
export declare const updateFlowJson: {
|
|
@@ -50,7 +50,7 @@ export declare const updateFlowJson: {
|
|
|
50
50
|
}, body: UpdateFlowJsonBody, opts?: Parameters<typeof updateFlowJsonRaw>[3]): Promise<FlowMutationResponse>;
|
|
51
51
|
readonly definition: typeof updateFlowJsonRaw.definition;
|
|
52
52
|
};
|
|
53
|
-
declare const publishFlowRaw: import("
|
|
53
|
+
declare const publishFlowRaw: import("../../endpoint.js").EndpointCallable<{
|
|
54
54
|
flowId: string;
|
|
55
55
|
}, never, FlowMutationResponse>;
|
|
56
56
|
export declare const publishFlow: {
|
|
@@ -59,7 +59,7 @@ export declare const publishFlow: {
|
|
|
59
59
|
}, body?: never, opts?: Parameters<typeof publishFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
60
60
|
readonly definition: typeof publishFlowRaw.definition;
|
|
61
61
|
};
|
|
62
|
-
declare const deleteFlowRaw: import("
|
|
62
|
+
declare const deleteFlowRaw: import("../../endpoint.js").EndpointCallable<{
|
|
63
63
|
flowId: string;
|
|
64
64
|
}, never, FlowMutationResponse>;
|
|
65
65
|
export declare const deleteFlow: {
|
|
@@ -68,7 +68,7 @@ export declare const deleteFlow: {
|
|
|
68
68
|
}, body?: never, opts?: Parameters<typeof deleteFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
69
69
|
readonly definition: typeof deleteFlowRaw.definition;
|
|
70
70
|
};
|
|
71
|
-
declare const deprecateFlowRaw: import("
|
|
71
|
+
declare const deprecateFlowRaw: import("../../endpoint.js").EndpointCallable<{
|
|
72
72
|
flowId: string;
|
|
73
73
|
}, never, FlowMutationResponse>;
|
|
74
74
|
export declare const deprecateFlow: {
|
|
@@ -77,7 +77,7 @@ export declare const deprecateFlow: {
|
|
|
77
77
|
}, body?: never, opts?: Parameters<typeof deprecateFlowRaw>[3]): Promise<FlowMutationResponse>;
|
|
78
78
|
readonly definition: typeof deprecateFlowRaw.definition;
|
|
79
79
|
};
|
|
80
|
-
declare const getFlowAssetsRaw: import("
|
|
80
|
+
declare const getFlowAssetsRaw: import("../../endpoint.js").EndpointCallable<{
|
|
81
81
|
flowId: string;
|
|
82
82
|
fields?: string;
|
|
83
83
|
limit?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineEndpoint } from "../../endpoint";
|
|
1
|
+
import { defineEndpoint } from "../../endpoint.js";
|
|
2
2
|
import {
|
|
3
3
|
flowNormalizePathParams,
|
|
4
4
|
mapCreateFlowBody,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
normalizeFlowAssetsParams,
|
|
8
8
|
normalizeGetFlowParams,
|
|
9
9
|
normalizeListFlowsParams
|
|
10
|
-
} from "./flowJson";
|
|
10
|
+
} from "./flowJson.js";
|
|
11
11
|
const listFlowsRaw = defineEndpoint({
|
|
12
12
|
method: "GET",
|
|
13
13
|
pathTemplate: "/{wabaId}/flows",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FlowCloseResponse, FlowCloseResponseInput, FlowErrorResponse, FlowErrorResponseInput, FlowScreenResponse, FlowScreenResponseInput } from "./types";
|
|
1
|
+
import type { FlowCloseResponse, FlowCloseResponseInput, FlowErrorResponse, FlowErrorResponseInput, FlowScreenResponse, FlowScreenResponseInput } from "./types.js";
|
|
2
2
|
export declare function buildFlowScreenResponse(input: FlowScreenResponseInput): FlowScreenResponse;
|
|
3
3
|
export declare function buildFlowCloseResponse(input?: FlowCloseResponseInput): FlowCloseResponse;
|
|
4
4
|
export declare function buildFlowErrorResponse(input: FlowErrorResponseInput): FlowErrorResponse;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flowAssertPlainRecord, flowMaybeString, flowString } from "./shared";
|
|
2
|
-
import { flowJsonClone } from "./flowJson";
|
|
1
|
+
import { flowAssertPlainRecord, flowMaybeString, flowString } from "./shared.js";
|
|
2
|
+
import { flowJsonClone } from "./flowJson.js";
|
|
3
3
|
function cloneFlowResponseData(value, helperName) {
|
|
4
4
|
if (value === undefined)
|
|
5
5
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateFlowBody, FlowJson, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
|
|
1
|
+
import type { CreateFlowBody, FlowJson, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types.js";
|
|
2
2
|
interface FlowJsonCloneState {
|
|
3
3
|
readonly seen: WeakSet<object>;
|
|
4
4
|
componentCount: number;
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
flowMaybeString,
|
|
15
15
|
flowString,
|
|
16
16
|
flowUrl
|
|
17
|
-
} from "./shared";
|
|
17
|
+
} from "./shared.js";
|
|
18
18
|
export function flowJsonClone(value, helperName, path = "input", state = { seen: new WeakSet, componentCount: 0 }, depth = 0, parentKey = "") {
|
|
19
19
|
if (depth > FLOW_JSON_MAX_DEPTH) {
|
|
20
20
|
throw flowError(`Invalid ${helperName} input: ${path} exceeds maximum depth ${FLOW_JSON_MAX_DEPTH}.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata } from "./callables";
|
|
2
|
-
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES } from "./shared";
|
|
3
|
-
export { buildFlowJson, validateFlowJson } from "./flowJson";
|
|
4
|
-
export { buildFlowCloseResponse, buildFlowErrorResponse, buildFlowScreenResponse } from "./dataExchange";
|
|
5
|
-
export type { GraphPaging } from "../wabaEndpoints";
|
|
6
|
-
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types";
|
|
1
|
+
export { createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata } from "./callables.js";
|
|
2
|
+
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES } from "./shared.js";
|
|
3
|
+
export { buildFlowJson, validateFlowJson } from "./flowJson.js";
|
|
4
|
+
export { buildFlowCloseResponse, buildFlowErrorResponse, buildFlowScreenResponse } from "./dataExchange.js";
|
|
5
|
+
export type { GraphPaging } from "../wabaEndpoints.js";
|
|
6
|
+
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./types.js";
|
|
@@ -8,7 +8,7 @@ export {
|
|
|
8
8
|
publishFlow,
|
|
9
9
|
updateFlowJson,
|
|
10
10
|
updateFlowMetadata
|
|
11
|
-
} from "./callables";
|
|
11
|
+
} from "./callables.js";
|
|
12
12
|
export {
|
|
13
13
|
FLOW_JSON_MAX_ARRAY_LENGTH,
|
|
14
14
|
FLOW_JSON_MAX_BYTES,
|
|
@@ -17,10 +17,10 @@ export {
|
|
|
17
17
|
FLOW_JSON_MAX_SCREENS,
|
|
18
18
|
FLOW_JSON_MAX_STRING_LENGTH,
|
|
19
19
|
FLOW_MAX_CATEGORIES
|
|
20
|
-
} from "./shared";
|
|
21
|
-
export { buildFlowJson, validateFlowJson } from "./flowJson";
|
|
20
|
+
} from "./shared.js";
|
|
21
|
+
export { buildFlowJson, validateFlowJson } from "./flowJson.js";
|
|
22
22
|
export {
|
|
23
23
|
buildFlowCloseResponse,
|
|
24
24
|
buildFlowErrorResponse,
|
|
25
25
|
buildFlowScreenResponse
|
|
26
|
-
} from "./dataExchange";
|
|
26
|
+
} from "./dataExchange.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphRequestValidationError } from "../../errors";
|
|
1
|
+
import { GraphRequestValidationError } from "../../errors.js";
|
|
2
2
|
export declare const FLOW_JSON_MAX_DEPTH = 16;
|
|
3
3
|
export declare const FLOW_JSON_MAX_ARRAY_LENGTH = 1000;
|
|
4
4
|
export declare const FLOW_JSON_MAX_SCREENS = 50;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphPaging } from "../wabaEndpoints";
|
|
1
|
+
import type { GraphPaging } from "../wabaEndpoints.js";
|
|
2
2
|
export type FlowStatus = "DRAFT" | "PUBLISHED" | "DEPRECATED" | "BLOCKED" | "THROTTLED" | string;
|
|
3
3
|
export type FlowCategory = "SIGN_UP" | "SIGN_IN" | "APPOINTMENT_BOOKING" | "LEAD_GENERATION" | "CONTACT_US" | "CUSTOMER_SUPPORT" | "SURVEY" | "OTHER" | string;
|
|
4
4
|
export interface FlowDetails {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowScreenResponse, createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index";
|
|
2
|
-
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, GraphPaging, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index";
|
|
1
|
+
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowScreenResponse, createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index.js";
|
|
2
|
+
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, GraphPaging, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index.js";
|
package/dist/endpoints/flows.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphClient } from "../client";
|
|
1
|
+
import type { GraphClient } from "../client.js";
|
|
2
2
|
export type MediaOperation = "upload" | "download" | "delete" | "download_bytes" | "decrypt_encrypted" | "create_upload_session" | "upload_file_to_session" | "get_upload_session";
|
|
3
3
|
export type MediaNotImplementedCode = "not_implemented";
|
|
4
4
|
export declare class MediaNotImplementedError extends Error {
|
package/dist/endpoints/media.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GraphMessagesAudioPayload, GraphMessagesContactsPayload, GraphMessagesDocumentPayload, GraphMessagesImagePayload, GraphMessagesLocationPayload, GraphMessagesReactionPayload, GraphMessagesRemoveReactionInput, GraphMessagesSendAudioInput, GraphMessagesSendContactsInput, GraphMessagesSendDocumentInput, GraphMessagesSendImageInput, GraphMessagesSendLocationInput, GraphMessagesSendReactionInput, GraphMessagesSendStickerInput, GraphMessagesSendTextInput, GraphMessagesSendVideoInput, GraphMessagesStickerPayload, GraphMessagesTextPayload, GraphMessagesVideoPayload } from "./types.js";
|
|
2
|
+
export declare function buildSendTextPayload(input: GraphMessagesSendTextInput): GraphMessagesTextPayload;
|
|
3
|
+
export declare function buildSendImagePayload(input: GraphMessagesSendImageInput): GraphMessagesImagePayload;
|
|
4
|
+
export declare function buildSendVideoPayload(input: GraphMessagesSendVideoInput): GraphMessagesVideoPayload;
|
|
5
|
+
export declare function buildSendAudioPayload(input: GraphMessagesSendAudioInput): GraphMessagesAudioPayload;
|
|
6
|
+
export declare function buildSendDocumentPayload(input: GraphMessagesSendDocumentInput): GraphMessagesDocumentPayload;
|
|
7
|
+
export declare function buildSendStickerPayload(input: GraphMessagesSendStickerInput): GraphMessagesStickerPayload;
|
|
8
|
+
export declare function buildSendLocationPayload(input: GraphMessagesSendLocationInput): GraphMessagesLocationPayload;
|
|
9
|
+
export declare function buildSendContactsPayload(input: GraphMessagesSendContactsInput): GraphMessagesContactsPayload;
|
|
10
|
+
export declare function buildSendReactionPayload(input: GraphMessagesSendReactionInput): GraphMessagesReactionPayload;
|
|
11
|
+
export declare function buildRemoveReactionPayload(input: GraphMessagesRemoveReactionInput): GraphMessagesReactionPayload;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { GraphRequestValidationError } from "../../errors.js";
|
|
2
|
+
import {
|
|
3
|
+
GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH,
|
|
4
|
+
GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH,
|
|
5
|
+
GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH,
|
|
6
|
+
GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH,
|
|
7
|
+
GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH,
|
|
8
|
+
GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH,
|
|
9
|
+
GRAPH_MESSAGES_MAX_CONTACTS,
|
|
10
|
+
assertBoundedArray,
|
|
11
|
+
assertNonEmptyControlFreeString,
|
|
12
|
+
assertNoUnsupportedMediaFields,
|
|
13
|
+
assertValidMediaLink,
|
|
14
|
+
assertValidNumberInRange,
|
|
15
|
+
asRecordInput,
|
|
16
|
+
assertValidRecipient,
|
|
17
|
+
assertValidReplyToMessageId,
|
|
18
|
+
assertValidText,
|
|
19
|
+
isPlainOptionsObject,
|
|
20
|
+
mapValidatedArray,
|
|
21
|
+
maybeText,
|
|
22
|
+
withReplyContext
|
|
23
|
+
} from "./validation.js";
|
|
24
|
+
export function buildSendTextPayload(input) {
|
|
25
|
+
if (!isPlainOptionsObject(input)) {
|
|
26
|
+
throw new GraphRequestValidationError("Invalid sendText input: expected an options object.");
|
|
27
|
+
}
|
|
28
|
+
const to = assertValidRecipient(input.to);
|
|
29
|
+
const text = assertValidText(input.text);
|
|
30
|
+
if (input.previewUrl !== undefined && typeof input.previewUrl !== "boolean") {
|
|
31
|
+
throw new GraphRequestValidationError("Invalid sendText input: previewUrl must be a boolean when provided.");
|
|
32
|
+
}
|
|
33
|
+
const payload = {
|
|
34
|
+
messaging_product: "whatsapp",
|
|
35
|
+
to,
|
|
36
|
+
type: "text",
|
|
37
|
+
text: {
|
|
38
|
+
body: text
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (input.previewUrl !== undefined) {
|
|
42
|
+
payload.text.preview_url = input.previewUrl;
|
|
43
|
+
}
|
|
44
|
+
if (input.replyToMessageId !== undefined) {
|
|
45
|
+
payload.context = {
|
|
46
|
+
message_id: assertValidReplyToMessageId(input.replyToMessageId)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return payload;
|
|
50
|
+
}
|
|
51
|
+
function buildSendMediaPayload(input, mediaType, helperName, options) {
|
|
52
|
+
if (!isPlainOptionsObject(input)) {
|
|
53
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: expected an options object.`);
|
|
54
|
+
}
|
|
55
|
+
const record = input;
|
|
56
|
+
assertNoUnsupportedMediaFields(record, helperName, options);
|
|
57
|
+
const to = assertValidRecipient(record.to, helperName);
|
|
58
|
+
const hasMediaId = record.mediaId !== undefined;
|
|
59
|
+
const hasLink = record.link !== undefined;
|
|
60
|
+
if (hasMediaId === hasLink) {
|
|
61
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: exactly one of mediaId or link is required.`);
|
|
62
|
+
}
|
|
63
|
+
const media = {};
|
|
64
|
+
if (hasMediaId) {
|
|
65
|
+
media.id = assertNonEmptyControlFreeString(record.mediaId, "mediaId", GRAPH_MESSAGES_MEDIA_ID_MAX_LENGTH, helperName);
|
|
66
|
+
} else {
|
|
67
|
+
media.link = assertValidMediaLink(record.link, helperName);
|
|
68
|
+
}
|
|
69
|
+
if (record.caption !== undefined) {
|
|
70
|
+
media.caption = assertNonEmptyControlFreeString(record.caption, "caption", GRAPH_MESSAGES_MEDIA_CAPTION_MAX_LENGTH, helperName);
|
|
71
|
+
}
|
|
72
|
+
if (record.filename !== undefined) {
|
|
73
|
+
media.filename = assertNonEmptyControlFreeString(record.filename, "filename", GRAPH_MESSAGES_DOCUMENT_FILENAME_MAX_LENGTH, helperName);
|
|
74
|
+
}
|
|
75
|
+
const payload = {
|
|
76
|
+
messaging_product: "whatsapp",
|
|
77
|
+
to,
|
|
78
|
+
type: mediaType,
|
|
79
|
+
[mediaType]: media
|
|
80
|
+
};
|
|
81
|
+
if (record.replyToMessageId !== undefined) {
|
|
82
|
+
payload.context = {
|
|
83
|
+
message_id: assertValidReplyToMessageId(record.replyToMessageId)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return payload;
|
|
87
|
+
}
|
|
88
|
+
export function buildSendImagePayload(input) {
|
|
89
|
+
return buildSendMediaPayload(input, "image", "sendImage", {
|
|
90
|
+
caption: true,
|
|
91
|
+
filename: false
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function buildSendVideoPayload(input) {
|
|
95
|
+
return buildSendMediaPayload(input, "video", "sendVideo", {
|
|
96
|
+
caption: true,
|
|
97
|
+
filename: false
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export function buildSendAudioPayload(input) {
|
|
101
|
+
const payload = buildSendMediaPayload(input, "audio", "sendAudio", {
|
|
102
|
+
caption: false,
|
|
103
|
+
filename: false
|
|
104
|
+
});
|
|
105
|
+
const record = input;
|
|
106
|
+
if (record.voice !== undefined) {
|
|
107
|
+
if (typeof record.voice !== "boolean") {
|
|
108
|
+
throw new GraphRequestValidationError("Invalid sendAudio input: voice must be a boolean when provided.");
|
|
109
|
+
}
|
|
110
|
+
if (record.voice)
|
|
111
|
+
payload.audio.voice = true;
|
|
112
|
+
}
|
|
113
|
+
return payload;
|
|
114
|
+
}
|
|
115
|
+
export function buildSendDocumentPayload(input) {
|
|
116
|
+
return buildSendMediaPayload(input, "document", "sendDocument", {
|
|
117
|
+
caption: true,
|
|
118
|
+
filename: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function buildSendStickerPayload(input) {
|
|
122
|
+
return buildSendMediaPayload(input, "sticker", "sendSticker", {
|
|
123
|
+
caption: false,
|
|
124
|
+
filename: false
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export function buildSendLocationPayload(input) {
|
|
128
|
+
const record = asRecordInput(input, "sendLocation");
|
|
129
|
+
const payload = {
|
|
130
|
+
messaging_product: "whatsapp",
|
|
131
|
+
to: assertValidRecipient(record.to, "sendLocation"),
|
|
132
|
+
type: "location",
|
|
133
|
+
location: {
|
|
134
|
+
latitude: assertValidNumberInRange(record.latitude, "latitude", -90, 90, "sendLocation"),
|
|
135
|
+
longitude: assertValidNumberInRange(record.longitude, "longitude", -180, 180, "sendLocation")
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const name = maybeText(record.name, "name", GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, "sendLocation");
|
|
139
|
+
const address = maybeText(record.address, "address", GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH, "sendLocation");
|
|
140
|
+
if (name !== undefined)
|
|
141
|
+
payload.location.name = name;
|
|
142
|
+
if (address !== undefined)
|
|
143
|
+
payload.location.address = address;
|
|
144
|
+
return withReplyContext(payload, record);
|
|
145
|
+
}
|
|
146
|
+
function normalizeContactName(value, helperName) {
|
|
147
|
+
if (!isPlainOptionsObject(value))
|
|
148
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: contact.name must be an object.`);
|
|
149
|
+
const name = value;
|
|
150
|
+
const formatted = maybeText(name.formattedName ?? name.formatted, "name.formattedName", GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH, helperName);
|
|
151
|
+
if (formatted === undefined)
|
|
152
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: contact.name.formattedName is required.`);
|
|
153
|
+
const out = { formatted_name: formatted };
|
|
154
|
+
const pairs = [["firstName", "first_name"], ["lastName", "last_name"], ["middleName", "middle_name"], ["suffix", "suffix"], ["prefix", "prefix"]];
|
|
155
|
+
for (const [camel, snake] of pairs) {
|
|
156
|
+
const v = maybeText(name[camel] ?? name[snake], `name.${camel}`, GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, helperName);
|
|
157
|
+
if (v !== undefined)
|
|
158
|
+
out[snake] = v;
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
function normalizeTypedStringRecord(value, fieldName, requiredField, helperName) {
|
|
163
|
+
if (!isPlainOptionsObject(value))
|
|
164
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName} entries must be objects.`);
|
|
165
|
+
const record = value;
|
|
166
|
+
const primary = maybeText(record[requiredField], `${fieldName}.${requiredField}`, GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH, helperName);
|
|
167
|
+
if (primary === undefined)
|
|
168
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: ${fieldName}.${requiredField} is required.`);
|
|
169
|
+
const out = { [requiredField]: primary };
|
|
170
|
+
const type = maybeText(record.type, `${fieldName}.type`, GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, helperName);
|
|
171
|
+
if (type !== undefined)
|
|
172
|
+
out.type = type;
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
function normalizeContact(value, helperName) {
|
|
176
|
+
if (!isPlainOptionsObject(value))
|
|
177
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: contacts entries must be objects.`);
|
|
178
|
+
const contact = value;
|
|
179
|
+
const out = { name: normalizeContactName(contact.name, helperName) };
|
|
180
|
+
if (contact.phones !== undefined) {
|
|
181
|
+
out.phones = mapValidatedArray(assertBoundedArray(contact.phones, "contact.phones", 1, 20, helperName), (entry) => {
|
|
182
|
+
if (!isPlainOptionsObject(entry))
|
|
183
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: phone entries must be objects.`);
|
|
184
|
+
const phone = entry;
|
|
185
|
+
const rawPhone = maybeText(phone.phone, "phone.phone", GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, helperName);
|
|
186
|
+
const waId = maybeText(phone.waId ?? phone.wa_id, "phone.waId", GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, helperName);
|
|
187
|
+
if (rawPhone === undefined && waId === undefined)
|
|
188
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: phone requires phone or waId.`);
|
|
189
|
+
const normalized = {};
|
|
190
|
+
if (rawPhone !== undefined)
|
|
191
|
+
normalized.phone = rawPhone;
|
|
192
|
+
if (waId !== undefined)
|
|
193
|
+
normalized.wa_id = waId;
|
|
194
|
+
const type = maybeText(phone.type, "phone.type", GRAPH_MESSAGES_SHORT_LABEL_MAX_LENGTH, helperName);
|
|
195
|
+
if (type !== undefined)
|
|
196
|
+
normalized.type = type;
|
|
197
|
+
return normalized;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (contact.emails !== undefined)
|
|
201
|
+
out.emails = mapValidatedArray(assertBoundedArray(contact.emails, "contact.emails", 1, 20, helperName), (entry) => normalizeTypedStringRecord(entry, "email", "email", helperName));
|
|
202
|
+
if (contact.urls !== undefined) {
|
|
203
|
+
out.urls = mapValidatedArray(assertBoundedArray(contact.urls, "contact.urls", 1, 20, helperName), (entry) => {
|
|
204
|
+
const normalized = normalizeTypedStringRecord(entry, "url", "url", helperName);
|
|
205
|
+
normalized.url = assertValidMediaLink(normalized.url, helperName);
|
|
206
|
+
return normalized;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (contact.addresses !== undefined) {
|
|
210
|
+
out.addresses = mapValidatedArray(assertBoundedArray(contact.addresses, "contact.addresses", 1, 20, helperName), (entry) => {
|
|
211
|
+
if (!isPlainOptionsObject(entry))
|
|
212
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: address entries must be objects.`);
|
|
213
|
+
const address = entry;
|
|
214
|
+
const normalized = {};
|
|
215
|
+
for (const [camel, snake] of [["street", "street"], ["city", "city"], ["state", "state"], ["zip", "zip"], ["country", "country"], ["countryCode", "country_code"], ["type", "type"]]) {
|
|
216
|
+
const v = maybeText(address[camel] ?? address[snake], `address.${camel}`, GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH, helperName);
|
|
217
|
+
if (v !== undefined)
|
|
218
|
+
normalized[snake] = v;
|
|
219
|
+
}
|
|
220
|
+
if (Object.keys(normalized).length === 0)
|
|
221
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: address entries must contain at least one field.`);
|
|
222
|
+
return normalized;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (contact.org !== undefined) {
|
|
226
|
+
if (!isPlainOptionsObject(contact.org))
|
|
227
|
+
throw new GraphRequestValidationError(`Invalid ${helperName} input: org must be an object.`);
|
|
228
|
+
const org = contact.org;
|
|
229
|
+
const normalized = {};
|
|
230
|
+
for (const key of ["company", "department", "title"]) {
|
|
231
|
+
const v = maybeText(org[key], `org.${key}`, GRAPH_MESSAGES_GENERAL_TEXT_MAX_LENGTH, helperName);
|
|
232
|
+
if (v !== undefined)
|
|
233
|
+
normalized[key] = v;
|
|
234
|
+
}
|
|
235
|
+
if (Object.keys(normalized).length > 0)
|
|
236
|
+
out.org = normalized;
|
|
237
|
+
}
|
|
238
|
+
const birthday = maybeText(contact.birthday, "birthday", 32, helperName);
|
|
239
|
+
if (birthday !== undefined)
|
|
240
|
+
out.birthday = birthday;
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
export function buildSendContactsPayload(input) {
|
|
244
|
+
const record = asRecordInput(input, "sendContacts");
|
|
245
|
+
const contacts = mapValidatedArray(assertBoundedArray(record.contacts, "contacts", 1, GRAPH_MESSAGES_MAX_CONTACTS, "sendContacts"), (c) => normalizeContact(c, "sendContacts"));
|
|
246
|
+
return withReplyContext({ messaging_product: "whatsapp", to: assertValidRecipient(record.to, "sendContacts"), type: "contacts", contacts }, record);
|
|
247
|
+
}
|
|
248
|
+
export function buildSendReactionPayload(input) {
|
|
249
|
+
const record = asRecordInput(input, "sendReaction");
|
|
250
|
+
const emoji = assertNonEmptyControlFreeString(record.emoji, "emoji", 32, "sendReaction");
|
|
251
|
+
return {
|
|
252
|
+
messaging_product: "whatsapp",
|
|
253
|
+
to: assertValidRecipient(record.to, "sendReaction"),
|
|
254
|
+
type: "reaction",
|
|
255
|
+
reaction: {
|
|
256
|
+
message_id: assertNonEmptyControlFreeString(record.messageId, "messageId", GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH, "sendReaction"),
|
|
257
|
+
emoji
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export function buildRemoveReactionPayload(input) {
|
|
262
|
+
const record = asRecordInput(input, "removeReaction");
|
|
263
|
+
return {
|
|
264
|
+
messaging_product: "whatsapp",
|
|
265
|
+
to: assertValidRecipient(record.to, "removeReaction"),
|
|
266
|
+
type: "reaction",
|
|
267
|
+
reaction: {
|
|
268
|
+
message_id: assertNonEmptyControlFreeString(record.messageId, "messageId", GRAPH_MESSAGES_REPLY_TO_MESSAGE_ID_MAX_LENGTH, "removeReaction"),
|
|
269
|
+
emoji: ""
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GraphMessagesInteractivePayload, GraphMessagesMarkMessageAsReadInput, GraphMessagesRequestLocationInput, GraphMessagesSendButtonsInput, GraphMessagesSendCallPermissionRequestInput, GraphMessagesSendCatalogInput, GraphMessagesSendCtaUrlInput, GraphMessagesSendListInput, GraphMessagesSendProductInput, GraphMessagesSendProductsInput, GraphMessagesStatusPayload, GraphMessagesTypingIndicatorInput } from "./types.js";
|
|
2
|
+
export declare function buildSendButtonsPayload(input: GraphMessagesSendButtonsInput): GraphMessagesInteractivePayload;
|
|
3
|
+
export declare function buildSendListPayload(input: GraphMessagesSendListInput): GraphMessagesInteractivePayload;
|
|
4
|
+
export declare function buildSendCtaUrlPayload(input: GraphMessagesSendCtaUrlInput): GraphMessagesInteractivePayload;
|
|
5
|
+
export declare function buildSendCallPermissionRequestPayload(input: GraphMessagesSendCallPermissionRequestInput): GraphMessagesInteractivePayload;
|
|
6
|
+
export declare function buildSendProductPayload(input: GraphMessagesSendProductInput): GraphMessagesInteractivePayload;
|
|
7
|
+
export declare function buildSendProductsPayload(input: GraphMessagesSendProductsInput): GraphMessagesInteractivePayload;
|
|
8
|
+
export declare function buildSendCatalogPayload(input: GraphMessagesSendCatalogInput): GraphMessagesInteractivePayload;
|
|
9
|
+
export declare function buildRequestLocationPayload(input: GraphMessagesRequestLocationInput): GraphMessagesInteractivePayload;
|
|
10
|
+
export declare function buildMarkMessageAsReadPayload(input: GraphMessagesMarkMessageAsReadInput): GraphMessagesStatusPayload;
|
|
11
|
+
export declare function buildTypingIndicatorPayload(input: GraphMessagesTypingIndicatorInput): GraphMessagesStatusPayload;
|