lua-cli 3.1.0-alpha.3 → 3.1.0-alpha.4
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 +0 -4
- package/dist/api/job.api.service.d.ts +23 -100
- package/dist/api/job.api.service.js +13 -11
- package/dist/api/lazy-instances.d.ts +8 -0
- package/dist/api/lazy-instances.js +16 -0
- package/dist/api/postprocessor.api.service.d.ts +1 -8
- package/dist/api/postprocessor.api.service.js +1 -2
- package/dist/api/preprocessor.api.service.d.ts +1 -8
- package/dist/api/preprocessor.api.service.js +1 -2
- package/dist/api/webhook.api.service.d.ts +1 -3
- package/dist/api/webhook.api.service.js +1 -1
- package/dist/api/whatsapp-templates.api.service.d.ts +40 -0
- package/dist/api/whatsapp-templates.api.service.js +78 -0
- package/dist/api-exports.d.ts +81 -2
- package/dist/api-exports.js +91 -15
- package/dist/commands/chat.js +2 -4
- package/dist/commands/init.js +11 -44
- package/dist/commands/jobs.js +5 -5
- package/dist/commands/push.js +2 -9
- package/dist/common/job.instance.d.ts +35 -7
- package/dist/common/job.instance.js +46 -19
- package/dist/interfaces/agent.d.ts +0 -3
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/init.d.ts +0 -1
- package/dist/interfaces/jobs.d.ts +88 -132
- package/dist/interfaces/jobs.js +1 -1
- package/dist/interfaces/postprocessors.d.ts +0 -3
- package/dist/interfaces/preprocessors.d.ts +0 -3
- package/dist/interfaces/webhooks.d.ts +0 -5
- package/dist/interfaces/whatsapp-templates.d.ts +104 -0
- package/dist/interfaces/whatsapp-templates.js +5 -0
- package/dist/types/api-contracts.d.ts +32 -0
- package/dist/types/compile.types.d.ts +0 -6
- package/dist/types/index.d.ts +1 -1
- package/dist/types/skill.d.ts +61 -90
- package/dist/types/skill.js +28 -86
- package/dist/utils/agent-management.d.ts +3 -5
- package/dist/utils/agent-management.js +6 -8
- package/dist/utils/bundling.js +5 -6
- package/dist/utils/compile.d.ts +0 -1
- package/dist/utils/compile.js +1 -51
- package/dist/utils/deployment.js +0 -1
- package/dist/utils/dev-api.js +0 -2
- package/dist/utils/files.d.ts +3 -3
- package/dist/utils/files.js +4 -12
- package/dist/utils/init-agent.d.ts +1 -2
- package/dist/utils/init-agent.js +4 -6
- package/dist/utils/init-helpers.d.ts +2 -4
- package/dist/utils/init-helpers.js +4 -10
- package/dist/utils/job-management.js +0 -2
- package/dist/utils/postprocessor-management.js +2 -4
- package/dist/utils/preprocessor-management.js +2 -4
- package/dist/utils/sandbox.js +17 -7
- package/dist/utils/webhook-management.js +1 -3
- package/package.json +1 -1
- package/template/QUICKSTART.md +0 -13
- package/template/README.md +6 -7
- package/template/src/jobs/AbandonedBasketProcessorJob.ts +0 -3
- package/template/src/jobs/DailyCleanupJob.ts +0 -3
- package/template/src/jobs/DataMigrationJob.ts +0 -3
- package/template/src/jobs/HealthCheckJob.ts +0 -3
- package/template/src/postprocessors/modifyResponse.ts +0 -1
- package/template/src/preprocessors/messageMatching.ts +18 -5
- package/template/src/skills/basket.skill.ts +0 -1
- package/template/src/skills/product.skill.ts +0 -1
- package/template/src/skills/user.skill.ts +0 -1
- package/template/src/webhooks/PaymentWebhook.ts +12 -9
- package/template/src/webhooks/UserEventWebhook.ts +39 -11
package/README.md
CHANGED
|
@@ -105,7 +105,6 @@ import { LuaAgent, LuaSkill, LuaWebhook, LuaJob } from 'lua-cli';
|
|
|
105
105
|
export const agent = new LuaAgent({
|
|
106
106
|
name: 'my-assistant',
|
|
107
107
|
persona: 'You are a helpful AI assistant...',
|
|
108
|
-
welcomeMessage: 'Hello! How can I help you today?',
|
|
109
108
|
|
|
110
109
|
skills: [customerSupportSkill, productSkill],
|
|
111
110
|
webhooks: [paymentWebhook],
|
|
@@ -166,7 +165,6 @@ import { z } from 'zod';
|
|
|
166
165
|
|
|
167
166
|
export default new LuaWebhook({
|
|
168
167
|
name: 'payment-webhook',
|
|
169
|
-
version: '1.0.0',
|
|
170
168
|
description: 'Handle payment notifications',
|
|
171
169
|
|
|
172
170
|
bodySchema: z.object({
|
|
@@ -194,7 +192,6 @@ import { LuaJob } from 'lua-cli';
|
|
|
194
192
|
|
|
195
193
|
export default new LuaJob({
|
|
196
194
|
name: 'daily-cleanup',
|
|
197
|
-
version: '1.0.0',
|
|
198
195
|
description: 'Clean up old data daily',
|
|
199
196
|
|
|
200
197
|
schedule: {
|
|
@@ -564,7 +561,6 @@ agent:
|
|
|
564
561
|
orgId: your-org-id
|
|
565
562
|
persona: |
|
|
566
563
|
You are a helpful AI assistant...
|
|
567
|
-
welcomeMessage: Hello! How can I help you today?
|
|
568
564
|
|
|
569
565
|
skills:
|
|
570
566
|
- name: general-skill
|
|
@@ -1,69 +1,7 @@
|
|
|
1
1
|
import { HttpClient } from "../common/http.client.js";
|
|
2
2
|
import { ApiResponse } from "../interfaces/common.js";
|
|
3
|
-
import { CreateJobDTO, PushJobVersionDTO, UpdateJobVersionDTO } from "../interfaces/jobs.js";
|
|
3
|
+
import { CreateJobDTO, Job, JobVersion, JobExecution, PushJobVersionDTO, UpdateJobVersionDTO, GetJobsResponseData, GetJobExecutionsResponseData, DeleteJobResponseData, UpdateJobMetadataResponseData } from "../interfaces/jobs.js";
|
|
4
4
|
import { JobInstance } from "../common/job.instance.js";
|
|
5
|
-
/**
|
|
6
|
-
* Job API Response Types
|
|
7
|
-
*/
|
|
8
|
-
export interface JobVersion {
|
|
9
|
-
version: string;
|
|
10
|
-
jobId: string;
|
|
11
|
-
createdAt: string | number;
|
|
12
|
-
isActive?: boolean;
|
|
13
|
-
schedule?: any;
|
|
14
|
-
timeout?: number;
|
|
15
|
-
retry?: {
|
|
16
|
-
maxAttempts: number;
|
|
17
|
-
backoffSeconds?: number;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export interface GetJobsResponse {
|
|
21
|
-
jobs: Array<{
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
context?: string;
|
|
26
|
-
versions: JobVersion[];
|
|
27
|
-
activeVersionId?: string;
|
|
28
|
-
lastRunAt?: string;
|
|
29
|
-
nextRunAt?: string;
|
|
30
|
-
status?: 'active' | 'paused' | 'failed';
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
export interface CreateJobResponse {
|
|
34
|
-
id: string;
|
|
35
|
-
name: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
agentId: string;
|
|
38
|
-
context?: string;
|
|
39
|
-
}
|
|
40
|
-
export interface JobVersionResponse {
|
|
41
|
-
versionId: string;
|
|
42
|
-
jobId: string;
|
|
43
|
-
version: string;
|
|
44
|
-
createdAt: string;
|
|
45
|
-
schedule: any;
|
|
46
|
-
}
|
|
47
|
-
export interface UpdateJobVersionResponse {
|
|
48
|
-
versionId: string;
|
|
49
|
-
jobId: string;
|
|
50
|
-
version: string;
|
|
51
|
-
updatedAt: string;
|
|
52
|
-
}
|
|
53
|
-
export interface DeleteJobResponse {
|
|
54
|
-
deleted: boolean;
|
|
55
|
-
deactivated?: boolean;
|
|
56
|
-
message: string;
|
|
57
|
-
}
|
|
58
|
-
export interface JobExecutionResponse {
|
|
59
|
-
executionId: string;
|
|
60
|
-
jobId: string;
|
|
61
|
-
startedAt: string;
|
|
62
|
-
completedAt?: string;
|
|
63
|
-
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
64
|
-
result?: any;
|
|
65
|
-
error?: string;
|
|
66
|
-
}
|
|
67
5
|
/**
|
|
68
6
|
* Job API Service
|
|
69
7
|
* Handles all job-related API calls
|
|
@@ -85,7 +23,7 @@ export default class JobApi extends HttpClient {
|
|
|
85
23
|
*/
|
|
86
24
|
getJobs(options?: {
|
|
87
25
|
includeDynamic?: boolean;
|
|
88
|
-
}): Promise<ApiResponse<
|
|
26
|
+
}): Promise<ApiResponse<GetJobsResponseData>>;
|
|
89
27
|
/**
|
|
90
28
|
* Retrieves a job by its unique identifier
|
|
91
29
|
* @param jobId - The unique identifier of the job to retrieve
|
|
@@ -100,10 +38,10 @@ export default class JobApi extends HttpClient {
|
|
|
100
38
|
* @param jobData - The job data including name, description, schedule, and optional version
|
|
101
39
|
* @param jobData.version - If provided, creates first version automatically
|
|
102
40
|
* @param jobData.activate - If true, activates the job immediately
|
|
103
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
41
|
+
* @returns Promise resolving to an ApiResponse containing the full job with versions
|
|
104
42
|
* @throws Error if the job creation fails or validation errors occur
|
|
105
43
|
*/
|
|
106
|
-
createJob(jobData: CreateJobDTO): Promise<ApiResponse<
|
|
44
|
+
createJob(jobData: CreateJobDTO): Promise<ApiResponse<Job>>;
|
|
107
45
|
/**
|
|
108
46
|
* Creates a new job for the agent and returns a JobInstance.
|
|
109
47
|
* Supports automatic version creation and activation.
|
|
@@ -120,50 +58,42 @@ export default class JobApi extends HttpClient {
|
|
|
120
58
|
* Pushes a new version of a job to production
|
|
121
59
|
* @param jobId - The unique identifier of the job
|
|
122
60
|
* @param versionData - The version data including code, configuration, and metadata
|
|
123
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
61
|
+
* @returns Promise resolving to an ApiResponse containing the full job version
|
|
124
62
|
* @throws Error if the job is not found or the push operation fails
|
|
125
63
|
*/
|
|
126
|
-
pushJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<
|
|
64
|
+
pushJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<JobVersion>>;
|
|
127
65
|
/**
|
|
128
66
|
* Pushes a new development/sandbox version of a job for testing
|
|
129
67
|
* @param jobId - The unique identifier of the job
|
|
130
68
|
* @param versionData - The version data including code, configuration, and metadata
|
|
131
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
69
|
+
* @returns Promise resolving to an ApiResponse containing the full job version
|
|
132
70
|
* @throws Error if the job is not found or the push operation fails
|
|
133
71
|
*/
|
|
134
|
-
pushDevJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<
|
|
72
|
+
pushDevJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<JobVersion>>;
|
|
135
73
|
/**
|
|
136
74
|
* Updates an existing development/sandbox version of a job
|
|
137
75
|
* @param jobId - The unique identifier of the job
|
|
138
76
|
* @param sandboxVersionId - The unique identifier of the sandbox version to update
|
|
139
77
|
* @param versionData - The updated version data including code, configuration, and metadata
|
|
140
|
-
* @returns Promise resolving to an ApiResponse containing the updated version
|
|
78
|
+
* @returns Promise resolving to an ApiResponse containing the full updated job version
|
|
141
79
|
* @throws Error if the job or version is not found or the update fails
|
|
142
80
|
*/
|
|
143
|
-
updateDevJob(jobId: string, sandboxVersionId: string, versionData: UpdateJobVersionDTO): Promise<ApiResponse<
|
|
81
|
+
updateDevJob(jobId: string, sandboxVersionId: string, versionData: UpdateJobVersionDTO): Promise<ApiResponse<JobVersion>>;
|
|
144
82
|
/**
|
|
145
83
|
* Retrieves all versions of a specific job
|
|
146
84
|
* @param jobId - The unique identifier of the job
|
|
147
85
|
* @returns Promise resolving to an ApiResponse containing an array of job versions
|
|
148
86
|
* @throws Error if the job is not found or the request fails
|
|
149
87
|
*/
|
|
150
|
-
getJobVersions(jobId: string): Promise<ApiResponse<
|
|
151
|
-
versions: JobVersion[];
|
|
152
|
-
activeVersionId?: string;
|
|
153
|
-
}>>;
|
|
88
|
+
getJobVersions(jobId: string): Promise<ApiResponse<JobVersion[]>>;
|
|
154
89
|
/**
|
|
155
90
|
* Publishes a specific version of a job to production
|
|
156
91
|
* @param jobId - The unique identifier of the job
|
|
157
92
|
* @param version - The version identifier to publish
|
|
158
|
-
* @returns Promise resolving to an ApiResponse containing
|
|
93
|
+
* @returns Promise resolving to an ApiResponse containing the full updated job
|
|
159
94
|
* @throws Error if the job or version is not found or the publish operation fails
|
|
160
95
|
*/
|
|
161
|
-
publishJobVersion(jobId: string, version: string): Promise<ApiResponse<
|
|
162
|
-
message: string;
|
|
163
|
-
jobId: string;
|
|
164
|
-
activeVersionId: string;
|
|
165
|
-
publishedAt: string;
|
|
166
|
-
}>>;
|
|
96
|
+
publishJobVersion(jobId: string, version: string): Promise<ApiResponse<Job>>;
|
|
167
97
|
/**
|
|
168
98
|
* Deletes a job and all its versions, or deactivates it if it has versions
|
|
169
99
|
* @param jobId - The unique identifier of the job to delete
|
|
@@ -172,34 +102,29 @@ export default class JobApi extends HttpClient {
|
|
|
172
102
|
* - If deleted is false and deactivated is true: job has versions and was deactivated instead
|
|
173
103
|
* @throws Error if the job is not found or the delete operation fails
|
|
174
104
|
*/
|
|
175
|
-
deleteJob(jobId: string): Promise<ApiResponse<
|
|
105
|
+
deleteJob(jobId: string): Promise<ApiResponse<DeleteJobResponseData>>;
|
|
176
106
|
/**
|
|
177
107
|
* Activates a job (enables it to run on schedule)
|
|
178
108
|
* @param jobId - The unique identifier of the job to activate
|
|
179
|
-
* @returns Promise resolving to an ApiResponse with
|
|
109
|
+
* @returns Promise resolving to an ApiResponse with the full updated job
|
|
180
110
|
* @throws Error if the job is not found or the operation fails
|
|
181
111
|
*/
|
|
182
|
-
activateJob(jobId: string): Promise<ApiResponse<
|
|
183
|
-
message: string;
|
|
184
|
-
active: boolean;
|
|
185
|
-
}>>;
|
|
112
|
+
activateJob(jobId: string): Promise<ApiResponse<Job>>;
|
|
186
113
|
/**
|
|
187
114
|
* Deactivates a job (disables it from running)
|
|
188
115
|
* @param jobId - The unique identifier of the job to deactivate
|
|
189
|
-
* @returns Promise resolving to an ApiResponse with
|
|
116
|
+
* @returns Promise resolving to an ApiResponse with the full updated job
|
|
190
117
|
* @throws Error if the job is not found or the operation fails
|
|
191
118
|
*/
|
|
192
|
-
deactivateJob(jobId: string): Promise<ApiResponse<
|
|
193
|
-
message: string;
|
|
194
|
-
active: boolean;
|
|
195
|
-
}>>;
|
|
119
|
+
deactivateJob(jobId: string): Promise<ApiResponse<Job>>;
|
|
196
120
|
/**
|
|
197
121
|
* Manually triggers a job execution (ignores schedule)
|
|
198
122
|
* @param jobId - The unique identifier of the job to trigger
|
|
199
|
-
* @
|
|
123
|
+
* @param versionId - The version identifier to execute (optional, defaults to activeVersionId)
|
|
124
|
+
* @returns Promise resolving to an ApiResponse with the execution record
|
|
200
125
|
* @throws Error if the job is not found or the operation fails
|
|
201
126
|
*/
|
|
202
|
-
triggerJob(jobId: string): Promise<ApiResponse<
|
|
127
|
+
triggerJob(jobId: string, versionId?: string): Promise<ApiResponse<JobExecution>>;
|
|
203
128
|
/**
|
|
204
129
|
* Retrieves execution history for a job
|
|
205
130
|
* @param jobId - The unique identifier of the job
|
|
@@ -207,9 +132,7 @@ export default class JobApi extends HttpClient {
|
|
|
207
132
|
* @returns Promise resolving to an ApiResponse with execution history
|
|
208
133
|
* @throws Error if the job is not found or the request fails
|
|
209
134
|
*/
|
|
210
|
-
getJobExecutions(jobId: string, limit?: number): Promise<ApiResponse<
|
|
211
|
-
executions: JobExecutionResponse[];
|
|
212
|
-
}>>;
|
|
135
|
+
getJobExecutions(jobId: string, limit?: number): Promise<ApiResponse<GetJobExecutionsResponseData>>;
|
|
213
136
|
/**
|
|
214
137
|
* Updates the metadata of a job
|
|
215
138
|
* @param jobId - The unique identifier of the job
|
|
@@ -217,5 +140,5 @@ export default class JobApi extends HttpClient {
|
|
|
217
140
|
* @returns Promise resolving to the updated metadata
|
|
218
141
|
* @throws Error if the job is not found or the metadata update fails
|
|
219
142
|
*/
|
|
220
|
-
updateMetadata(jobId: string, metadata: any): Promise<ApiResponse<
|
|
143
|
+
updateMetadata(jobId: string, metadata: Record<string, any>): Promise<ApiResponse<UpdateJobMetadataResponseData>>;
|
|
221
144
|
}
|
|
@@ -54,7 +54,7 @@ export default class JobApi extends HttpClient {
|
|
|
54
54
|
* @param jobData - The job data including name, description, schedule, and optional version
|
|
55
55
|
* @param jobData.version - If provided, creates first version automatically
|
|
56
56
|
* @param jobData.activate - If true, activates the job immediately
|
|
57
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
57
|
+
* @returns Promise resolving to an ApiResponse containing the full job with versions
|
|
58
58
|
* @throws Error if the job creation fails or validation errors occur
|
|
59
59
|
*/
|
|
60
60
|
async createJob(jobData) {
|
|
@@ -92,7 +92,7 @@ export default class JobApi extends HttpClient {
|
|
|
92
92
|
* Pushes a new version of a job to production
|
|
93
93
|
* @param jobId - The unique identifier of the job
|
|
94
94
|
* @param versionData - The version data including code, configuration, and metadata
|
|
95
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
95
|
+
* @returns Promise resolving to an ApiResponse containing the full job version
|
|
96
96
|
* @throws Error if the job is not found or the push operation fails
|
|
97
97
|
*/
|
|
98
98
|
async pushJob(jobId, versionData) {
|
|
@@ -104,7 +104,7 @@ export default class JobApi extends HttpClient {
|
|
|
104
104
|
* Pushes a new development/sandbox version of a job for testing
|
|
105
105
|
* @param jobId - The unique identifier of the job
|
|
106
106
|
* @param versionData - The version data including code, configuration, and metadata
|
|
107
|
-
* @returns Promise resolving to an ApiResponse containing the
|
|
107
|
+
* @returns Promise resolving to an ApiResponse containing the full job version
|
|
108
108
|
* @throws Error if the job is not found or the push operation fails
|
|
109
109
|
*/
|
|
110
110
|
async pushDevJob(jobId, versionData) {
|
|
@@ -117,7 +117,7 @@ export default class JobApi extends HttpClient {
|
|
|
117
117
|
* @param jobId - The unique identifier of the job
|
|
118
118
|
* @param sandboxVersionId - The unique identifier of the sandbox version to update
|
|
119
119
|
* @param versionData - The updated version data including code, configuration, and metadata
|
|
120
|
-
* @returns Promise resolving to an ApiResponse containing the updated version
|
|
120
|
+
* @returns Promise resolving to an ApiResponse containing the full updated job version
|
|
121
121
|
* @throws Error if the job or version is not found or the update fails
|
|
122
122
|
*/
|
|
123
123
|
async updateDevJob(jobId, sandboxVersionId, versionData) {
|
|
@@ -140,11 +140,11 @@ export default class JobApi extends HttpClient {
|
|
|
140
140
|
* Publishes a specific version of a job to production
|
|
141
141
|
* @param jobId - The unique identifier of the job
|
|
142
142
|
* @param version - The version identifier to publish
|
|
143
|
-
* @returns Promise resolving to an ApiResponse containing
|
|
143
|
+
* @returns Promise resolving to an ApiResponse containing the full updated job
|
|
144
144
|
* @throws Error if the job or version is not found or the publish operation fails
|
|
145
145
|
*/
|
|
146
146
|
async publishJobVersion(jobId, version) {
|
|
147
|
-
return this.
|
|
147
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/${version}/publish`, {}, {
|
|
148
148
|
Authorization: `Bearer ${this.apiKey}`,
|
|
149
149
|
});
|
|
150
150
|
}
|
|
@@ -164,7 +164,7 @@ export default class JobApi extends HttpClient {
|
|
|
164
164
|
/**
|
|
165
165
|
* Activates a job (enables it to run on schedule)
|
|
166
166
|
* @param jobId - The unique identifier of the job to activate
|
|
167
|
-
* @returns Promise resolving to an ApiResponse with
|
|
167
|
+
* @returns Promise resolving to an ApiResponse with the full updated job
|
|
168
168
|
* @throws Error if the job is not found or the operation fails
|
|
169
169
|
*/
|
|
170
170
|
async activateJob(jobId) {
|
|
@@ -175,7 +175,7 @@ export default class JobApi extends HttpClient {
|
|
|
175
175
|
/**
|
|
176
176
|
* Deactivates a job (disables it from running)
|
|
177
177
|
* @param jobId - The unique identifier of the job to deactivate
|
|
178
|
-
* @returns Promise resolving to an ApiResponse with
|
|
178
|
+
* @returns Promise resolving to an ApiResponse with the full updated job
|
|
179
179
|
* @throws Error if the job is not found or the operation fails
|
|
180
180
|
*/
|
|
181
181
|
async deactivateJob(jobId) {
|
|
@@ -186,11 +186,13 @@ export default class JobApi extends HttpClient {
|
|
|
186
186
|
/**
|
|
187
187
|
* Manually triggers a job execution (ignores schedule)
|
|
188
188
|
* @param jobId - The unique identifier of the job to trigger
|
|
189
|
-
* @
|
|
189
|
+
* @param versionId - The version identifier to execute (optional, defaults to activeVersionId)
|
|
190
|
+
* @returns Promise resolving to an ApiResponse with the execution record
|
|
190
191
|
* @throws Error if the job is not found or the operation fails
|
|
191
192
|
*/
|
|
192
|
-
async triggerJob(jobId) {
|
|
193
|
-
|
|
193
|
+
async triggerJob(jobId, versionId) {
|
|
194
|
+
const body = versionId ? { versionId } : {};
|
|
195
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/trigger`, body, {
|
|
194
196
|
Authorization: `Bearer ${this.apiKey}`,
|
|
195
197
|
});
|
|
196
198
|
}
|
|
@@ -10,6 +10,7 @@ import CustomDataApiService from "./custom.data.api.service.js";
|
|
|
10
10
|
import WebhookApi from "./webhook.api.service.js";
|
|
11
11
|
import JobApi from "./job.api.service.js";
|
|
12
12
|
import ChatApi from "./chat.api.service.js";
|
|
13
|
+
import WhatsAppTemplatesApiService from "./whatsapp-templates.api.service.js";
|
|
13
14
|
/**
|
|
14
15
|
* Gets or creates User Data API instance.
|
|
15
16
|
* Instance is created once and reused for subsequent calls.
|
|
@@ -66,6 +67,13 @@ export declare function getJobInstance(): Promise<JobApi>;
|
|
|
66
67
|
* @returns ChatApi instance
|
|
67
68
|
*/
|
|
68
69
|
export declare function getChatInstance(): Promise<ChatApi>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets or creates Templates API instance.
|
|
72
|
+
* Instance is created once and reused for subsequent calls.
|
|
73
|
+
*
|
|
74
|
+
* @returns WhatsAppTemplatesApiService instance
|
|
75
|
+
*/
|
|
76
|
+
export declare function getWhatsAppTemplatesInstance(): Promise<WhatsAppTemplatesApiService>;
|
|
69
77
|
/**
|
|
70
78
|
* Clears all cached API instances.
|
|
71
79
|
* Useful for testing or when credentials change.
|
|
@@ -12,6 +12,7 @@ import CustomDataApiService from "./custom.data.api.service.js";
|
|
|
12
12
|
import WebhookApi from "./webhook.api.service.js";
|
|
13
13
|
import JobApi from "./job.api.service.js";
|
|
14
14
|
import ChatApi from "./chat.api.service.js";
|
|
15
|
+
import WhatsAppTemplatesApiService from "./whatsapp-templates.api.service.js";
|
|
15
16
|
/**
|
|
16
17
|
* Singleton instances (lazy-loaded)
|
|
17
18
|
*/
|
|
@@ -23,6 +24,7 @@ let _orderInstance = null;
|
|
|
23
24
|
let _webhookInstance = null;
|
|
24
25
|
let _jobInstance = null;
|
|
25
26
|
let _chatInstance = null;
|
|
27
|
+
let _whatsAppTemplatesInstance = null;
|
|
26
28
|
/**
|
|
27
29
|
* Gets or creates User Data API instance.
|
|
28
30
|
* Instance is created once and reused for subsequent calls.
|
|
@@ -127,6 +129,19 @@ export async function getChatInstance() {
|
|
|
127
129
|
}
|
|
128
130
|
return _chatInstance;
|
|
129
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Gets or creates Templates API instance.
|
|
134
|
+
* Instance is created once and reused for subsequent calls.
|
|
135
|
+
*
|
|
136
|
+
* @returns WhatsAppTemplatesApiService instance
|
|
137
|
+
*/
|
|
138
|
+
export async function getWhatsAppTemplatesInstance() {
|
|
139
|
+
if (!_whatsAppTemplatesInstance) {
|
|
140
|
+
const creds = await getCredentials();
|
|
141
|
+
_whatsAppTemplatesInstance = new WhatsAppTemplatesApiService(BASE_URLS.API, creds.apiKey, creds.agentId);
|
|
142
|
+
}
|
|
143
|
+
return _whatsAppTemplatesInstance;
|
|
144
|
+
}
|
|
130
145
|
/**
|
|
131
146
|
* Clears all cached API instances.
|
|
132
147
|
* Useful for testing or when credentials change.
|
|
@@ -140,4 +155,5 @@ export function clearAllInstances() {
|
|
|
140
155
|
_webhookInstance = null;
|
|
141
156
|
_jobInstance = null;
|
|
142
157
|
_chatInstance = null;
|
|
158
|
+
_whatsAppTemplatesInstance = null;
|
|
143
159
|
}
|
|
@@ -14,7 +14,6 @@ export interface GetPostProcessorsResponse {
|
|
|
14
14
|
id: string;
|
|
15
15
|
name: string;
|
|
16
16
|
description?: string;
|
|
17
|
-
context?: string;
|
|
18
17
|
versions: PostProcessorVersion[];
|
|
19
18
|
activeVersionId?: string;
|
|
20
19
|
}>;
|
|
@@ -24,7 +23,6 @@ export interface CreatePostProcessorResponse {
|
|
|
24
23
|
name: string;
|
|
25
24
|
description?: string;
|
|
26
25
|
agentId: string;
|
|
27
|
-
context?: string;
|
|
28
26
|
}
|
|
29
27
|
export interface PostProcessorVersionResponse {
|
|
30
28
|
versionId: string;
|
|
@@ -55,25 +53,22 @@ export default class PostProcessorApi extends HttpClient {
|
|
|
55
53
|
createPostProcessor(data: {
|
|
56
54
|
name: string;
|
|
57
55
|
description?: string;
|
|
58
|
-
context?: string;
|
|
59
56
|
}): Promise<ApiResponse<CreatePostProcessorResponse>>;
|
|
60
57
|
/**
|
|
61
58
|
* Pushes a new version of a postprocessor
|
|
62
59
|
*
|
|
63
60
|
* @param postprocessorId - The postprocessor ID
|
|
64
|
-
* @param versionData - Version data including code, description,
|
|
61
|
+
* @param versionData - Version data including code, description, and async flag
|
|
65
62
|
* @param versionData.version - Version number
|
|
66
63
|
* @param versionData.code - Compressed execute function code
|
|
67
64
|
* @param versionData.executeFunction - Raw execute function code
|
|
68
65
|
* @param versionData.description - Postprocessor description
|
|
69
|
-
* @param versionData.context - Postprocessor context
|
|
70
66
|
* @param versionData.async - Async execution flag (true = background, false = blocking)
|
|
71
67
|
*/
|
|
72
68
|
pushPostProcessor(postprocessorId: string, versionData: {
|
|
73
69
|
name: string;
|
|
74
70
|
version: string;
|
|
75
71
|
description?: string;
|
|
76
|
-
context?: string;
|
|
77
72
|
postprocessorId: string;
|
|
78
73
|
code: string;
|
|
79
74
|
executeFunction: string;
|
|
@@ -125,7 +120,6 @@ export default class PostProcessorApi extends HttpClient {
|
|
|
125
120
|
name: string;
|
|
126
121
|
version?: string;
|
|
127
122
|
description?: string;
|
|
128
|
-
context?: string;
|
|
129
123
|
code: string;
|
|
130
124
|
executeFunction: string;
|
|
131
125
|
async?: boolean;
|
|
@@ -147,7 +141,6 @@ export default class PostProcessorApi extends HttpClient {
|
|
|
147
141
|
name: string;
|
|
148
142
|
version?: string;
|
|
149
143
|
description?: string;
|
|
150
|
-
context?: string;
|
|
151
144
|
code: string;
|
|
152
145
|
executeFunction: string;
|
|
153
146
|
async?: boolean;
|
|
@@ -29,12 +29,11 @@ export default class PostProcessorApi extends HttpClient {
|
|
|
29
29
|
* Pushes a new version of a postprocessor
|
|
30
30
|
*
|
|
31
31
|
* @param postprocessorId - The postprocessor ID
|
|
32
|
-
* @param versionData - Version data including code, description,
|
|
32
|
+
* @param versionData - Version data including code, description, and async flag
|
|
33
33
|
* @param versionData.version - Version number
|
|
34
34
|
* @param versionData.code - Compressed execute function code
|
|
35
35
|
* @param versionData.executeFunction - Raw execute function code
|
|
36
36
|
* @param versionData.description - Postprocessor description
|
|
37
|
-
* @param versionData.context - Postprocessor context
|
|
38
37
|
* @param versionData.async - Async execution flag (true = background, false = blocking)
|
|
39
38
|
*/
|
|
40
39
|
async pushPostProcessor(postprocessorId, versionData) {
|
|
@@ -14,7 +14,6 @@ export interface GetPreProcessorsResponse {
|
|
|
14
14
|
id: string;
|
|
15
15
|
name: string;
|
|
16
16
|
description?: string;
|
|
17
|
-
context?: string;
|
|
18
17
|
versions: PreProcessorVersion[];
|
|
19
18
|
activeVersionId?: string;
|
|
20
19
|
}>;
|
|
@@ -24,7 +23,6 @@ export interface CreatePreProcessorResponse {
|
|
|
24
23
|
name: string;
|
|
25
24
|
description?: string;
|
|
26
25
|
agentId: string;
|
|
27
|
-
context?: string;
|
|
28
26
|
}
|
|
29
27
|
export interface PreProcessorVersionResponse {
|
|
30
28
|
versionId: string;
|
|
@@ -55,25 +53,22 @@ export default class PreProcessorApi extends HttpClient {
|
|
|
55
53
|
createPreProcessor(data: {
|
|
56
54
|
name: string;
|
|
57
55
|
description?: string;
|
|
58
|
-
context?: string;
|
|
59
56
|
}): Promise<ApiResponse<CreatePreProcessorResponse>>;
|
|
60
57
|
/**
|
|
61
58
|
* Pushes a new version of a preprocessor
|
|
62
59
|
*
|
|
63
60
|
* @param preprocessorId - The preprocessor ID
|
|
64
|
-
* @param versionData - Version data including code, description,
|
|
61
|
+
* @param versionData - Version data including code, description, and async flag
|
|
65
62
|
* @param versionData.version - Version number
|
|
66
63
|
* @param versionData.code - Compressed execute function code
|
|
67
64
|
* @param versionData.executeFunction - Raw execute function code
|
|
68
65
|
* @param versionData.description - Preprocessor description
|
|
69
|
-
* @param versionData.context - Preprocessor context
|
|
70
66
|
* @param versionData.async - Async execution flag (true = background, false = blocking)
|
|
71
67
|
*/
|
|
72
68
|
pushPreProcessor(preprocessorId: string, versionData: {
|
|
73
69
|
name: string;
|
|
74
70
|
version: string;
|
|
75
71
|
description?: string;
|
|
76
|
-
context?: string;
|
|
77
72
|
preprocessorId: string;
|
|
78
73
|
code: string;
|
|
79
74
|
executeFunction: string;
|
|
@@ -125,7 +120,6 @@ export default class PreProcessorApi extends HttpClient {
|
|
|
125
120
|
name: string;
|
|
126
121
|
version?: string;
|
|
127
122
|
description?: string;
|
|
128
|
-
context?: string;
|
|
129
123
|
code: string;
|
|
130
124
|
executeFunction: string;
|
|
131
125
|
async?: boolean;
|
|
@@ -147,7 +141,6 @@ export default class PreProcessorApi extends HttpClient {
|
|
|
147
141
|
name: string;
|
|
148
142
|
version?: string;
|
|
149
143
|
description?: string;
|
|
150
|
-
context?: string;
|
|
151
144
|
code: string;
|
|
152
145
|
executeFunction: string;
|
|
153
146
|
async?: boolean;
|
|
@@ -29,12 +29,11 @@ export default class PreProcessorApi extends HttpClient {
|
|
|
29
29
|
* Pushes a new version of a preprocessor
|
|
30
30
|
*
|
|
31
31
|
* @param preprocessorId - The preprocessor ID
|
|
32
|
-
* @param versionData - Version data including code, description,
|
|
32
|
+
* @param versionData - Version data including code, description, and async flag
|
|
33
33
|
* @param versionData.version - Version number
|
|
34
34
|
* @param versionData.code - Compressed execute function code
|
|
35
35
|
* @param versionData.executeFunction - Raw execute function code
|
|
36
36
|
* @param versionData.description - Preprocessor description
|
|
37
|
-
* @param versionData.context - Preprocessor context
|
|
38
37
|
* @param versionData.async - Async execution flag (true = background, false = blocking)
|
|
39
38
|
*/
|
|
40
39
|
async pushPreProcessor(preprocessorId, versionData) {
|
|
@@ -15,7 +15,6 @@ export interface GetWebhooksResponse {
|
|
|
15
15
|
id: string;
|
|
16
16
|
name: string;
|
|
17
17
|
description?: string;
|
|
18
|
-
context?: string;
|
|
19
18
|
versions: WebhookVersion[];
|
|
20
19
|
activeVersionId?: string;
|
|
21
20
|
}>;
|
|
@@ -25,7 +24,6 @@ export interface CreateWebhookResponse {
|
|
|
25
24
|
name: string;
|
|
26
25
|
description?: string;
|
|
27
26
|
agentId: string;
|
|
28
|
-
context?: string;
|
|
29
27
|
}
|
|
30
28
|
export interface WebhookVersionResponse {
|
|
31
29
|
versionId: string;
|
|
@@ -66,7 +64,7 @@ export default class WebhookApi extends HttpClient {
|
|
|
66
64
|
getWebhooks(): Promise<ApiResponse<GetWebhooksResponse>>;
|
|
67
65
|
/**
|
|
68
66
|
* Creates a new webhook for the agent
|
|
69
|
-
* @param webhookData - The webhook data including name
|
|
67
|
+
* @param webhookData - The webhook data including name and description
|
|
70
68
|
* @returns Promise resolving to an ApiResponse containing the created webhook details
|
|
71
69
|
* @throws Error if the webhook creation fails or validation errors occur
|
|
72
70
|
*/
|
|
@@ -27,7 +27,7 @@ export default class WebhookApi extends HttpClient {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Creates a new webhook for the agent
|
|
30
|
-
* @param webhookData - The webhook data including name
|
|
30
|
+
* @param webhookData - The webhook data including name and description
|
|
31
31
|
* @returns Promise resolving to an ApiResponse containing the created webhook details
|
|
32
32
|
* @throws Error if the webhook creation fails or validation errors occur
|
|
33
33
|
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { HttpClient } from "../common/http.client.js";
|
|
2
|
+
import { WhatsAppTemplatesAPI } from "../types/index.js";
|
|
3
|
+
import { WhatsAppTemplate, PaginatedTemplatesResponse, ListTemplatesOptions, SendTemplateData, SendTemplateResponse } from "../interfaces/whatsapp-templates.js";
|
|
4
|
+
/**
|
|
5
|
+
* WhatsApp Templates API Service
|
|
6
|
+
* Handles WhatsApp template operations
|
|
7
|
+
*/
|
|
8
|
+
export default class WhatsAppTemplatesApiService extends HttpClient implements WhatsAppTemplatesAPI {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private agentId;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of WhatsAppTemplatesApiService
|
|
13
|
+
* @param baseUrl - The base URL for the API
|
|
14
|
+
* @param apiKey - The API key for authentication
|
|
15
|
+
* @param agentId - The unique identifier of the agent
|
|
16
|
+
*/
|
|
17
|
+
constructor(baseUrl: string, apiKey: string, agentId: string);
|
|
18
|
+
/**
|
|
19
|
+
* Lists WhatsApp templates for a channel with optional pagination and search
|
|
20
|
+
* @param channelId - The WhatsApp channel identifier
|
|
21
|
+
* @param options - Optional pagination and search options
|
|
22
|
+
* @returns Promise resolving to paginated templates response
|
|
23
|
+
*/
|
|
24
|
+
list(channelId: string, options?: ListTemplatesOptions): Promise<PaginatedTemplatesResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets a specific WhatsApp template by ID
|
|
27
|
+
* @param channelId - The WhatsApp channel identifier
|
|
28
|
+
* @param templateId - The template identifier
|
|
29
|
+
* @returns Promise resolving to the template
|
|
30
|
+
*/
|
|
31
|
+
get(channelId: string, templateId: string): Promise<WhatsAppTemplate>;
|
|
32
|
+
/**
|
|
33
|
+
* Sends a WhatsApp template message to one or more phone numbers
|
|
34
|
+
* @param channelId - The WhatsApp channel identifier
|
|
35
|
+
* @param templateId - The template identifier
|
|
36
|
+
* @param data - Send data including phone numbers and template values
|
|
37
|
+
* @returns Promise resolving to the send response with results and errors
|
|
38
|
+
*/
|
|
39
|
+
send(channelId: string, templateId: string, data: SendTemplateData): Promise<SendTemplateResponse>;
|
|
40
|
+
}
|