lua-cli 3.5.0-alpha.3 → 3.5.0-beta.1
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 +137 -689
- package/dist/api/agent.api.service.d.ts +1 -8
- package/dist/api/agent.api.service.js +1 -11
- package/dist/api/agent.api.service.js.map +1 -1
- package/dist/api/auth.api.service.d.ts +1 -1
- package/dist/api/auth.api.service.js +1 -1
- package/dist/api/auth.api.service.js.map +1 -1
- package/dist/api/backup.api.service.d.ts +80 -0
- package/dist/api/backup.api.service.js +101 -0
- package/dist/api/backup.api.service.js.map +1 -0
- package/dist/api/basket.api.service.d.ts +4 -5
- package/dist/api/basket.api.service.js +13 -18
- package/dist/api/basket.api.service.js.map +1 -1
- package/dist/api/cdn.api.service.d.ts +2 -0
- package/dist/api/cdn.api.service.js +2 -0
- package/dist/api/cdn.api.service.js.map +1 -1
- package/dist/api/chat.api.service.d.ts +10 -2
- package/dist/api/chat.api.service.js +21 -2
- package/dist/api/chat.api.service.js.map +1 -1
- package/dist/api/credentials.js +5 -8
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/custom.data.api.service.d.ts +3 -3
- package/dist/api/custom.data.api.service.js +9 -10
- package/dist/api/custom.data.api.service.js.map +1 -1
- package/dist/api/developer.api.service.d.ts +1 -1
- package/dist/api/developer.api.service.js +1 -1
- package/dist/api/developer.api.service.js.map +1 -1
- package/dist/api/http.client.js.map +1 -0
- package/dist/api/job.api.service.d.ts +2 -2
- package/dist/api/job.api.service.js +2 -2
- package/dist/api/job.api.service.js.map +1 -1
- package/dist/api/logs.api.service.d.ts +1 -1
- package/dist/api/logs.api.service.js +1 -1
- package/dist/api/logs.api.service.js.map +1 -1
- package/dist/api/marketplace.api.service.d.ts +6 -6
- package/dist/api/marketplace.api.service.js.map +1 -1
- package/dist/api/order.api.service.d.ts +3 -4
- package/dist/api/order.api.service.js +8 -10
- package/dist/api/order.api.service.js.map +1 -1
- package/dist/api/persona.api.service.d.ts +1 -1
- package/dist/api/persona.api.service.js +1 -1
- package/dist/api/persona.api.service.js.map +1 -1
- package/dist/api/postprocessor.api.service.d.ts +1 -1
- package/dist/api/postprocessor.api.service.js +1 -1
- package/dist/api/postprocessor.api.service.js.map +1 -1
- package/dist/api/preprocessor.api.service.d.ts +1 -1
- package/dist/api/preprocessor.api.service.js +1 -1
- package/dist/api/preprocessor.api.service.js.map +1 -1
- package/dist/api/products.api.service.d.ts +4 -4
- package/dist/api/products.api.service.js +6 -6
- package/dist/api/products.api.service.js.map +1 -1
- package/dist/api/resource.api.service.d.ts +76 -0
- package/dist/api/resource.api.service.js +74 -0
- package/dist/api/resource.api.service.js.map +1 -0
- package/dist/api/skills.api.service.d.ts +7 -15
- package/dist/api/skills.api.service.js +1 -1
- package/dist/api/skills.api.service.js.map +1 -1
- package/dist/api/tool.api.service.d.ts +1 -1
- package/dist/api/tool.api.service.js +1 -1
- package/dist/api/tool.api.service.js.map +1 -1
- package/dist/api/unifiedto.api.service.d.ts +1 -1
- package/dist/api/unifiedto.api.service.js +1 -1
- package/dist/api/unifiedto.api.service.js.map +1 -1
- package/dist/api/user.data.api.service.d.ts +7 -8
- package/dist/api/user.data.api.service.js +2 -3
- package/dist/api/user.data.api.service.js.map +1 -1
- package/dist/api/webhook.api.service.d.ts +1 -1
- package/dist/api/webhook.api.service.js +1 -1
- package/dist/api/webhook.api.service.js.map +1 -1
- package/dist/api/whatsapp-templates.api.service.d.ts +1 -1
- package/dist/api/whatsapp-templates.api.service.js +1 -1
- package/dist/api/whatsapp-templates.api.service.js.map +1 -1
- package/dist/api-exports.d.ts +14 -12
- package/dist/api-exports.js +8 -8
- package/dist/api-exports.js.map +1 -1
- package/dist/cli/command-definitions.js +32 -17
- package/dist/cli/command-definitions.js.map +1 -1
- package/dist/commands/admin.js +3 -24
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/agents.d.ts +8 -7
- package/dist/commands/agents.js +63 -21
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/channels.js +11 -23
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.js +33 -47
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/chatClear.js +11 -41
- package/dist/commands/chatClear.js.map +1 -1
- package/dist/commands/compile.d.ts +26 -23
- package/dist/commands/compile.js +98 -403
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/completion.js +1 -1
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/deploy.js +55 -25
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +29 -45
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/env.js +12 -25
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/evals.js +3 -20
- package/dist/commands/evals.js.map +1 -1
- package/dist/commands/features.js +10 -23
- package/dist/commands/features.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +135 -19
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/integrations.js +26 -37
- package/dist/commands/integrations.js.map +1 -1
- package/dist/commands/jobs.js +32 -56
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/logs.js +9 -20
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/marketplace.js +34 -52
- package/dist/commands/marketplace.js.map +1 -1
- package/dist/commands/mcp.js +10 -23
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/persona.js +43 -74
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/postprocessors.js +15 -28
- package/dist/commands/postprocessors.js.map +1 -1
- package/dist/commands/preprocessors.js +15 -28
- package/dist/commands/preprocessors.js.map +1 -1
- package/dist/commands/production.js +30 -63
- package/dist/commands/production.js.map +1 -1
- package/dist/commands/push.js +294 -1241
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/pushBackup.d.ts +22 -0
- package/dist/commands/pushBackup.js +133 -0
- package/dist/commands/pushBackup.js.map +1 -0
- package/dist/commands/resources.js +29 -72
- package/dist/commands/resources.js.map +1 -1
- package/dist/commands/skills.d.ts +1 -1
- package/dist/commands/skills.js +58 -70
- package/dist/commands/skills.js.map +1 -1
- package/dist/commands/sync.d.ts +1 -3
- package/dist/commands/sync.js +12 -24
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/test.js +135 -104
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/webhooks.js +15 -28
- package/dist/commands/webhooks.js.map +1 -1
- package/dist/compiler/agent-traverser.d.ts +104 -0
- package/dist/compiler/agent-traverser.js +311 -0
- package/dist/compiler/agent-traverser.js.map +1 -0
- package/dist/compiler/bundler.d.ts +42 -0
- package/dist/compiler/bundler.js +187 -0
- package/dist/compiler/bundler.js.map +1 -0
- package/dist/compiler/compiler.d.ts +177 -0
- package/dist/compiler/compiler.js +580 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/index.d.ts +36 -0
- package/dist/compiler/index.js +42 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/plugins/base.d.ts +264 -0
- package/dist/compiler/plugins/base.js +307 -0
- package/dist/compiler/plugins/base.js.map +1 -0
- package/dist/compiler/plugins/job.plugin.d.ts +33 -0
- package/dist/compiler/plugins/job.plugin.js +143 -0
- package/dist/compiler/plugins/job.plugin.js.map +1 -0
- package/dist/compiler/plugins/mcp-server.plugin.d.ts +50 -0
- package/dist/compiler/plugins/mcp-server.plugin.js +186 -0
- package/dist/compiler/plugins/mcp-server.plugin.js.map +1 -0
- package/dist/compiler/plugins/postprocessor.plugin.d.ts +20 -0
- package/dist/compiler/plugins/postprocessor.plugin.js +39 -0
- package/dist/compiler/plugins/postprocessor.plugin.js.map +1 -0
- package/dist/compiler/plugins/preprocessor.plugin.d.ts +20 -0
- package/dist/compiler/plugins/preprocessor.plugin.js +48 -0
- package/dist/compiler/plugins/preprocessor.plugin.js.map +1 -0
- package/dist/compiler/plugins/processor-base.d.ts +16 -0
- package/dist/compiler/plugins/processor-base.js +34 -0
- package/dist/compiler/plugins/processor-base.js.map +1 -0
- package/dist/compiler/plugins/registry.d.ts +61 -0
- package/dist/compiler/plugins/registry.js +107 -0
- package/dist/compiler/plugins/registry.js.map +1 -0
- package/dist/compiler/plugins/skill.plugin.d.ts +71 -0
- package/dist/compiler/plugins/skill.plugin.js +243 -0
- package/dist/compiler/plugins/skill.plugin.js.map +1 -0
- package/dist/compiler/plugins/tool.plugin.d.ts +67 -0
- package/dist/compiler/plugins/tool.plugin.js +279 -0
- package/dist/compiler/plugins/tool.plugin.js.map +1 -0
- package/dist/compiler/plugins/webhook.plugin.d.ts +37 -0
- package/dist/compiler/plugins/webhook.plugin.js +127 -0
- package/dist/compiler/plugins/webhook.plugin.js.map +1 -0
- package/dist/compiler/source-writer.d.ts +98 -0
- package/dist/compiler/source-writer.js +223 -0
- package/dist/compiler/source-writer.js.map +1 -0
- package/dist/compiler/types.d.ts +289 -0
- package/dist/compiler/types.js +20 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/compiler/utils/ast-helpers.d.ts +57 -0
- package/dist/compiler/utils/ast-helpers.js +164 -0
- package/dist/compiler/utils/ast-helpers.js.map +1 -0
- package/dist/compiler/utils/common.d.ts +23 -0
- package/dist/compiler/utils/common.js +66 -0
- package/dist/compiler/utils/common.js.map +1 -0
- package/dist/compiler/utils/file-discovery.d.ts +34 -0
- package/dist/compiler/utils/file-discovery.js +68 -0
- package/dist/compiler/utils/file-discovery.js.map +1 -0
- package/dist/compiler/utils/path-resolver.d.ts +25 -0
- package/dist/compiler/utils/path-resolver.js +66 -0
- package/dist/compiler/utils/path-resolver.js.map +1 -0
- package/dist/compiler/utils/schema-converter.d.ts +26 -0
- package/dist/compiler/utils/schema-converter.js +94 -0
- package/dist/compiler/utils/schema-converter.js.map +1 -0
- package/dist/config/compile.constants.d.ts +2 -22
- package/dist/config/compile.constants.js +2 -49
- package/dist/config/compile.constants.js.map +1 -1
- package/dist/config/constants.d.ts +18 -2
- package/dist/config/constants.js +28 -8
- package/dist/config/constants.js.map +1 -1
- package/dist/config/dev.constants.d.ts +0 -10
- package/dist/config/dev.constants.js +0 -10
- package/dist/config/dev.constants.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/instances/basket.instance.js.map +1 -0
- package/dist/instances/data.entry.instance.js.map +1 -0
- package/dist/instances/job.instance.js.map +1 -0
- package/dist/instances/order.instance.js.map +1 -0
- package/dist/instances/product.instance.js.map +1 -0
- package/dist/instances/product.pagination.instance.js.map +1 -0
- package/dist/instances/product.search.instance.js.map +1 -0
- package/dist/instances/user.instance.js.map +1 -0
- package/dist/interfaces/admin.d.ts +0 -38
- package/dist/interfaces/backup.d.ts +125 -0
- package/dist/interfaces/backup.js +8 -0
- package/dist/interfaces/backup.js.map +1 -0
- package/dist/interfaces/baskets.d.ts +0 -56
- package/dist/interfaces/common.d.ts +1 -0
- package/dist/interfaces/deploy.d.ts +0 -15
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/marketplace.d.ts +51 -0
- package/dist/interfaces/marketplace.js +1 -1
- package/dist/interfaces/marketplace.js.map +1 -1
- package/dist/interfaces/message.d.ts +0 -3
- package/dist/interfaces/orders.d.ts +0 -24
- package/dist/interfaces/postprocessors.d.ts +0 -18
- package/dist/interfaces/preprocessors.d.ts +0 -18
- package/dist/interfaces/skills.d.ts +61 -0
- package/dist/interfaces/user.d.ts +25 -0
- package/dist/interfaces/webhooks.d.ts +0 -9
- package/dist/primitives/base.handler.d.ts +106 -0
- package/dist/primitives/base.handler.js +370 -0
- package/dist/primitives/base.handler.js.map +1 -0
- package/dist/primitives/index.d.ts +47 -0
- package/dist/primitives/index.js +78 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/job.handler.d.ts +52 -0
- package/dist/primitives/job.handler.js +118 -0
- package/dist/primitives/job.handler.js.map +1 -0
- package/dist/primitives/mcp-server.handler.d.ts +54 -0
- package/dist/primitives/mcp-server.handler.js +91 -0
- package/dist/primitives/mcp-server.handler.js.map +1 -0
- package/dist/primitives/postprocessor.handler.d.ts +49 -0
- package/dist/primitives/postprocessor.handler.js +81 -0
- package/dist/primitives/postprocessor.handler.js.map +1 -0
- package/dist/primitives/preprocessor.handler.d.ts +54 -0
- package/dist/primitives/preprocessor.handler.js +95 -0
- package/dist/primitives/preprocessor.handler.js.map +1 -0
- package/dist/primitives/skill.handler.d.ts +44 -0
- package/dist/primitives/skill.handler.js +192 -0
- package/dist/primitives/skill.handler.js.map +1 -0
- package/dist/primitives/types.d.ts +72 -0
- package/dist/primitives/types.js +17 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/primitives/webhook.handler.d.ts +50 -0
- package/dist/primitives/webhook.handler.js +96 -0
- package/dist/primitives/webhook.handler.js.map +1 -0
- package/dist/services/auth.js +1 -2
- package/dist/services/auth.js.map +1 -1
- package/dist/services/sandbox.service.d.ts +103 -0
- package/dist/services/sandbox.service.js +479 -0
- package/dist/services/sandbox.service.js.map +1 -0
- package/dist/types/api-contracts.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/skill.d.ts +8 -2
- package/dist/types/skill.js +8 -0
- package/dist/types/skill.js.map +1 -1
- package/dist/types/yaml.types.d.ts +69 -0
- package/dist/types/yaml.types.js +6 -0
- package/dist/types/yaml.types.js.map +1 -0
- package/dist/utils/artifact-loader.d.ts +108 -0
- package/dist/utils/artifact-loader.js +188 -0
- package/dist/utils/artifact-loader.js.map +1 -0
- package/dist/utils/backup-helpers.d.ts +122 -0
- package/dist/utils/backup-helpers.js +274 -0
- package/dist/utils/backup-helpers.js.map +1 -0
- package/dist/utils/cli.d.ts +8 -0
- package/dist/utils/cli.js +19 -2
- package/dist/utils/cli.js.map +1 -1
- package/dist/utils/command-utils.d.ts +42 -0
- package/dist/utils/command-utils.js +83 -0
- package/dist/utils/command-utils.js.map +1 -0
- package/dist/utils/deploy-helpers.d.ts +0 -29
- package/dist/utils/deploy-helpers.js +0 -70
- package/dist/utils/deploy-helpers.js.map +1 -1
- package/dist/utils/dev-api.d.ts +3 -99
- package/dist/utils/dev-api.js +3 -430
- package/dist/utils/dev-api.js.map +1 -1
- package/dist/utils/dev-server.d.ts +3 -1
- package/dist/utils/dev-server.js +69 -145
- package/dist/utils/dev-server.js.map +1 -1
- package/dist/utils/dev-watcher.d.ts +0 -1
- package/dist/utils/dev-watcher.js +23 -8
- package/dist/utils/dev-watcher.js.map +1 -1
- package/dist/utils/env-loader.utils.d.ts +10 -1
- package/dist/utils/env-loader.utils.js +39 -31
- package/dist/utils/env-loader.utils.js.map +1 -1
- package/dist/utils/files.d.ts +47 -3
- package/dist/utils/files.js +98 -40
- package/dist/utils/files.js.map +1 -1
- package/dist/utils/init-agent.js +1 -2
- package/dist/utils/init-agent.js.map +1 -1
- package/dist/utils/init-helpers.d.ts +2 -10
- package/dist/utils/init-helpers.js +9 -17
- package/dist/utils/init-helpers.js.map +1 -1
- package/dist/utils/init-prompts.d.ts +0 -8
- package/dist/utils/init-prompts.js +0 -22
- package/dist/utils/init-prompts.js.map +1 -1
- package/dist/utils/prompt-handler.d.ts +3 -0
- package/dist/utils/prompt-handler.js +13 -0
- package/dist/utils/prompt-handler.js.map +1 -1
- package/dist/utils/sandbox-storage.d.ts +6 -5
- package/dist/utils/sandbox-storage.js +12 -12
- package/dist/utils/sandbox-storage.js.map +1 -1
- package/dist/utils/sandbox.d.ts +7 -30
- package/dist/utils/sandbox.js +247 -223
- package/dist/utils/sandbox.js.map +1 -1
- package/dist/utils/semver.d.ts +12 -0
- package/dist/utils/semver.js +23 -0
- package/dist/utils/semver.js.map +1 -1
- package/dist/utils/sync-display.d.ts +9 -0
- package/dist/utils/sync-display.js +67 -0
- package/dist/utils/sync-display.js.map +1 -0
- package/dist/utils/sync-fetch.d.ts +23 -0
- package/dist/utils/sync-fetch.js +64 -0
- package/dist/utils/sync-fetch.js.map +1 -0
- package/dist/utils/sync-helpers.d.ts +4 -59
- package/dist/utils/sync-helpers.js +4 -206
- package/dist/utils/sync-helpers.js.map +1 -1
- package/dist/web/app.css +912 -186
- package/dist/web/app.js +46 -46
- package/docs/API_INDEX.md +100 -0
- package/docs/API_REFERENCE.md +773 -0
- package/docs/CLI_REFERENCE.md +924 -0
- package/docs/GETTING_STARTED.md +862 -0
- package/docs/README.md +270 -0
- package/docs/api/AI.md +882 -0
- package/docs/api/Baskets.md +511 -0
- package/docs/api/CDN.md +524 -0
- package/docs/api/Data.md +446 -0
- package/docs/api/Jobs.md +524 -0
- package/docs/api/LuaAgent.md +454 -0
- package/docs/api/LuaJob.md +604 -0
- package/docs/api/LuaSkill.md +396 -0
- package/docs/api/LuaTool.md +521 -0
- package/docs/api/LuaWebhook.md +601 -0
- package/docs/api/Orders.md +514 -0
- package/docs/api/PostProcessor.md +565 -0
- package/docs/api/PreProcessor.md +630 -0
- package/docs/api/Products.md +507 -0
- package/docs/api/Templates.md +662 -0
- package/docs/api/User.md +567 -0
- package/docs/archive/DEVELOPMENT_GUIDE_V1.md +1294 -0
- package/docs/compiler-v2/ASSESSMENT.md +205 -0
- package/docs/compiler-v2/TEST_PLAN.md +306 -0
- package/package.json +3 -7
- package/template/tsconfig.json +1 -1
- package/dist/common/basket.instance.js.map +0 -1
- package/dist/common/data.entry.instance.js.map +0 -1
- package/dist/common/http.client.js.map +0 -1
- package/dist/common/job.instance.js.map +0 -1
- package/dist/common/order.instance.js.map +0 -1
- package/dist/common/product.instance.js.map +0 -1
- package/dist/common/product.pagination.instance.js.map +0 -1
- package/dist/common/product.search.instance.js.map +0 -1
- package/dist/common/user.instance.js.map +0 -1
- package/dist/config/auth.constants.d.ts +0 -11
- package/dist/config/auth.constants.js +0 -12
- package/dist/config/auth.constants.js.map +0 -1
- package/dist/config/init.constants.d.ts +0 -15
- package/dist/config/init.constants.js +0 -20
- package/dist/config/init.constants.js.map +0 -1
- package/dist/interfaces/compile.d.ts +0 -12
- package/dist/interfaces/compile.js +0 -5
- package/dist/interfaces/compile.js.map +0 -1
- package/dist/types/compile.types.d.ts +0 -131
- package/dist/types/compile.types.js +0 -6
- package/dist/types/compile.types.js.map +0 -1
- package/dist/utils/agent-code-utils.d.ts +0 -25
- package/dist/utils/agent-code-utils.js +0 -107
- package/dist/utils/agent-code-utils.js.map +0 -1
- package/dist/utils/bundling.d.ts +0 -89
- package/dist/utils/bundling.js +0 -1068
- package/dist/utils/bundling.js.map +0 -1
- package/dist/utils/compile.d.ts +0 -116
- package/dist/utils/compile.js +0 -1062
- package/dist/utils/compile.js.map +0 -1
- package/dist/utils/deploy-api.d.ts +0 -26
- package/dist/utils/deploy-api.js +0 -54
- package/dist/utils/deploy-api.js.map +0 -1
- package/dist/utils/deployment.d.ts +0 -26
- package/dist/utils/deployment.js +0 -218
- package/dist/utils/deployment.js.map +0 -1
- package/dist/utils/dev-helpers.d.ts +0 -47
- package/dist/utils/dev-helpers.js +0 -82
- package/dist/utils/dev-helpers.js.map +0 -1
- package/dist/utils/job-management.d.ts +0 -27
- package/dist/utils/job-management.js +0 -248
- package/dist/utils/job-management.js.map +0 -1
- package/dist/utils/mcp-server-management.d.ts +0 -26
- package/dist/utils/mcp-server-management.js +0 -197
- package/dist/utils/mcp-server-management.js.map +0 -1
- package/dist/utils/postprocessor-management.d.ts +0 -9
- package/dist/utils/postprocessor-management.js +0 -117
- package/dist/utils/postprocessor-management.js.map +0 -1
- package/dist/utils/pre-bundle-jobs.d.ts +0 -27
- package/dist/utils/pre-bundle-jobs.js +0 -189
- package/dist/utils/pre-bundle-jobs.js.map +0 -1
- package/dist/utils/preprocessor-management.d.ts +0 -9
- package/dist/utils/preprocessor-management.js +0 -117
- package/dist/utils/preprocessor-management.js.map +0 -1
- package/dist/utils/push-api.d.ts +0 -15
- package/dist/utils/push-api.js +0 -49
- package/dist/utils/push-api.js.map +0 -1
- package/dist/utils/push-helpers.d.ts +0 -82
- package/dist/utils/push-helpers.js +0 -246
- package/dist/utils/push-helpers.js.map +0 -1
- package/dist/utils/skill-management.d.ts +0 -39
- package/dist/utils/skill-management.js +0 -299
- package/dist/utils/skill-management.js.map +0 -1
- package/dist/utils/test-helpers.d.ts +0 -33
- package/dist/utils/test-helpers.js +0 -84
- package/dist/utils/test-helpers.js.map +0 -1
- package/dist/utils/test-prompts.d.ts +0 -23
- package/dist/utils/test-prompts.js +0 -187
- package/dist/utils/test-prompts.js.map +0 -1
- package/dist/utils/tool-detection.d.ts +0 -19
- package/dist/utils/tool-detection.js +0 -125
- package/dist/utils/tool-detection.js.map +0 -1
- package/dist/utils/webhook-management.d.ts +0 -27
- package/dist/utils/webhook-management.js +0 -241
- package/dist/utils/webhook-management.js.map +0 -1
- /package/dist/{common → api}/http.client.d.ts +0 -0
- /package/dist/{common → api}/http.client.js +0 -0
- /package/dist/{common → instances}/basket.instance.d.ts +0 -0
- /package/dist/{common → instances}/basket.instance.js +0 -0
- /package/dist/{common → instances}/data.entry.instance.d.ts +0 -0
- /package/dist/{common → instances}/data.entry.instance.js +0 -0
- /package/dist/{common → instances}/job.instance.d.ts +0 -0
- /package/dist/{common → instances}/job.instance.js +0 -0
- /package/dist/{common → instances}/order.instance.d.ts +0 -0
- /package/dist/{common → instances}/order.instance.js +0 -0
- /package/dist/{common → instances}/product.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.instance.js +0 -0
- /package/dist/{common → instances}/product.pagination.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.pagination.instance.js +0 -0
- /package/dist/{common → instances}/product.search.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.search.instance.js +0 -0
- /package/dist/{common → instances}/user.instance.d.ts +0 -0
- /package/dist/{common → instances}/user.instance.js +0 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
# Templates API
|
|
2
|
+
|
|
3
|
+
The Templates API allows you to send WhatsApp template messages to users. Templates are pre-approved message formats for marketing, utility, and authentication purposes.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { Templates } from 'lua-cli';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The Templates API enables:
|
|
14
|
+
- List WhatsApp templates for a channel
|
|
15
|
+
- Get specific template details
|
|
16
|
+
- Send template messages to phone numbers
|
|
17
|
+
- Use template variables for personalization
|
|
18
|
+
- Send bulk messages with templates
|
|
19
|
+
- Access button values and actions
|
|
20
|
+
|
|
21
|
+
## Methods
|
|
22
|
+
|
|
23
|
+
| Method | Description |
|
|
24
|
+
|--------|-------------|
|
|
25
|
+
| `Templates.whatsapp.list(channelId, options?)` | List all templates for a WhatsApp channel |
|
|
26
|
+
| `Templates.whatsapp.get(channelId, templateId)` | Get a specific template |
|
|
27
|
+
| `Templates.whatsapp.send(channelId, templateId, data)` | Send template to phone numbers |
|
|
28
|
+
|
|
29
|
+
## Template Categories
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
type WhatsAppTemplateCategory =
|
|
33
|
+
| 'AUTHENTICATION' // OTP, verification codes
|
|
34
|
+
| 'MARKETING' // Promotional messages
|
|
35
|
+
| 'UTILITY'; // Transactional, notifications
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Template Status
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
type WhatsAppTemplateStatus =
|
|
42
|
+
| 'APPROVED' // Ready to use
|
|
43
|
+
| 'REJECTED' // Not approved by WhatsApp
|
|
44
|
+
| 'PENDING'; // Awaiting approval
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Methods
|
|
48
|
+
|
|
49
|
+
### `Templates.whatsapp.list(channelId, options?)`
|
|
50
|
+
|
|
51
|
+
Lists all templates for a WhatsApp channel with pagination.
|
|
52
|
+
|
|
53
|
+
**Parameters:**
|
|
54
|
+
- `channelId` (string) - WhatsApp channel ID
|
|
55
|
+
- `options` (object, optional)
|
|
56
|
+
- `page` (number) - Page number (default: 1)
|
|
57
|
+
- `limit` (number) - Results per page (default: 10)
|
|
58
|
+
- `search` (string) - Search by template name
|
|
59
|
+
|
|
60
|
+
**Returns:** `Promise<PaginatedTemplatesResponse>`
|
|
61
|
+
- `templates` - Array of template objects
|
|
62
|
+
- `total` - Total template count
|
|
63
|
+
- `page` - Current page
|
|
64
|
+
- `limit` - Page size
|
|
65
|
+
- `totalPages` - Total pages
|
|
66
|
+
|
|
67
|
+
**Example:**
|
|
68
|
+
```typescript
|
|
69
|
+
const response = await Templates.whatsapp.list('channel_123', {
|
|
70
|
+
page: 1,
|
|
71
|
+
limit: 20,
|
|
72
|
+
search: 'order'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log(`Found ${response.total} templates`);
|
|
76
|
+
response.templates.forEach(template => {
|
|
77
|
+
console.log(`${template.name} - ${template.status}`);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `Templates.whatsapp.get(channelId, templateId)`
|
|
82
|
+
|
|
83
|
+
Gets a specific template by ID.
|
|
84
|
+
|
|
85
|
+
**Parameters:**
|
|
86
|
+
- `channelId` (string) - WhatsApp channel ID
|
|
87
|
+
- `templateId` (string) - Template ID
|
|
88
|
+
|
|
89
|
+
**Returns:** `Promise<WhatsAppTemplate>`
|
|
90
|
+
|
|
91
|
+
**Example:**
|
|
92
|
+
```typescript
|
|
93
|
+
const template = await Templates.whatsapp.get('channel_123', 'template_456');
|
|
94
|
+
|
|
95
|
+
console.log(template.name);
|
|
96
|
+
console.log(template.category);
|
|
97
|
+
console.log(template.components);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `Templates.whatsapp.send(channelId, templateId, data)`
|
|
101
|
+
|
|
102
|
+
Sends a template message to one or more phone numbers.
|
|
103
|
+
|
|
104
|
+
**Parameters:**
|
|
105
|
+
- `channelId` (string) - WhatsApp channel ID
|
|
106
|
+
- `templateId` (string) - Template ID
|
|
107
|
+
- `data` (object)
|
|
108
|
+
- `phoneNumbers` (string[]) - Array of phone numbers (E.164 format)
|
|
109
|
+
- `values` (object, optional) - Template variable values
|
|
110
|
+
- `header` (object) - Header variables (key-value pairs)
|
|
111
|
+
- `body` (object) - Body variables (key-value pairs)
|
|
112
|
+
- `buttons` (array) - Button values
|
|
113
|
+
|
|
114
|
+
**Returns:** `Promise<SendTemplateResponse>`
|
|
115
|
+
- `results` - Array of successful sends
|
|
116
|
+
- `errors` - Array of failed sends
|
|
117
|
+
- `totalProcessed` - Total messages processed
|
|
118
|
+
- `totalErrors` - Total errors
|
|
119
|
+
|
|
120
|
+
**Example:**
|
|
121
|
+
```typescript
|
|
122
|
+
const response = await Templates.whatsapp.send(
|
|
123
|
+
'channel_123',
|
|
124
|
+
'template_456',
|
|
125
|
+
{
|
|
126
|
+
phoneNumbers: ['+1234567890', '+0987654321'],
|
|
127
|
+
values: {
|
|
128
|
+
body: {
|
|
129
|
+
name: 'John Doe',
|
|
130
|
+
order_id: 'ORD-12345'
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
console.log(`Sent ${response.totalProcessed} messages`);
|
|
137
|
+
console.log(`Errors: ${response.totalErrors}`);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Template Structure
|
|
141
|
+
|
|
142
|
+
### Template Components
|
|
143
|
+
|
|
144
|
+
Templates consist of components:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
interface WhatsAppTemplate {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
category: 'AUTHENTICATION' | 'MARKETING' | 'UTILITY';
|
|
151
|
+
language: string;
|
|
152
|
+
status: 'APPROVED' | 'REJECTED' | 'PENDING';
|
|
153
|
+
components: [
|
|
154
|
+
{
|
|
155
|
+
type: 'HEADER';
|
|
156
|
+
format: 'TEXT';
|
|
157
|
+
text: string;
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: 'BODY';
|
|
161
|
+
text: string;
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'FOOTER';
|
|
165
|
+
text: string;
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
type: 'BUTTONS';
|
|
169
|
+
buttons: [...]
|
|
170
|
+
}
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Button Types
|
|
176
|
+
|
|
177
|
+
Templates can include buttons:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Quick Reply Button
|
|
181
|
+
{
|
|
182
|
+
type: 'QUICK_REPLY',
|
|
183
|
+
text: 'Yes, I confirm'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Call Button
|
|
187
|
+
{
|
|
188
|
+
type: 'PHONE_NUMBER',
|
|
189
|
+
text: 'Call Support',
|
|
190
|
+
phone_number: '+1234567890'
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// URL Button
|
|
194
|
+
{
|
|
195
|
+
type: 'URL',
|
|
196
|
+
text: 'Visit Website',
|
|
197
|
+
url: 'https://example.com'
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Copy Code Button (for OTP)
|
|
201
|
+
{
|
|
202
|
+
type: 'COPY_CODE',
|
|
203
|
+
example: '123456'
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Complete Examples
|
|
208
|
+
|
|
209
|
+
### Send Order Confirmation
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { LuaTool, Templates } from 'lua-cli';
|
|
213
|
+
import { z } from 'zod';
|
|
214
|
+
|
|
215
|
+
export default class SendOrderConfirmationTool implements LuaTool {
|
|
216
|
+
name = 'send_order_confirmation';
|
|
217
|
+
description = 'Send WhatsApp order confirmation';
|
|
218
|
+
|
|
219
|
+
inputSchema = z.object({
|
|
220
|
+
phoneNumber: z.string(),
|
|
221
|
+
orderNumber: z.string(),
|
|
222
|
+
customerName: z.string(),
|
|
223
|
+
totalAmount: z.number()
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
227
|
+
const channelId = process.env.WHATSAPP_CHANNEL_ID!;
|
|
228
|
+
const templateId = 'order_confirmation_template';
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const response = await Templates.whatsapp.send(
|
|
232
|
+
channelId,
|
|
233
|
+
templateId,
|
|
234
|
+
{
|
|
235
|
+
phoneNumbers: [input.phoneNumber],
|
|
236
|
+
values: {
|
|
237
|
+
body: {
|
|
238
|
+
customer_name: input.customerName,
|
|
239
|
+
order_number: input.orderNumber,
|
|
240
|
+
total_amount: input.totalAmount.toFixed(2)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
if (response.totalErrors > 0) {
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
error: 'Failed to send confirmation',
|
|
250
|
+
errors: response.errors
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
success: true,
|
|
256
|
+
message: 'Order confirmation sent',
|
|
257
|
+
orderNumber: input.orderNumber
|
|
258
|
+
};
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
error: error instanceof Error ? error.message : 'Send failed'
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Send OTP Code
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { LuaTool, Templates } from 'lua-cli';
|
|
273
|
+
import { z } from 'zod';
|
|
274
|
+
|
|
275
|
+
export default class SendOTPTool implements LuaTool {
|
|
276
|
+
name = 'send_otp';
|
|
277
|
+
description = 'Send OTP verification code via WhatsApp';
|
|
278
|
+
|
|
279
|
+
inputSchema = z.object({
|
|
280
|
+
phoneNumber: z.string().describe('Phone number in E.164 format'),
|
|
281
|
+
otp: z.string().length(6).describe('6-digit OTP code')
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
285
|
+
const channelId = process.env.WHATSAPP_CHANNEL_ID!;
|
|
286
|
+
const templateId = 'otp_verification_template';
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const response = await Templates.whatsapp.send(
|
|
290
|
+
channelId,
|
|
291
|
+
templateId,
|
|
292
|
+
{
|
|
293
|
+
phoneNumbers: [input.phoneNumber],
|
|
294
|
+
values: {
|
|
295
|
+
body: {
|
|
296
|
+
otp_code: input.otp
|
|
297
|
+
},
|
|
298
|
+
buttons: [
|
|
299
|
+
{
|
|
300
|
+
sub_type: 'COPY_CODE',
|
|
301
|
+
index: '0',
|
|
302
|
+
coupon_code: input.otp
|
|
303
|
+
}
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
success: response.totalErrors === 0,
|
|
311
|
+
message: response.totalErrors === 0
|
|
312
|
+
? 'OTP sent successfully'
|
|
313
|
+
: 'Failed to send OTP',
|
|
314
|
+
errors: response.errors
|
|
315
|
+
};
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return {
|
|
318
|
+
success: false,
|
|
319
|
+
error: error instanceof Error ? error.message : 'OTP send failed'
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Bulk Marketing Campaign
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
import { LuaTool, Templates, Data } from 'lua-cli';
|
|
330
|
+
import { z } from 'zod';
|
|
331
|
+
|
|
332
|
+
export default class SendMarketingCampaignTool implements LuaTool {
|
|
333
|
+
name = 'send_marketing_campaign';
|
|
334
|
+
description = 'Send bulk marketing message to customers';
|
|
335
|
+
|
|
336
|
+
inputSchema = z.object({
|
|
337
|
+
campaignName: z.string(),
|
|
338
|
+
offerText: z.string(),
|
|
339
|
+
discountCode: z.string()
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
343
|
+
// Get opted-in customer phone numbers
|
|
344
|
+
const customers = await Data.get('opted_in_customers');
|
|
345
|
+
const phoneNumbers = customers
|
|
346
|
+
.map(c => c.data.phoneNumber)
|
|
347
|
+
.filter(Boolean);
|
|
348
|
+
|
|
349
|
+
if (phoneNumbers.length === 0) {
|
|
350
|
+
return {
|
|
351
|
+
success: false,
|
|
352
|
+
error: 'No opted-in customers found'
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const channelId = process.env.WHATSAPP_CHANNEL_ID!;
|
|
357
|
+
const templateId = 'marketing_offer_template';
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
// Send in batches of 50
|
|
361
|
+
const batchSize = 50;
|
|
362
|
+
const results = [];
|
|
363
|
+
|
|
364
|
+
for (let i = 0; i < phoneNumbers.length; i += batchSize) {
|
|
365
|
+
const batch = phoneNumbers.slice(i, i + batchSize);
|
|
366
|
+
|
|
367
|
+
const response = await Templates.whatsapp.send(
|
|
368
|
+
channelId,
|
|
369
|
+
templateId,
|
|
370
|
+
{
|
|
371
|
+
phoneNumbers: batch,
|
|
372
|
+
values: {
|
|
373
|
+
body: {
|
|
374
|
+
offer_text: input.offerText,
|
|
375
|
+
discount_code: input.discountCode
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
results.push(response);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const totalSent = results.reduce((sum, r) => sum + r.totalProcessed, 0);
|
|
385
|
+
const totalErrors = results.reduce((sum, r) => sum + r.totalErrors, 0);
|
|
386
|
+
|
|
387
|
+
// Log campaign results
|
|
388
|
+
await Data.create('campaign_results', {
|
|
389
|
+
campaignName: input.campaignName,
|
|
390
|
+
totalRecipients: phoneNumbers.length,
|
|
391
|
+
totalSent,
|
|
392
|
+
totalErrors,
|
|
393
|
+
sentAt: new Date().toISOString()
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
return {
|
|
397
|
+
success: true,
|
|
398
|
+
message: `Campaign sent to ${totalSent} customers`,
|
|
399
|
+
totalSent,
|
|
400
|
+
totalErrors,
|
|
401
|
+
campaignName: input.campaignName
|
|
402
|
+
};
|
|
403
|
+
} catch (error) {
|
|
404
|
+
return {
|
|
405
|
+
success: false,
|
|
406
|
+
error: error instanceof Error ? error.message : 'Campaign failed'
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Send Appointment Reminder
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import { LuaTool, Templates } from 'lua-cli';
|
|
417
|
+
import { z } from 'zod';
|
|
418
|
+
|
|
419
|
+
export default class SendAppointmentReminderTool implements LuaTool {
|
|
420
|
+
name = 'send_appointment_reminder';
|
|
421
|
+
description = 'Send appointment reminder via WhatsApp';
|
|
422
|
+
|
|
423
|
+
inputSchema = z.object({
|
|
424
|
+
phoneNumber: z.string(),
|
|
425
|
+
customerName: z.string(),
|
|
426
|
+
appointmentDate: z.string(),
|
|
427
|
+
appointmentTime: z.string(),
|
|
428
|
+
location: z.string()
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
432
|
+
const channelId = process.env.WHATSAPP_CHANNEL_ID!;
|
|
433
|
+
const templateId = 'appointment_reminder_template';
|
|
434
|
+
|
|
435
|
+
try {
|
|
436
|
+
const response = await Templates.whatsapp.send(
|
|
437
|
+
channelId,
|
|
438
|
+
templateId,
|
|
439
|
+
{
|
|
440
|
+
phoneNumbers: [input.phoneNumber],
|
|
441
|
+
values: {
|
|
442
|
+
body: {
|
|
443
|
+
customer_name: input.customerName,
|
|
444
|
+
appointment_date: input.appointmentDate,
|
|
445
|
+
appointment_time: input.appointmentTime,
|
|
446
|
+
location: input.location
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
success: response.totalErrors === 0,
|
|
454
|
+
message: 'Reminder sent successfully'
|
|
455
|
+
};
|
|
456
|
+
} catch (error) {
|
|
457
|
+
return {
|
|
458
|
+
success: false,
|
|
459
|
+
error: error instanceof Error ? error.message : 'Send failed'
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### List and Search Templates
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
import { LuaTool, Templates } from 'lua-cli';
|
|
470
|
+
import { z } from 'zod';
|
|
471
|
+
|
|
472
|
+
export default class ListTemplatesToolimplements LuaTool {
|
|
473
|
+
name = 'list_whatsapp_templates';
|
|
474
|
+
description = 'List available WhatsApp templates';
|
|
475
|
+
|
|
476
|
+
inputSchema = z.object({
|
|
477
|
+
search: z.string().optional(),
|
|
478
|
+
category: z.enum(['AUTHENTICATION', 'MARKETING', 'UTILITY']).optional()
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
async execute(input: z.infer<typeof this.inputSchema>) {
|
|
482
|
+
const channelId = process.env.WHATSAPP_CHANNEL_ID!;
|
|
483
|
+
|
|
484
|
+
try {
|
|
485
|
+
const response = await Templates.whatsapp.list(channelId, {
|
|
486
|
+
search: input.search,
|
|
487
|
+
limit: 50
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// Filter by category if specified
|
|
491
|
+
let templates = response.templates;
|
|
492
|
+
if (input.category) {
|
|
493
|
+
templates = templates.filter(t => t.category === input.category);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Only show approved templates
|
|
497
|
+
const approved = templates.filter(t => t.status === 'APPROVED');
|
|
498
|
+
|
|
499
|
+
return {
|
|
500
|
+
success: true,
|
|
501
|
+
total: approved.length,
|
|
502
|
+
templates: approved.map(t => ({
|
|
503
|
+
id: t.id,
|
|
504
|
+
name: t.name,
|
|
505
|
+
category: t.category,
|
|
506
|
+
language: t.language,
|
|
507
|
+
components: t.components.length
|
|
508
|
+
}))
|
|
509
|
+
};
|
|
510
|
+
} catch (error) {
|
|
511
|
+
return {
|
|
512
|
+
success: false,
|
|
513
|
+
error: error instanceof Error ? error.message : 'List failed'
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## Phone Number Format
|
|
521
|
+
|
|
522
|
+
WhatsApp requires phone numbers in E.164 format:
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
// ✅ Correct (E.164 format)
|
|
526
|
+
'+1234567890' // US number
|
|
527
|
+
'+442071234567' // UK number
|
|
528
|
+
'+919876543210' // India number
|
|
529
|
+
|
|
530
|
+
// ❌ Incorrect
|
|
531
|
+
'1234567890' // Missing + prefix
|
|
532
|
+
'(123) 456-7890' // Formatted
|
|
533
|
+
'123-456-7890' // With dashes
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
## Best Practices
|
|
537
|
+
|
|
538
|
+
### ✅ DO
|
|
539
|
+
|
|
540
|
+
- Use approved templates only (check `status === 'APPROVED'`)
|
|
541
|
+
- Validate phone numbers in E.164 format
|
|
542
|
+
- Send in batches for large recipient lists
|
|
543
|
+
- Track campaign results in Data API
|
|
544
|
+
- Handle opt-out requests properly
|
|
545
|
+
- Use appropriate template categories
|
|
546
|
+
- Test templates before bulk sending
|
|
547
|
+
- Include clear unsubscribe instructions for marketing
|
|
548
|
+
- Respect WhatsApp rate limits
|
|
549
|
+
|
|
550
|
+
### ❌ DON'T
|
|
551
|
+
|
|
552
|
+
- Don't send to numbers without consent
|
|
553
|
+
- Don't spam users with frequent messages
|
|
554
|
+
- Don't use marketing templates for transactional messages
|
|
555
|
+
- Don't ignore template variable requirements
|
|
556
|
+
- Don't send without validating template status
|
|
557
|
+
- Don't exceed recommended batch sizes
|
|
558
|
+
- Don't ignore send errors
|
|
559
|
+
- Don't forget to log campaign metrics
|
|
560
|
+
|
|
561
|
+
## Error Handling
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
try {
|
|
565
|
+
const response = await Templates.whatsapp.send(
|
|
566
|
+
channelId,
|
|
567
|
+
templateId,
|
|
568
|
+
{ phoneNumbers, values }
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
if (response.totalErrors > 0) {
|
|
572
|
+
console.log('Some messages failed:', response.errors);
|
|
573
|
+
// Handle partial failure
|
|
574
|
+
}
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (error.message.includes('template not found')) {
|
|
577
|
+
console.log('Template does not exist or is not approved');
|
|
578
|
+
} else if (error.message.includes('channel')) {
|
|
579
|
+
console.log('Invalid channel ID');
|
|
580
|
+
} else {
|
|
581
|
+
console.log('Send failed:', error.message);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
## Common Patterns
|
|
587
|
+
|
|
588
|
+
### Validate Template Variables
|
|
589
|
+
|
|
590
|
+
```typescript
|
|
591
|
+
function validateTemplateVariables(
|
|
592
|
+
template: WhatsAppTemplate,
|
|
593
|
+
values: Record<string, string>
|
|
594
|
+
): boolean {
|
|
595
|
+
const bodyComponent = template.components.find(c => c.type === 'BODY');
|
|
596
|
+
if (!bodyComponent) return true;
|
|
597
|
+
|
|
598
|
+
// Extract variable names from template text ({{variable_name}})
|
|
599
|
+
const variables = bodyComponent.text.match(/\{\{(\w+)\}\}/g);
|
|
600
|
+
if (!variables) return true;
|
|
601
|
+
|
|
602
|
+
// Check all variables are provided
|
|
603
|
+
return variables.every(v => {
|
|
604
|
+
const varName = v.replace(/\{\{|\}\}/g, '');
|
|
605
|
+
return values[varName] !== undefined;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### Format Phone Number to E.164
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
function formatToE164(phone: string, countryCode: string = '+1'): string {
|
|
614
|
+
// Remove all non-digit characters
|
|
615
|
+
const digits = phone.replace(/\D/g, '');
|
|
616
|
+
|
|
617
|
+
// Add country code if not present
|
|
618
|
+
if (!phone.startsWith('+')) {
|
|
619
|
+
return `${countryCode}${digits}`;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return `+${digits}`;
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Batch Send with Retry
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
async function sendWithRetry(
|
|
630
|
+
channelId: string,
|
|
631
|
+
templateId: string,
|
|
632
|
+
phoneNumbers: string[],
|
|
633
|
+
values: any,
|
|
634
|
+
maxRetries: number = 3
|
|
635
|
+
): Promise<SendTemplateResponse> {
|
|
636
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
637
|
+
try {
|
|
638
|
+
return await Templates.whatsapp.send(channelId, templateId, {
|
|
639
|
+
phoneNumbers,
|
|
640
|
+
values
|
|
641
|
+
});
|
|
642
|
+
} catch (error) {
|
|
643
|
+
if (attempt === maxRetries) throw error;
|
|
644
|
+
// Wait before retry
|
|
645
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
throw new Error('Max retries exceeded');
|
|
649
|
+
}
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
## Related APIs
|
|
653
|
+
|
|
654
|
+
- [User API](./User.md) - Get user phone numbers
|
|
655
|
+
- [Data API](./Data.md) - Store opt-in status and campaign results
|
|
656
|
+
- [Jobs API](./Jobs.md) - Schedule template messages
|
|
657
|
+
|
|
658
|
+
## See Also
|
|
659
|
+
|
|
660
|
+
- [WhatsApp Business API](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates)
|
|
661
|
+
- [Template Guidelines](https://developers.facebook.com/docs/whatsapp/message-templates/guidelines)
|
|
662
|
+
- [Marketing Messages Guide](../guides/MarketingMessages.md)
|