botpress/botpress

Bot stops responding after more than 60 seconds of execute code processing

Closed this issue · 1 comments

Hi Botpress team! I have an issue I've been struggling with for some time and definitely you could shed some light.

My bot needs to API-call an external system which works in a queue based pattern:

I send a request to it and it returns me a job id
Aftwerwards, I can either poll for the job completion status through one (or many) follow-up call or wait for a callback to move on

Considerations:

  • These jobs usually take 3 to 5 minutes to complete
  • I am using the WhatsApp integration as the main delivery channel to users

Polling the service in an execute code card led me to a timeout after 60 seconds and the bot stopped responding.

I replicated this question in the Office Hours session earlier today, and Patrick suggested me to try creating several Execute Card statements to do the polling every 40 seconds or so. I implemented it and was not successful - after 60 seconds (second polling interval), the bot just stops responding and does not get back to the user and do not throw an error. I had to reset the state to get the conversation back to a working state.

The workflow implementation, Execute Code card and the user response are attached.

Workflow:
image

Execute Code:

// Auxiliary functions and constants
const POLLING_INTERVAL_MS = 40000
const TIMEOUT_INTERVAL_SECONDS = 180
const wait = (ms = 1000) => {
  return new Promise((resolve) => {
    setTimeout(resolve, ms)
  })
}

// Initialize query params
const query = `
  query IngestAdhocContentStandalonePublication($id: uuid!) {
    ingestAdhocContentStandalonePublication(id: $id) {
      // --- redacted ---
    }
  }`
const variables = { id: workflow.ingestionId }
const config = {
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': env.backend_gql_api_key
  }
}

if (workflow.ingestionStatus !== 'success' && workflow.ingestionStatus !== 'failed') {
  // Poll ingestion processing job
  const { data } = await axios.post(env.backend_gql_api_endpoint, { query, variables }, config)
  if (data.data?.errors?.length > 0 || data.data?.ingestAdhocContentStandalonePublication?.output?.postId) {
    if (data.data.errors?.length > 0) {
      // Flag failed ingestion
      workflow.ingestionStatus = 'failed'
    } else {
      // Store results in workflow variables
      const { postId, title, publisher, description } = data.data.ingestAdhocContentStandalonePublication.output
      workflow.postId = postId
      workflow.title = title
      workflow.publisher = publisher
      workflow.description = description
      workflow.ingestionStatus = 'success'
    }
  } else {
    await wait(POLLING_INTERVAL_MS)
  }
}

User response:
image

Hey there,

It looks like you're facing some trouble with Botpress Studio or Dashboard. This repository is mainly focused on integrations and developer tools like the Client, SDK, and CLI.

For the best support and help, I recommend heading over to our discord server. That's the perfect place to ask your question and get the assistance you need.

I'll go ahead and close this issue for now, but don't hesitate to open a new one if I misunderstood your concern.

Cheers,
Frank