How to built a Whastsapp Chatbot with Zenvia API

Hello everyone.

Please, forgive for my bad english, i’m so rusted.

I’m a brazilian marketing maneger and I have a misson to do. I’m must to build an AI agent to answer the leads/clients of my company on Whatsapp Business.

The Make Plataform have a lot of content to how do this, but, the great problem is that our Whatsapp Business Solution is hosted in Zenvia. So, to conect the Make AI Agent Module to the Whatsapp I must to use a Webhook to listen when messages arrives and use a HTTP request to send the answer created by the IA Agent to the lead/client.

When I run the scenario, it Works 1 or max 2 times. After, the scenario stops to work, sometimes show a error 500, 400. It can’t continue the conversation, and I don’t have idea how to solve this.

I read a lot of Zenvia docs at Github, but, when more I try more I faill.

Someone know how to solve this, maybe show me a blueprint of the solution?

Best regards,

Hi @Alexander_Jose_Eduar. Welcome.

The overall flow seems correct from your description. If it works eventually, then you should investigate why it stops. Maybe you can add more info about the 400/500 errors, so we can try to help.

@damato

1 Like

Hello @damato.

I’ll show some printscreens about the error.

First, take a look of my whole scenario:

And now the erro report:

Is so strange, cause, like I said, the first and/or second messages I sent are answered normaly by the Helena (the name of AI agent).

I tested with 2 different whatsapp numbers and it will happens all the times.

Some times, a 400 error is reported too.

See the report below:

Thanks for help.

Best regards

Your API call to Zenvia seems to be correct. That’s why it does work sometimes.

You have two different issues here.

The first one, with the 500 error, is a generic server error. This error means that something went wrong while processing your request and the service you were calling can do nothing about it but fail. The best you can do here is to retry the call after some time.

The second one, 400, is an error in your request. The message says that the value of “text” inside your “contents” array is empty. According to Zenvia’s docs, this field is mandatory. It’s the actual message to be sent.

I suppose you are mapping the return of your agent to this field. So, when this error happens, you need to check the Agent module to find out why it gave you an empty response. Fix that, retry when you get 500 and it should work.

@damato

@damato I have good news!!!

I did solve the issue… The AI Agent generate the answers with line breaks, and send to the HTTP Request module with this “literal“ line breaks. The Json must to convert line break to \n, but it wasn’t happens.

First I’ve tried to search and replace using replace(response; \n; \\n). but it also wasn’t work. So went to the easier path, I put a rule in the IA Agent prompt asking to don’t use break line at the answers.

Now, it works perfectly… That was the paliative solution that I found, but, I think that has a better way to do it.

Thanks a lot for your help… I’ll continue my studies to be a Make expert like you. =D

3 Likes