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
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* User Event Webhook Example
|
|
3
3
|
*
|
|
4
4
|
* This webhook receives user events from external systems (e.g., CRM, marketing tools).
|
|
5
|
-
* It validates incoming data
|
|
5
|
+
* It validates incoming data, stores events for processing, and can send template
|
|
6
|
+
* messages using the Templates API (currently supports WhatsApp templates).
|
|
6
7
|
*
|
|
7
|
-
* Webhook
|
|
8
|
+
* Webhook URLs:
|
|
9
|
+
* https://webhook.heylua.ai/{agentId}/{webhookId}
|
|
10
|
+
* https://webhook.heylua.ai/{agentId}/{webhook-name}
|
|
8
11
|
*/
|
|
9
12
|
|
|
10
|
-
import { LuaWebhook, Data } from "lua-cli";
|
|
13
|
+
import { LuaWebhook, Data, Templates } from "lua-cli";
|
|
11
14
|
import { z } from "zod";
|
|
12
15
|
|
|
13
16
|
const userEventWebhook = new LuaWebhook({
|
|
14
17
|
name: "user-events",
|
|
15
|
-
version: "1.0.0",
|
|
16
18
|
description: "Receives user events from external systems",
|
|
17
|
-
context: "This webhook handles user registration, profile updates, and deletion events. " +
|
|
18
|
-
"It validates the incoming data, stores events in the database, and can trigger follow-up actions.",
|
|
19
19
|
|
|
20
20
|
// Validate query parameters (optional source tracking)
|
|
21
21
|
querySchema: z.object({
|
|
@@ -35,17 +35,20 @@ const userEventWebhook = new LuaWebhook({
|
|
|
35
35
|
userId: z.string(),
|
|
36
36
|
email: z.string().email(),
|
|
37
37
|
name: z.string().optional(),
|
|
38
|
+
phoneNumber: z.string().optional(),
|
|
39
|
+
channelId: z.string().optional(),
|
|
38
40
|
metadata: z.record(z.any()).optional(),
|
|
39
41
|
timestamp: z.string()
|
|
40
42
|
}),
|
|
41
43
|
|
|
42
|
-
execute: async (
|
|
43
|
-
|
|
44
|
+
execute: async (event: any) => {
|
|
45
|
+
const { query, headers, body } = event;
|
|
46
|
+
console.log(`📥 Received ${body?.eventType} event for user:`, body?.email);
|
|
44
47
|
console.log(`📍 Source:`, query?.source || 'unknown');
|
|
45
48
|
|
|
46
49
|
// Security: Validate API key (in production, use env variable)
|
|
47
50
|
const expectedKey = process.env.WEBHOOK_API_KEY || 'your-secret-key';
|
|
48
|
-
if (headers['x-api-key'] !== expectedKey) {
|
|
51
|
+
if (headers?.['x-api-key'] !== expectedKey) {
|
|
49
52
|
throw new Error('Invalid API key');
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -58,16 +61,41 @@ const userEventWebhook = new LuaWebhook({
|
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
const result = await Data.create('user-events', eventData,
|
|
61
|
-
`${body
|
|
64
|
+
`${body?.eventType} ${body?.email} ${body?.name || ''}`
|
|
62
65
|
);
|
|
63
66
|
|
|
64
67
|
console.log('✅ Event stored successfully:', result.id);
|
|
65
68
|
|
|
69
|
+
// Example: Send welcome template on signup using Templates API
|
|
70
|
+
// Uses Templates.whatsapp namespace for WhatsApp templates
|
|
71
|
+
let templateResult = null;
|
|
72
|
+
if (body?.eventType === 'signup' && body?.phoneNumber && body?.channelId) {
|
|
73
|
+
try {
|
|
74
|
+
// Search for a welcome template
|
|
75
|
+
const response = await Templates.whatsapp.list(body.channelId, { search: 'welcome' });
|
|
76
|
+
const welcomeTemplate = response.templates.find((t: any) => t.status === 'APPROVED');
|
|
77
|
+
|
|
78
|
+
if (welcomeTemplate) {
|
|
79
|
+
// Send the template message
|
|
80
|
+
templateResult = await Templates.whatsapp.send(body.channelId, welcomeTemplate.id, {
|
|
81
|
+
phoneNumbers: [body.phoneNumber],
|
|
82
|
+
values: {
|
|
83
|
+
body: { name: body.name || 'there' }
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
console.log('📱 Welcome template sent:', templateResult.results[0]?.messages[0]?.id);
|
|
87
|
+
}
|
|
88
|
+
} catch (error: any) {
|
|
89
|
+
console.log('⚠️ Could not send welcome template:', error.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
// Return success response
|
|
67
94
|
return {
|
|
68
95
|
success: true,
|
|
69
96
|
eventId: result.id,
|
|
70
|
-
userId: body
|
|
97
|
+
userId: body?.userId,
|
|
98
|
+
templateSent: templateResult?.totalErrors === 0,
|
|
71
99
|
timestamp: new Date().toISOString()
|
|
72
100
|
};
|
|
73
101
|
}
|