baptisteArno / typebot.io

💬 Typebot is a powerful chatbot builder that you can self-host.
https://typebot.io
Other
6.79k stars 1.83k forks source link

Webhook triggered as the flow starts #1144

Closed pedrofnts closed 6 months ago

pedrofnts commented 7 months ago

I'm using Typebot integrated with Evolution API. After bot starts, I have a text bubble that says "Hello", and next there's a webhook that makes a POST call. Basically, it sends a lists on WhatsApp. The problem is that the webhook is being triggered BEFORE the "Hello" is sent.

You can see that's not a problem with the integration, because it happens even in web interface (note in the screenshot that webhook is called even before the remoteJid (necessary on the request) is set (resulting in an error).

I've tried many approaches, like putting a wait, redirecting to group, but the problem remains with all of them.

I've tried it with:

In all cases, the problem remains.

Any way of adjusting this?

Captura de Tela 2024-01-10 às 17 42 39

pedrofnts commented 7 months ago

This is also happening on Typebot.io (cloud version). Notice how the webhook gets triggered just after the webhook starts, before the messages are sent and also before the wait block. This does not to seems a bug. Any way to adjust this behavior? @baptisteArno

Captura de Tela 2024-01-10 às 18 47 57

vforvilela commented 7 months ago

"Under the hood, typebot always compute all the blocks between each input blocks." Source: https://docs.typebot.io/editor/blocks/logic/wait

So the solution is to include a wait block with zero seconds and "pause the flow" enabled before the webhook call.

pedrofnts commented 7 months ago

If I enable "pause the flow", client needs to send a message before the flow continues. I need messages to be sent in a queue, without user interaction.

vforvilela commented 7 months ago

Have you tried?

image

image

pedrofnts commented 7 months ago

Yeah, unfortunately it only works on web. Through API the bot restarts.

Captura de Tela 2024-01-10 às 23 45 42

Captura de Tela 2024-01-10 às 23 44 55
baptisteArno commented 7 months ago

Indeed that is a current limitation in WhatsApp. This is an issue because your webhook takes a long time to respond?

pedrofnts commented 7 months ago

Nope, it's an issue because I have the need to send documents to clients. These documents are personal and exclusive, so they are sent through an webhook that sends a doc through my WhatsApp API. I need to create a flow like:

[message] Here's your report. [webhook] send file [message] Here's your assessment. [webhook] send file

With the actual scenario, when bot starts, and files are sent immediately, and messages are sent later. This breaks the entire flow.

baptisteArno commented 7 months ago

So the webhooks send WhatsApp messages? 🤔

pedrofnts commented 7 months ago

Yes! We need the webhook to send pdfs.

baptisteArno commented 7 months ago

Ok then I guess you could make it work directly on Typebot. Typebot should be able to send documents as text bubbles.

I'll work on that soon, then you won't need to use the webhook blocks.

Can you provide the PDF URLs you intend to use?

MarksEliel commented 7 months ago

I have the same problem here, the webhook is always sent before any other item even if different groups.

uelintonpessoa commented 6 months ago

@baptisteArno

n fact, any API is triggered first.

We need the API to be triggered according to the construction of the flow, regardless of what the API is.

Example Flow:

Message sent<< API triggered<< Message sent<< Message sent<< Message sent<< And finished with API being activated last Final API Triggered<<

This is the big question we face!

baptisteArno commented 6 months ago

I have the same problem here, the webhook is always sent before any other item even if different groups.

How do you see that? Can you record a video to show us?

I struggle to understand exactly why you need that.

cbalbinos commented 6 months ago

Hi @baptisteArno

Webhooks are executed at the moment the flow is started, regardless of the position the block is in the flow

I have a use case where text and audio messages are sent with a wait between them and two webhooks that trigger workflows on the n8n, which should return personalized image links with information about the time the Workflow was started, after waits of 20 and 7 minutes , but as both are triggered when the flow starts, the images are generated at the same time

I even tried using n8n's wait, but it doesn't work because Typebot's webhook has a timeout of up to 120 seconds

I'm using Typebot self hosted with version selfhost 2.22.0

baptisteArno commented 6 months ago

Does that somehow help clarify things?

https://docs.typebot.io/editor/blocks/integrations/webhook#webhook-is-not-executed-in-the-right-order

cbalbinos commented 6 months ago

This works in the browser, but unfortunately it doesn't work on WhatsApp

baptisteArno commented 6 months ago

Indeed! It won't work in WhatsApp. That's a limitation of the Typebot engine 🙏

lgertel commented 6 months ago

Ok then I guess you could make it work directly on Typebot. Typebot should be able to send documents as text bubbles.

I'll work on that soon, then you won't need to use the webhook blocks.

Can you provide the PDF URLs you intend to use?

@baptisteArno any news on something like this?

flavioxx commented 6 months ago

I also have the same problem, I use the WhatsApp API for integration and the webhook is always executed first unfortunately.

baptisteArno commented 6 months ago

Ok then I guess you could make it work directly on Typebot. Typebot should be able to send documents as text bubbles. I'll work on that soon, then you won't need to use the webhook blocks. Can you provide the PDF URLs you intend to use?

@baptisteArno any news on something like this?

Can you open a new issue and provide PDF urls as example?

lhonay commented 4 months ago

Did anyone manage to solve it?

demesiooliveira commented 1 month ago

Did anyone manage to solve it?

lhonay commented 1 month ago

yes, in my case it was the API