14 Replies
give me a minute.
am using this code snippet such that when a whatsapp message is received, we do some checks and then store the message, then, we call a function to process the request from whatsapp through
the function handles getting the message and processing the message through an llm, then sends the message back to the number, but am getting a response sometimes and not all times.
initially I thought maybe the llm is not calling tools that are supposed to send the message but when I added console logs, I realized the function is not being called in the first place, and as I said it does this sometimes and sometimes it does not, under the same conditions, without changing any code, and am messaging from the same number.
here is a snippet of the inbound function
You definitely don't need try catch in convex functions
But that's not the problem
what could be the problem?
I'm still reading the code
that's too much to take in one go
in the first message you have two if statements doing the same thing,
if (needsCache) {
and
} else if (needsCache) {
and the schedulers aren't getting called unless if media !messageData.fromMe
It looks like that's what's causing your issue, and this is what you should look into, if its true, it works but if the second if statements doesn't go through, it would also not work
you should do some debugging from the for loop. -> first if statment -> second if statment
And a snippet is a minimal reproduction, not your whole code base 😂well these needsCache are scoped differently, I dont know If you read that correctly, the first one is if the message is from me, we and i have sent an image through whatsapp, we cache the media but we dont respond because I dont want it to get into the loop of answering every message that comes in including the one sent by the bot, but if the message is not from me, i.e from a different number, we also cache if there is any media that has been sent, but then we schedule a function call for responding to that user.
They looked under the same if statement, sorry I'm reading this on a phone
so is not being wrongly called. Then am using 2 different numbers for testing, one is connected to be the automatic bot answering, and the other one is for sending the message, so should also not be an issue because am using 2 different numbers for testing.
but when send a message to the other number sometimes it responds sometimes it does not. I have tried to cross check the code for any logic errors but am not finding any, and even if there were logic errors, that is not the problem, the problem is the code is running until I see the message, which is directly immediate to the scheduling code, yet the console log in the function is not appearing meaning no function was scheduled. I dont know if you understood the point?
You need to log inside each individual if statements to see if they're being called
Even if the logic was wrong, but we got to the point of calling the console.log directly above the scheduling function i would assume the function needs to be scheduled anyway, irregardless of whether the logic was wrong or not.
because am getting the message from the console.log directly above the scheduling function but not the console.log message directly at the beginning of the inbound function, meaning the function was not scheduled and it did not run.
Can you share logs showing the working-then-not-working in action
Ngl, it's the if statements they got doing some :discord_sparkles: magical things :discord_sparkles: