-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-resolver.ts
More file actions
88 lines (83 loc) · 1.7 KB
/
Copy pathexample-resolver.ts
File metadata and controls
88 lines (83 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bun
// Example template resolver script for whap
// Usage: bun run example-resolver.ts [template_name] --lang [language]
const name = process.argv[2]
const langIndex = process.argv.indexOf('--lang')
const language = langIndex > -1 ? process.argv[langIndex + 1] : 'en'
// Example: Return different templates based on name and language
const templates: Record<string, any> = {
welcome: {
en: {
name: 'welcome',
language: 'en',
category: 'UTILITY',
components: [
{
type: 'HEADER',
format: 'TEXT',
text: 'Welcome!',
},
{
type: 'BODY',
text: 'Hello {{1}}! Welcome to our service.',
},
],
variables: {
'1': {
description: 'User name',
example: 'John',
},
},
},
es: {
name: 'welcome',
language: 'es',
category: 'UTILITY',
components: [
{
type: 'HEADER',
format: 'TEXT',
text: '¡Bienvenido!',
},
{
type: 'BODY',
text: 'Hola {{1}}! Bienvenido a nuestro servicio.',
},
],
variables: {
'1': {
description: 'Nombre de usuario',
example: 'Juan',
},
},
},
},
notification: {
en: {
name: 'notification',
language: 'en',
category: 'MARKETING',
components: [
{
type: 'BODY',
text: 'You have a new notification: {{1}}',
},
],
variables: {
'1': {
description: 'Notification message',
example: 'Your order has been shipped',
},
},
},
},
}
// Get the template
const template = templates[name]?.[language] || templates[name]?.['en']
if (template) {
console.log(JSON.stringify(template))
} else {
// Return empty result if template not found
// The TemplateResolver will handle this as null
process.exit(1)
}