How to handle function execute 2 times in same time

Hi Team
Need advice to solve my issue, I’m facing issue the function execute 2 times in same time. This bot in app and using Whatsapp channel. The issue is when bot asking user query to connect agent, and user typing their query 2 messages in close time, because of this 2 messages the bot executing next function 2 times too and hit api 2 times too, as result the api gave error code 409 duplicate message.
Any idea to handle this issue so when user typing 2 messages in close time the function only execute 1 time only. Thank you

Hi @Syarif ,

  1. According to your issue, at any point in WA 2 back to message before arrival of next action will result in execution repeat as per last intent context. But generally, even in WA the average response time should be <1.3 sec. User should be able to type 1 message each time.
  2. Bot will only process 1 message under 1 prompt across anywhere in a bot. In case one deliberately types fast to invoke 2 messages, at the order or time the next message arrive wrt the already execution of the 1st message will be handled by a next fallback.
  3. In your case where you have trouble of API getting called twice, and when the in 2nd time you get error from API as a duplicate suggesting that only 1 message must be processed,
    You can assign a custom profile/variable property to assign it with ‘executed’ and update the profile once the API executes for the first time. To execute the API, you should check if the profile/variable value is != ‘executed’, so that it executes only once. Once you choose to proceed to next step or conversation, assign the custom profile property/variable to null and update.
  4. Usually user wont get the time to send 2 texts in 1 prompt. If API takes time, render a text before so that it already passes away to the next step.
  5. Please check with Infra team if your WA account is slow.
  6. Execute API in next step/action node, not in same validator. That way you will avoid context concurrence of 2 messages having to execute under same prompt if API execution is slow

Hope it helps!

1 Like

Hi @Subhrajit_Gupta
Thank you for your input and explanation, but actually for number 3,4, and 6 I already implemented that, but this issue still happen, especially for number 3, because the function executed in same time so the condition profile I made didn’t work.
Number 5 maybe the solution, I will try check it. once again thank you for the advice :pray: