@ecodrix/erix-api 1.0.0

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.
@@ -0,0 +1,49 @@
1
+ import { APIResource } from "../../resource";
2
+ import { Messages } from "./messages";
3
+ import { Conversations } from "./conversations";
4
+ import type { AxiosInstance } from "axios";
5
+
6
+ export interface SendTemplatePayload {
7
+ /** Phone number in E.164 format. */
8
+ phone: string;
9
+ /** Name of the pre-approved WhatsApp template. */
10
+ templateName: string;
11
+ /** Language code (defaults to "en"). */
12
+ languageCode?: string;
13
+ /** Key-value pairs matching variables in your template (e.g., {{1}}, {{2}}). */
14
+ variables?: Record<string, string>;
15
+ /** Explicitly resolved variables if bypassing the internal resolution engine. */
16
+ resolvedVariables?: any[];
17
+ }
18
+
19
+ export class WhatsApp extends APIResource {
20
+ public messages: Messages;
21
+ public conversations: Conversations;
22
+
23
+ constructor(client: AxiosInstance) {
24
+ super(client);
25
+ this.messages = new Messages(client);
26
+ this.conversations = new Conversations(client);
27
+ }
28
+
29
+ /**
30
+ * Dispatch a WhatsApp template message directly to a specific phone number.
31
+ * Bypasses the automation queue for immediate high-priority delivery.
32
+ *
33
+ * @param payload - The template dispatch payload.
34
+ * @returns Information about the dispatched message.
35
+ */
36
+ async sendTemplate(payload: SendTemplatePayload): Promise<{
37
+ success: boolean;
38
+ messageId?: string;
39
+ templateName?: string;
40
+ resolvedVariables?: any[];
41
+ }> {
42
+ return this.post<{
43
+ success: boolean;
44
+ messageId?: string;
45
+ templateName?: string;
46
+ resolvedVariables?: any[];
47
+ }>("/api/saas/whatsapp/send-template", payload);
48
+ }
49
+ }
@@ -0,0 +1,138 @@
1
+ import { APIResource } from "../../resource";
2
+
3
+ /**
4
+ * Parameters for sending a free-form WhatsApp message.
5
+ */
6
+ export interface SendMessageParams {
7
+ /**
8
+ * Recipient's phone number in E.164 format.
9
+ * @example "+919876543210"
10
+ */
11
+ to: string;
12
+ /** Plain text body of the message. */
13
+ text?: string;
14
+ /** Public URL of the media asset to send. */
15
+ mediaUrl?: string;
16
+ /** MIME category of the media. */
17
+ mediaType?: "image" | "video" | "audio" | "document";
18
+ /** The `messageId` of the message to reply to (quoted replies). */
19
+ replyToId?: string;
20
+ /** Filename shown to the recipient (required for `document` type). */
21
+ filename?: string;
22
+ /** Arbitrary metadata stored with the message record. */
23
+ metadata?: Record<string, any>;
24
+ }
25
+
26
+ /**
27
+ * Parameters for sending a pre-approved WhatsApp Business template.
28
+ */
29
+ export interface SendTemplateParams {
30
+ /**
31
+ * Recipient's phone number in E.164 format.
32
+ * @example "+919876543210"
33
+ */
34
+ to: string;
35
+ /** The exact template name as approved in Meta Business Manager. */
36
+ templateName: string;
37
+ /**
38
+ * BCP-47 language code for the template.
39
+ * @default "en_US"
40
+ */
41
+ language?: string;
42
+ /**
43
+ * Ordered array of variable substitutions for template placeholders.
44
+ * @example ["Alice", "10 April 2026", "10:00 AM"]
45
+ */
46
+ variables?: string[];
47
+ /** Optional header media URL (for templates with media headers). */
48
+ mediaUrl?: string;
49
+ /** Media type for the header (e.g. "image", "document"). */
50
+ mediaType?: string;
51
+ }
52
+
53
+ /**
54
+ * WhatsApp outbound messaging resource.
55
+ *
56
+ * Access via `ecod.whatsapp.messages`.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * await ecod.whatsapp.messages.send({
61
+ * to: "+919876543210",
62
+ * text: "Your appointment is confirmed!",
63
+ * });
64
+ * ```
65
+ */
66
+ export class Messages extends APIResource {
67
+ /**
68
+ * Send a free-text or media message to a WhatsApp number.
69
+ *
70
+ * For text-only messages, supply `text`. For media, supply `mediaUrl`
71
+ * and `mediaType`. Both can be combined.
72
+ *
73
+ * @param params - Message parameters.
74
+ * @returns The created message record.
75
+ *
76
+ * @example Text message
77
+ * ```typescript
78
+ * await ecod.whatsapp.messages.send({
79
+ * to: "+919876543210",
80
+ * text: "Hello!",
81
+ * });
82
+ * ```
83
+ *
84
+ * @example Media message
85
+ * ```typescript
86
+ * await ecod.whatsapp.messages.send({
87
+ * to: "+919876543210",
88
+ * mediaUrl: "https://cdn.ecodrix.com/invoice.pdf",
89
+ * mediaType: "document",
90
+ * filename: "invoice.pdf",
91
+ * });
92
+ * ```
93
+ */
94
+ async send(params: SendMessageParams) {
95
+ return this.post("/api/saas/chat/send", params);
96
+ }
97
+
98
+ /**
99
+ * Send a pre-approved WhatsApp Business template message.
100
+ *
101
+ * Templates must be approved in Meta Business Manager before use.
102
+ * Variable placeholders in the template body are filled left-to-right
103
+ * from the `variables` array.
104
+ *
105
+ * @param params - Template message parameters.
106
+ * @returns The created message record.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * await ecod.whatsapp.messages.sendTemplate({
111
+ * to: "+919876543210",
112
+ * templateName: "appointment_reminder",
113
+ * language: "en_US",
114
+ * variables: ["Alice", "10 April", "10:00 AM"],
115
+ * });
116
+ * ```
117
+ */
118
+ async sendTemplate(params: SendTemplateParams) {
119
+ return this.post("/api/saas/chat/send", {
120
+ ...params,
121
+ templateLanguage: params.language || "en_US",
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Mark all messages in a conversation as read (double-tick).
127
+ *
128
+ * @param conversationId - The conversation to mark as read.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * await ecod.whatsapp.messages.markRead("conv_64abc...");
133
+ * ```
134
+ */
135
+ async markRead(conversationId: string) {
136
+ return this.post(`/api/saas/chat/conversations/${conversationId}/read`);
137
+ }
138
+ }