https://discord.gg/botpress logo
Bot stuck on Publishing
# đŸ€help
c
Hello everyone, recently I added an action to fetch data from a simple API to my bot and now I cannot publish it, gets stuck on an infinite "Publishing" also I get a Status Code: 400 error, is there any way to solve this? @cold-motherboard-82208 ? Thanks! https://cdn.discordapp.com/attachments/1433924175428321370/1433924176284225758/image.png?ex=69067574&is=690523f4&hm=040242e8b74a18cfe8bf4adeaef82015d215550a9dc0acfe8e3b459885717eed&
j
I can help with this! The issue is likely caused by the API action not returning valid JSON or missing required headers, which causes the publish process to fail. Can you share a snippet of your API action or the exact endpoint you're calling so I can check what’s breaking the publish?
c
Sure thing! This is the code i'm using in my action, the bot does work fine on the emulator, but I got stuck in the publishing loop. https://cdn.discordapp.com/attachments/1433924175428321370/1433958205716828220/Action_Snippet.rtf?ex=69093825&is=6907e6a5&hm=6d0424eeec7957cea996e7fe47c1c932c9f5f96797b72dd9cc22e24c9cf0a5b5&
w
hi cris! can you try publishing on another browser?
w
@creamy-gpu-4947 stupid question: if you delete action is publish ok?
c
Hello, I did try doing it in Safari and Chrome, same result. Then I deleted the Action and it worked! Now, curiosly I took my initial action code, pasted to a new action in the "Generate your action with AI" box, got new code, and publishing works, but now the bot is broken and cannot fetch from the API. What should this code not have in order to avoid the "infinite Publishing" error?
w
please post yours `consultarPaquetesInput1`and
consultarPaquetesOutput1
schema
w
I've inserted your acton with schemas in a my bot and i've published it without problem
i've changed you ifs with a `switch`:
Copy code
ts
      switch (status) {
        case 400:
          return { exito: false, mensaje: 'Los datos proporcionados parecen incorrectos.' }
        case 404:
          return { exito: false, mensaje: `No encontrĂ© ningĂșn cliente con ese ${input.tipoIdentificador}.` }
        case 429:
          return { exito: false, mensaje: 'El sistema estĂĄ procesando muchas consultas. Intenta mĂĄs tarde.' }
        case 500:
        case 503:
          return { exito: false, mensaje: 'El sistema de tracking no estĂĄ disponible. Intenta mĂĄs tarde.' }
        default:
          return { exito: false, mensaje: `Error del sistema (Error ${status}).` }
      }
this line
Copy code
ts
throw new Error('Respuesta invĂĄlida del servidor')
should be replaced by
Copy code
ts
return { exito: false, mensaje: 'Respuesta invĂĄlida del servidor' }
your output schema has a double
describe
Copy code
ts
totalPaquetes: z.optional(z.number().describe('Total number of packages')).describe('Total number of packages found')
If you create a file with code snippets, use a text file with the extension .txt, or better yet, use .ts for TypeScript.
c
I was able with much trial and error solve my problem, thanks everyone for all your help. Here is a summary of my solution: Problem: Couldn't publish bot due to Zod schema validation error in custom action. Root Causes & Solutions: Schema Issues: ❌ Using .nullable() without base type ✅ Changed to .optional() for fields that might not exist in all responses ✅ Removed double .describe() on fields (e.g., totalPaquetes had two describes) Error Handling: ❌ Using throw new Error() which doesn't match output schema ✅ Changed to return { exito: false, mensaje: '...' } format ✅ Converted if chains to switch statements for HTTP status codes Final Working Output Schema: typescriptz.object({ exito: z.boolean().describe('Indica si la consulta fue exitosa'), mensaje: z.string().describe('Mensaje formateado listo para mostrar al usuario o mensaje de error'), clienteInfo: z .object({ nombre: z.string(), codigo: z.string() }) .optional() // Not nullable, just optional .describe('Información del cliente'), paquetes: z .array( z.object({ tracking: z.string().optional(), estado: z.string(), estado_display: z.string().optional(), peso: z.string().optional(), // Simplified from union type monto_total: z.string().optional(), saldo_pendiente: z.string().optional() }) ) .optional() .describe('Lista de paquetes del cliente'), totalPaquetes: z.number().optional().describe('Cantidad total de paquetes encontrados') // Single describe only }) Line Break Issue (Production vs Emulator): ❌ Using \n characters weren't rendering in production channels ✅ Changed to literal line breaks inside template literals Key Takeaway: In Botpress, when a field might not exist in the response object, use .optional() instead of .nullable(). Reserve .nullable() for when the field exists but its value is explicitly null.
w
I'm happy to help! I like your final report