mirror of
https://github.com/Luchexx/wacrm.git
synced 2026-11-02 09:19:51 +00:00
Merge pull request #37 from ArnasDon/fix/automations-template-param-ordering
fix(automations): order send_template params numerically, not lexicographically
This commit is contained in:
commit
53bb056803
@ -315,9 +315,22 @@ async function runStep(step: AutomationStep, args: ExecuteArgs): Promise<string>
|
||||
if (!args.contactId) throw new Error('send_template needs a contact')
|
||||
if (!cfg.template_name) throw new Error('send_template needs template_name')
|
||||
const conversationId = await resolveConversationId(args)
|
||||
// Meta templates use positional {{1}}, {{2}}, … placeholders, so
|
||||
// we MUST emit params in strict numeric order. Lexicographic sort
|
||||
// of "1", "2", …, "10" yields "1", "10", "2", … which silently
|
||||
// scrambles every template with ≥10 variables.
|
||||
const params = cfg.variables
|
||||
? Object.keys(cfg.variables)
|
||||
.sort()
|
||||
.sort((a, b) => {
|
||||
const na = Number(a)
|
||||
const nb = Number(b)
|
||||
const aNum = Number.isFinite(na)
|
||||
const bNum = Number.isFinite(nb)
|
||||
if (aNum && bNum) return na - nb
|
||||
if (aNum) return -1
|
||||
if (bNum) return 1
|
||||
return a.localeCompare(b)
|
||||
})
|
||||
.map((k) => String(cfg.variables![k]))
|
||||
: []
|
||||
const { whatsapp_message_id } = await engineSendTemplate({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user