fix(automations): preserve media attachments, execution tracking, and wait-for-reply on AI Agent branch exits

Abierto
#48 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Start in apps/api/src/instagram/services/instagram-automation-runner.service.ts at executeAutomationBranchPath, then trace the queue payload through apps/workers/src/workers/message-worker.ts and apps/workers/src/services/instagram-api.service.ts. Compare the branch dispatch with triggerMatchingAutomations and check how executions resume after a reply. Done when branch DMs send media, appear in execution logs, wait for replies when configured, and can chain to another AI Agent node.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

backend bug workers
Problem Description

In apps/api/src/instagram/services/instagram-automation-runner.service.ts, executeAutomationBranchPath (lines 1737-1777) handles downstream nodes when an ACTION_AI_AGENT exits to a branch (e.g., VIP, Booked, Default, Exit), but has the following bugs:

  1. Media attachments are silently dropped (or skipped when text is empty):

    • Line 1752 checks if (replyText || hasCarousel) and omits config.mediaUrl, so media-only DM nodes are never queued.
    • Line 1761 hardcodes messageType: 'TEXT' while placing config.mediaType in a separate mediaType field.
    • processSendMessageJob (apps/workers/src/workers/message-worker.ts, lines 16, 57, 81) only reads messageType, and InstagramApiService.sendMessage (apps/workers/src/services/instagram-api.service.ts, lines 213 & 303) checks mediaUrl && messageType !== 'TEXT'. As a result, images/videos/audio on AI Agent exit branches are silently dropped and only plain text is sent.
  2. Missing executionId, nodeId, and waitForReplyAfterSend handling:

    • backgroundJob.payload (lines 1757-1769) omits executionId and nodeId. Because processSendMessageJob gates ExecutionStep logging and execution completion on if (executionId) (line 288) and resolves the canvas node via job.data.nodeId (lines 293, 313), branch DMs are invisible in Automation Logs & Analytics.
    • executeAutomationBranchPath also does not handle waitForReplyAfterSend, so any downstream nodes after an exit-branch DM will never resume when the user replies.

Expected Behavior
  1. DM nodes on AI Agent exit branches must send attached media (IMAGE, VIDEO, AUDIO, FILE) even when replyText is empty.
  2. messageType in the SEND_DM job payload must reflect config.mediaUrl ? (config.mediaType || 'IMAGE') : 'TEXT'.
  3. Branch executions must create/reuse an AutomationExecution (executionId), include nodeId: actionNode.nodeId in the job payload, and transition the execution to WAITING (with currentNodeId) when waitForReplyAfterSend is enabled.

Where to Look
  • apps/api/src/instagram/services/instagram-automation-runner.service.ts (executeAutomationBranchPath, lines 1737-1777)
  • apps/workers/src/workers/message-worker.ts (processSendMessageJob, lines 12-86, 288-334)
  • apps/workers/src/services/instagram-api.service.ts (sendMessage, lines 213, 303)

Solution / Implementation Guide
  1. In executeAutomationBranchPath:
    • Update the dispatch guard to if (replyText || hasCarousel || config.mediaUrl).
    • Set messageType: config.mediaUrl ? (config.mediaType || 'IMAGE') : 'TEXT' (matching triggerMatchingAutomations).
    • Create (or look up) the AutomationExecution record for (automation.id, senderId) and pass executionId and nodeId: actionNode.nodeId in backgroundJob.payload.
    • If config.waitForReplyAfterSend is true (and the node has downstream nextNodeIds), set AutomationExecution.status = 'WAITING' and currentNodeId = actionNode.nodeId so subsequent user replies resume the flow.
    • Also handle ACTION_AI_AGENT if an exit branch chains into another AI Agent node.
Lenguaje dominante
TypeScript
Estrellas
2
Forks
1
Merge medio
6 min
PR fusionados (30 d)
27

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sumamakhan761/tryinstance

Todos los issues de sumamakhan761/tryinstance

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.