@ecodrix/erix-api 1.0.0 → 1.0.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/README.md +32 -25
- package/dist/cli.js +38 -0
- package/dist/index.d.cts +1871 -0
- package/dist/index.d.ts +902 -42
- package/dist/ts/browser/index.global.js +14 -14
- package/dist/ts/browser/index.global.js.map +1 -1
- package/dist/ts/cjs/index.cjs +1 -1
- package/dist/ts/cjs/index.cjs.map +1 -1
- package/dist/ts/cjs/index.d.cts +902 -42
- package/dist/ts/esm/index.d.ts +902 -42
- package/dist/ts/esm/index.js +1 -1
- package/dist/ts/esm/index.js.map +1 -1
- package/package.json +7 -2
- package/src/cli.ts +318 -0
- package/src/core.ts +20 -0
- package/src/index.ts +17 -1
- package/src/resource.ts +44 -5
- package/src/resources/crm/activities.ts +89 -0
- package/src/resources/crm/analytics.ts +89 -0
- package/src/resources/crm/automationDashboard.ts +24 -0
- package/src/resources/crm/automations.ts +145 -0
- package/src/resources/crm/index.ts +24 -0
- package/src/resources/crm/leads.ts +170 -42
- package/src/resources/crm/payments.ts +10 -0
- package/src/resources/crm/pipelines.ts +117 -0
- package/src/resources/crm/scoring.ts +33 -0
- package/src/resources/crm/sequences.ts +24 -0
- package/src/resources/events.ts +41 -0
- package/src/resources/health.ts +61 -0
- package/src/resources/marketing.ts +104 -0
- package/src/resources/meet.ts +9 -2
- package/src/resources/notifications.ts +30 -0
- package/src/resources/queue.ts +39 -0
- package/src/resources/storage.ts +72 -0
- package/src/resources/whatsapp/broadcasts.ts +31 -0
- package/src/resources/whatsapp/conversations.ts +34 -9
- package/src/resources/whatsapp/index.ts +20 -0
- package/src/resources/whatsapp/messages.ts +24 -0
- package/src/resources/whatsapp/templates.ts +99 -0
package/src/resources/events.ts
CHANGED
|
@@ -64,6 +64,17 @@ export interface TriggerPayload {
|
|
|
64
64
|
delayMinutes?: number;
|
|
65
65
|
/** Explicit ISO timestamp to trigger the workflow run */
|
|
66
66
|
runAt?: string;
|
|
67
|
+
/** Automatically generate a Google Meet appointment if matched actions require it */
|
|
68
|
+
requiresMeet?: boolean;
|
|
69
|
+
/** Configuration details for the generated Google Meet appointment */
|
|
70
|
+
meetConfig?: {
|
|
71
|
+
summary?: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
startTime?: string;
|
|
74
|
+
duration?: number;
|
|
75
|
+
timezone?: string;
|
|
76
|
+
attendees?: string[];
|
|
77
|
+
};
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
/**
|
|
@@ -118,4 +129,34 @@ export class EventsResource extends APIResource {
|
|
|
118
129
|
async trigger(payload: TriggerPayload): Promise<TriggerResponse> {
|
|
119
130
|
return this.post<TriggerResponse>("/api/saas/workflows/trigger", payload);
|
|
120
131
|
}
|
|
132
|
+
|
|
133
|
+
// --- CRM Custom Events ---
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* List all custom event definitions.
|
|
137
|
+
*/
|
|
138
|
+
async listCustomEvents<T = any>() {
|
|
139
|
+
return this.get<T>("/api/saas/crm/custom-events");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Create or upsert a custom event definition.
|
|
144
|
+
*/
|
|
145
|
+
async createCustomEvent<T = any>(payload: { name: string; displayName: string; description?: string }) {
|
|
146
|
+
return this.post<T>("/api/saas/crm/custom-events", payload);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Delete a custom event definition.
|
|
151
|
+
*/
|
|
152
|
+
async deleteCustomEvent<T = any>(id: string) {
|
|
153
|
+
return this.deleteRequest<T>(`/api/saas/crm/custom-events/${id}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Manually emit a custom event to trigger workflows based on its definition.
|
|
158
|
+
*/
|
|
159
|
+
async emit<T = any>(payload: { eventName: string; leadId: string; data?: any }) {
|
|
160
|
+
return this.post<T>("/api/saas/crm/events/emit", payload);
|
|
161
|
+
}
|
|
121
162
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { APIResource } from "../resource";
|
|
2
|
+
|
|
3
|
+
export interface SystemHealth {
|
|
4
|
+
status: string;
|
|
5
|
+
version: string;
|
|
6
|
+
env: string;
|
|
7
|
+
uptime: number;
|
|
8
|
+
db: string;
|
|
9
|
+
queueDepth: number;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ClientHealth {
|
|
14
|
+
clientCode: string;
|
|
15
|
+
services: {
|
|
16
|
+
whatsapp: "connected" | "not_configured";
|
|
17
|
+
email: "configured" | "not_configured";
|
|
18
|
+
googleMeet: "configured" | "not_configured";
|
|
19
|
+
};
|
|
20
|
+
activeAutomations: number;
|
|
21
|
+
queueDepth: number;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface JobStatus {
|
|
26
|
+
jobId: string;
|
|
27
|
+
status: string;
|
|
28
|
+
attempts: number;
|
|
29
|
+
maxAttempts: number;
|
|
30
|
+
lastError: any;
|
|
31
|
+
runAt: string;
|
|
32
|
+
completedAt: string | null;
|
|
33
|
+
failedAt: string | null;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class Health extends APIResource {
|
|
38
|
+
/**
|
|
39
|
+
* Global platform health check.
|
|
40
|
+
*/
|
|
41
|
+
async system(): Promise<SystemHealth> {
|
|
42
|
+
const res = await this.get<{ data: SystemHealth }>("/api/saas/health", { headers: { accept: "application/json" } });
|
|
43
|
+
return res.data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Tenant-specific health check. Identifies configured services.
|
|
48
|
+
*/
|
|
49
|
+
async clientHealth(): Promise<ClientHealth> {
|
|
50
|
+
const res = await this.get<{ data: ClientHealth }>("/api/saas/health/client");
|
|
51
|
+
return res.data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Job execution status lookup.
|
|
56
|
+
*/
|
|
57
|
+
async jobStatus(jobId: string): Promise<JobStatus> {
|
|
58
|
+
const res = await this.get<{ data: JobStatus }>(`/api/saas/jobs/status/${jobId}`);
|
|
59
|
+
return res.data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { APIResource } from "../resource";
|
|
2
|
+
|
|
3
|
+
export interface SendCampaignParams {
|
|
4
|
+
recipients: string[];
|
|
5
|
+
subject: string;
|
|
6
|
+
html: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Emails extends APIResource {
|
|
10
|
+
/**
|
|
11
|
+
* Dispatch a bulk email campaign.
|
|
12
|
+
*/
|
|
13
|
+
async sendCampaign<T = any>(params: SendCampaignParams) {
|
|
14
|
+
return this.post<T>("/api/saas/marketing/emails/campaign", params);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Send a test verification email (used to verify SMTP functionality).
|
|
19
|
+
*/
|
|
20
|
+
async sendTest<T = any>(to: string) {
|
|
21
|
+
return this.post<T>("/api/saas/marketing/emails/test", { to });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class Campaigns extends APIResource {
|
|
25
|
+
/**
|
|
26
|
+
* List email and SMS marketing campaigns.
|
|
27
|
+
*/
|
|
28
|
+
async list<T = any>(params?: { status?: string; limit?: number }) {
|
|
29
|
+
return this.get<T>("/api/saas/marketing/campaigns", { params } as any);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a new campaign.
|
|
34
|
+
*/
|
|
35
|
+
async create<T = any>(payload: { name: string; type: string; subject?: string; html?: string; templateId?: string; recipients?: string[] }) {
|
|
36
|
+
return this.post<T>("/api/saas/marketing/campaigns", payload);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve campaign details.
|
|
41
|
+
*/
|
|
42
|
+
async retrieve<T = any>(campaignId: string) {
|
|
43
|
+
return this.get<T>(`/api/saas/marketing/campaigns/${campaignId}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Update a campaign.
|
|
48
|
+
*/
|
|
49
|
+
async update<T = any>(campaignId: string, payload: any) {
|
|
50
|
+
return this.patch<T>(`/api/saas/marketing/campaigns/${campaignId}`, payload);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Delete a campaign.
|
|
55
|
+
*/
|
|
56
|
+
async delete<T = any>(campaignId: string) {
|
|
57
|
+
return this.deleteRequest<T>(`/api/saas/marketing/campaigns/${campaignId}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Send or schedule a campaign.
|
|
62
|
+
*/
|
|
63
|
+
async send<T = any>(campaignId: string, payload?: { scheduledAt?: string }) {
|
|
64
|
+
return this.post<T>(`/api/saas/marketing/campaigns/${campaignId}/send`, payload || {});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get campaign stats (opens, clicks, bounces).
|
|
69
|
+
*/
|
|
70
|
+
async stats<T = any>(campaignId: string) {
|
|
71
|
+
return this.get<T>(`/api/saas/marketing/campaigns/${campaignId}/stats`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class WhatsAppMarketing extends APIResource {
|
|
76
|
+
/**
|
|
77
|
+
* Dispatch a template-based WhatsApp message with CRM-integrated variable resolution.
|
|
78
|
+
*
|
|
79
|
+
* Unlike direct WhatsApp sending, this endpoint automatically pulls data from the CRM
|
|
80
|
+
* based on the provided variables mapping.
|
|
81
|
+
*/
|
|
82
|
+
async sendTemplate<T = any>(params: {
|
|
83
|
+
phone: string;
|
|
84
|
+
templateName: string;
|
|
85
|
+
languageCode?: string;
|
|
86
|
+
variables?: Record<string, string>;
|
|
87
|
+
resolvedVariables?: Record<string, string>;
|
|
88
|
+
}) {
|
|
89
|
+
return this.post<T>("/api/saas/marketing/whatsapp/send-template", params);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class Marketing extends APIResource {
|
|
94
|
+
public emails: Emails;
|
|
95
|
+
public campaigns: Campaigns;
|
|
96
|
+
public whatsapp: WhatsAppMarketing;
|
|
97
|
+
|
|
98
|
+
constructor(client: any) {
|
|
99
|
+
super(client);
|
|
100
|
+
this.emails = new Emails(client);
|
|
101
|
+
this.campaigns = new Campaigns(client);
|
|
102
|
+
this.whatsapp = new WhatsAppMarketing(client);
|
|
103
|
+
}
|
|
104
|
+
}
|
package/src/resources/meet.ts
CHANGED
|
@@ -133,8 +133,15 @@ export class Meetings extends APIResource {
|
|
|
133
133
|
* });
|
|
134
134
|
* ```
|
|
135
135
|
*/
|
|
136
|
-
async update(meetingId: string, data: UpdateMeetingParams)
|
|
137
|
-
return this.
|
|
136
|
+
async update<T = any>(meetingId: string, data: UpdateMeetingParams) {
|
|
137
|
+
return this.patch<T>(`/api/saas/meet/${meetingId}`, data);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Reschedule an existing meeting. Provides explicit method for time modifications.
|
|
142
|
+
*/
|
|
143
|
+
async reschedule<T = any>(meetingId: string, params: { startTime: Date | string; endTime: Date | string; duration?: number }) {
|
|
144
|
+
return this.patch<T>(`/api/saas/meet/${meetingId}`, params);
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
/**
|
|
@@ -120,4 +120,34 @@ export class Notifications extends APIResource {
|
|
|
120
120
|
async listCallbacks(params?: Omit<LogFilter, "trigger" | "phone">) {
|
|
121
121
|
return this.get("/api/saas/callbacks/logs", { params } as any);
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
// --- CRM Notifications (Alerts) ---
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* List active CRM notifications/alerts for the current agent.
|
|
128
|
+
*/
|
|
129
|
+
async listAlerts<T = any>(params?: { limit?: number; unreadOnly?: boolean }) {
|
|
130
|
+
return this.get<T>("/api/saas/crm/notifications", { params } as any);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Dismiss a specific notification alert.
|
|
135
|
+
*/
|
|
136
|
+
async dismissAlert<T = any>(notificationId: string) {
|
|
137
|
+
return this.patch<T>(`/api/saas/crm/notifications/${notificationId}/dismiss`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Clear (dismiss) all notifications for the current agent.
|
|
142
|
+
*/
|
|
143
|
+
async clearAllAlerts<T = any>() {
|
|
144
|
+
return this.deleteRequest<T>("/api/saas/crm/notifications/clear-all");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Retry an action from a notification (e.g. failed send).
|
|
149
|
+
*/
|
|
150
|
+
async retryAction<T = any>(notificationId: string) {
|
|
151
|
+
return this.post<T>(`/api/saas/crm/notifications/${notificationId}/retry`, {});
|
|
152
|
+
}
|
|
123
153
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { APIResource } from "../resource";
|
|
2
|
+
|
|
3
|
+
export interface JobStats {
|
|
4
|
+
waiting: number;
|
|
5
|
+
active: number;
|
|
6
|
+
completed: number;
|
|
7
|
+
failed: number;
|
|
8
|
+
delayed: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class Queue extends APIResource {
|
|
12
|
+
/**
|
|
13
|
+
* List all failed jobs.
|
|
14
|
+
*/
|
|
15
|
+
async listFailed<T = any>() {
|
|
16
|
+
return this.get<T>("/api/saas/queue/failed");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get queue health statistics.
|
|
21
|
+
*/
|
|
22
|
+
async getStats<T = JobStats>() {
|
|
23
|
+
return this.get<T>("/api/saas/queue/stats");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Retry a failed job.
|
|
28
|
+
*/
|
|
29
|
+
async retryJob<T = any>(jobId: string) {
|
|
30
|
+
return this.post<T>(`/api/saas/queue/${jobId}/retry`, {});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Remove a job from the queue.
|
|
35
|
+
*/
|
|
36
|
+
async deleteJob<T = any>(jobId: string) {
|
|
37
|
+
return this.deleteRequest<T>(`/api/saas/queue/${jobId}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { APIResource } from "../resource";
|
|
2
|
+
|
|
3
|
+
export class Folders extends APIResource {
|
|
4
|
+
/**
|
|
5
|
+
* Create a new folder.
|
|
6
|
+
*/
|
|
7
|
+
async create<T = any>(name: string) {
|
|
8
|
+
return this.post<T>("/api/saas/storage/folders", { name });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Delete a folder and its contents.
|
|
13
|
+
*/
|
|
14
|
+
async delete<T = any>(folderPath: string) {
|
|
15
|
+
return this.deleteRequest<T>(`/api/saas/storage/folders/${encodeURIComponent(folderPath)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class Files extends APIResource {
|
|
20
|
+
/**
|
|
21
|
+
* List files in a folder.
|
|
22
|
+
*/
|
|
23
|
+
async list<T = any>(folder: string, params?: { year?: string; month?: string }) {
|
|
24
|
+
return this.get<T>(`/api/saas/storage/files/${folder}`, { params } as any);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get a presigned upload URL for direct-to-cloud browser uploads.
|
|
29
|
+
*/
|
|
30
|
+
async getUploadUrl<T = any>(params: { folder: string; filename: string; contentType: string }) {
|
|
31
|
+
return this.post<T>("/api/saas/storage/upload-url", params);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Notify backend after a successful direct browser upload.
|
|
36
|
+
*/
|
|
37
|
+
async confirmUpload<T = any>(params: { key: string; sizeBytes: number }) {
|
|
38
|
+
return this.post<T>("/api/saas/storage/confirm-upload", params);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get a presigned download URL for an R2 key.
|
|
43
|
+
*/
|
|
44
|
+
async getDownloadUrl<T = any>(key: string) {
|
|
45
|
+
return this.post<T>("/api/saas/storage/download-url", { key });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Delete a file by key.
|
|
50
|
+
*/
|
|
51
|
+
async delete(key: string) {
|
|
52
|
+
return this.deleteRequest("/api/saas/storage/files", { params: { key } } as any);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class Storage extends APIResource {
|
|
57
|
+
public folders: Folders;
|
|
58
|
+
public files: Files;
|
|
59
|
+
|
|
60
|
+
constructor(client: any) {
|
|
61
|
+
super(client);
|
|
62
|
+
this.folders = new Folders(client);
|
|
63
|
+
this.files = new Files(client);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get tenant storage usage and quota limitations.
|
|
68
|
+
*/
|
|
69
|
+
async usage<T = any>() {
|
|
70
|
+
return this.get<T>("/api/saas/storage/usage");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { APIResource } from "../../resource";
|
|
2
|
+
|
|
3
|
+
export interface CreateBroadcastParams {
|
|
4
|
+
/** Optional name for the broadcast campaign */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Name of the Meta template to send */
|
|
7
|
+
templateName: string;
|
|
8
|
+
/** Language code (defaults to en_US) */
|
|
9
|
+
templateLanguage?: string;
|
|
10
|
+
/** List of recipients with their phone numbers and variable overrides */
|
|
11
|
+
recipients: {
|
|
12
|
+
phone: string;
|
|
13
|
+
variables?: string[];
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Broadcasts extends APIResource {
|
|
18
|
+
/**
|
|
19
|
+
* List past and active broadcasts.
|
|
20
|
+
*/
|
|
21
|
+
async list<T = any>(params?: Record<string, any>) {
|
|
22
|
+
return this.get<T>("/api/saas/chat/broadcasts", { params } as any);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a new broadcast to send a template message to multiple recipients.
|
|
27
|
+
*/
|
|
28
|
+
async create<T = any>(params: CreateBroadcastParams) {
|
|
29
|
+
return this.post<T>("/api/saas/chat/broadcast", params);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -3,41 +3,66 @@ import { APIResource } from "../../resource";
|
|
|
3
3
|
export interface ListParams {
|
|
4
4
|
limit?: number;
|
|
5
5
|
before?: string;
|
|
6
|
+
after?: string;
|
|
7
|
+
status?: string;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export class Conversations extends APIResource {
|
|
9
11
|
/**
|
|
10
12
|
* List conversations for the tenant.
|
|
11
13
|
*/
|
|
12
|
-
async list(params?: ListParams)
|
|
13
|
-
return this.get("/api/saas/chat/conversations", { params } as any);
|
|
14
|
+
async list<T = any>(params?: ListParams) {
|
|
15
|
+
return this.get<T>("/api/saas/chat/conversations", { params } as any);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new conversation explicitly.
|
|
20
|
+
*
|
|
21
|
+
* @param params - Conversation details.
|
|
22
|
+
*/
|
|
23
|
+
async create<T = any>(params: { phone: string; name?: string }) {
|
|
24
|
+
return this.post<T>("/api/saas/chat/conversations", params);
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
/**
|
|
17
28
|
* Retrieve details of a specific conversation.
|
|
18
29
|
*/
|
|
19
|
-
async retrieve(conversationId: string)
|
|
20
|
-
return this.get(`/api/saas/chat/conversations/${conversationId}`);
|
|
30
|
+
async retrieve<T = any>(conversationId: string) {
|
|
31
|
+
return this.get<T>(`/api/saas/chat/conversations/${conversationId}`);
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
35
|
* Get messages for a specific conversation.
|
|
25
36
|
*/
|
|
26
|
-
async messages(conversationId: string, params?: ListParams)
|
|
27
|
-
return this.get(`/api/saas/chat/conversations/${conversationId}/messages`, { params } as any);
|
|
37
|
+
async messages<T = any>(conversationId: string, params?: ListParams) {
|
|
38
|
+
return this.get<T>(`/api/saas/chat/conversations/${conversationId}/messages`, { params } as any);
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
/**
|
|
31
42
|
* Link a conversation to a lead.
|
|
32
43
|
*/
|
|
33
|
-
async linkLead(conversationId: string, leadId: string) {
|
|
34
|
-
return this.post(`/api/saas/chat/conversations/${conversationId}/link-lead`, { leadId });
|
|
44
|
+
async linkLead<T = any>(conversationId: string, leadId: string, leadData?: any) {
|
|
45
|
+
return this.post<T>(`/api/saas/chat/conversations/${conversationId}/link-lead`, { leadId, leadData });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mark a conversation as read (clear unread count).
|
|
50
|
+
*/
|
|
51
|
+
async markRead<T = any>(conversationId: string) {
|
|
52
|
+
return this.post<T>(`/api/saas/chat/conversations/${conversationId}/read`, {});
|
|
35
53
|
}
|
|
36
54
|
|
|
37
55
|
/**
|
|
38
56
|
* Delete a conversation.
|
|
39
57
|
*/
|
|
40
|
-
async delete(conversationId: string)
|
|
58
|
+
async delete(conversationId: string) {
|
|
41
59
|
return this.deleteRequest(`/api/saas/chat/conversations/${conversationId}`);
|
|
42
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Bulk delete conversations.
|
|
64
|
+
*/
|
|
65
|
+
async bulkDelete(ids: string[]) {
|
|
66
|
+
return this.post("/api/saas/chat/conversations/bulk-delete", { ids });
|
|
67
|
+
}
|
|
43
68
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { APIResource } from "../../resource";
|
|
2
2
|
import { Messages } from "./messages";
|
|
3
3
|
import { Conversations } from "./conversations";
|
|
4
|
+
import { Broadcasts } from "./broadcasts";
|
|
5
|
+
import { Templates } from "./templates";
|
|
4
6
|
import type { AxiosInstance } from "axios";
|
|
5
7
|
|
|
6
8
|
export interface SendTemplatePayload {
|
|
@@ -19,11 +21,29 @@ export interface SendTemplatePayload {
|
|
|
19
21
|
export class WhatsApp extends APIResource {
|
|
20
22
|
public messages: Messages;
|
|
21
23
|
public conversations: Conversations;
|
|
24
|
+
public broadcasts: Broadcasts;
|
|
25
|
+
public templates: Templates;
|
|
22
26
|
|
|
23
27
|
constructor(client: AxiosInstance) {
|
|
24
28
|
super(client);
|
|
25
29
|
this.messages = new Messages(client);
|
|
26
30
|
this.conversations = new Conversations(client);
|
|
31
|
+
this.broadcasts = new Broadcasts(client);
|
|
32
|
+
this.templates = new Templates(client);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Upload an asset directly to chat storage.
|
|
37
|
+
*/
|
|
38
|
+
async upload<T = any>(file: Blob | Buffer | File | any, filename: string) {
|
|
39
|
+
const form = new FormData();
|
|
40
|
+
form.append("file", file, filename);
|
|
41
|
+
return this.post<T>("/api/saas/whatsapp/upload", form, {
|
|
42
|
+
headers:
|
|
43
|
+
typeof (form as any).getHeaders === "function"
|
|
44
|
+
? (form as any).getHeaders()
|
|
45
|
+
: undefined,
|
|
46
|
+
});
|
|
27
47
|
}
|
|
28
48
|
|
|
29
49
|
/**
|
|
@@ -122,6 +122,30 @@ export class Messages extends APIResource {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Star or unstar a message.
|
|
127
|
+
*
|
|
128
|
+
* @param messageId - The ID of the message.
|
|
129
|
+
* @param isStarred - Boolean indicating whether to star or unstar.
|
|
130
|
+
*/
|
|
131
|
+
async star<T = any>(messageId: string, isStarred: boolean) {
|
|
132
|
+
return this.post<T>(`/api/saas/chat/messages/${messageId}/star`, {
|
|
133
|
+
isStarred,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* React to a message with an emoji.
|
|
139
|
+
*
|
|
140
|
+
* @param messageId - The ID of the message.
|
|
141
|
+
* @param reaction - The emoji (e.g. "👍") to react with, or empty string to remove.
|
|
142
|
+
*/
|
|
143
|
+
async react<T = any>(messageId: string, reaction: string) {
|
|
144
|
+
return this.post<T>(`/api/saas/chat/messages/${messageId}/react`, {
|
|
145
|
+
reaction,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
/**
|
|
126
150
|
* Mark all messages in a conversation as read (double-tick).
|
|
127
151
|
*
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { APIResource } from "../../resource";
|
|
2
|
+
|
|
3
|
+
export interface TemplateMapping {
|
|
4
|
+
mappings: any[];
|
|
5
|
+
onEmptyVariable: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class Templates extends APIResource {
|
|
9
|
+
/**
|
|
10
|
+
* List all templates from the tenant database.
|
|
11
|
+
*/
|
|
12
|
+
async list<T = any>(params?: { status?: string; mappingStatus?: string; channel?: string }) {
|
|
13
|
+
return this.get<T>("/api/saas/whatsapp/templates", { params } as any);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Synchronize templates from Meta API.
|
|
18
|
+
*/
|
|
19
|
+
async sync<T = any>() {
|
|
20
|
+
return this.post<T>("/api/saas/whatsapp/templates/sync", {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get template details.
|
|
25
|
+
*/
|
|
26
|
+
async retrieve<T = any>(templateIdentifier: string) {
|
|
27
|
+
return this.get<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateIdentifier)}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a new template manually.
|
|
32
|
+
*/
|
|
33
|
+
async create<T = any>(payload: any) {
|
|
34
|
+
return this.post<T>("/api/saas/whatsapp/templates", payload);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Update an existing template.
|
|
39
|
+
*/
|
|
40
|
+
async update<T = any>(templateId: string, payload: any) {
|
|
41
|
+
return this.put<T>(`/api/saas/whatsapp/templates/${templateId}`, payload);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Delete a template.
|
|
46
|
+
*/
|
|
47
|
+
async deleteTemplate<T = any>(templateName: string, force?: boolean) {
|
|
48
|
+
return this.deleteRequest<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateName)}${force ? "?force=true" : ""}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* List curated mapping config options.
|
|
53
|
+
*/
|
|
54
|
+
async mappingConfig<T = any>() {
|
|
55
|
+
return this.get<T>("/api/saas/whatsapp/templates/mapping/config");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* List CRM collections for variable mapping.
|
|
60
|
+
*/
|
|
61
|
+
async collections<T = any>() {
|
|
62
|
+
return this.get<T>("/api/saas/whatsapp/templates/collections");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* List CRM fields for a collection.
|
|
67
|
+
*/
|
|
68
|
+
async collectionFields<T = any>(collectionName: string) {
|
|
69
|
+
return this.get<T>(`/api/saas/whatsapp/templates/collections/${encodeURIComponent(collectionName)}/fields`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Update variable mappings for a template.
|
|
74
|
+
*/
|
|
75
|
+
async updateMapping<T = any>(templateName: string, payload: TemplateMapping) {
|
|
76
|
+
return this.put<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateName)}/mapping`, payload);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Validate mapping readiness.
|
|
81
|
+
*/
|
|
82
|
+
async validate<T = any>(templateName: string) {
|
|
83
|
+
return this.get<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateName)}/validate`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Preview a template resolution.
|
|
88
|
+
*/
|
|
89
|
+
async preview<T = any>(templateName: string, context: { lead?: any; vars?: any }) {
|
|
90
|
+
return this.post<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateName)}/preview`, { context });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Check automation usage of a template.
|
|
95
|
+
*/
|
|
96
|
+
async checkUsage<T = any>(templateName: string) {
|
|
97
|
+
return this.get<T>(`/api/saas/whatsapp/templates/${encodeURIComponent(templateName)}/usage`);
|
|
98
|
+
}
|
|
99
|
+
}
|