evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

Meta Webhook for WhatsApp Cloud API not working

Open denisroldan opened this issue 1 year ago • 4 comments

Welcome!

  • [X] Yes, I have searched for similar issues on GitHub and found none.

What did you do?

After deploying Evolution 2.1.0 with postgres and redis, I created an instance using WABA official Cloud API. All the prerequisites are properly done and the account is working if, for example, I connect it directly to Chatwoot. Token is correct, number ID, business ID, etc. I'm even able to get the available HSM Templates through the Evolution API (GET {{baseUrl}}/template/find/{{instance}}).

The problem is that, after registering the instance I receive:

{
    "instance": {
        "instanceName": "...",
        "instanceId": "de6c0z11-f4fc-4ce1-9664-df68719c8e5f",
        "integration": "WHATSAPP-BUSINESS",
        "webhookWaBusiness": "https://mydomain.com/webhook/meta",
        "accessTokenWaBusiness": "mySecretToken",
        "status": "created"
    },
    ...

And that URL is not working.

What did you expect?

The webhook should work as documented :)

What did you observe instead of what you expected?

When I go to facebook to register the webhook on my app, it doesn't work, showing an error. Also if I try doing it through the official Meta API I get:

{
    "error": {
        "message": "(#100) Before override the current callback uri, your app must be subscribed to receive messages for WhatsApp Business Account",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "..."
    }
}

Even if I try to do a GET request using postman to my Evolution instance, it returns a 404:

{
    "status": 404,
    "error": "Not Found",
    "response": {
        "message": [
            "Cannot GET /webhook/meta"
        ]
    }
}

Screenshots/Videos

No response

Which version of the API are you using?

2.1.0

What is your environment?

Linux

Other environment specifications

GCP Instance using NVM, pm2, Postgres and Redis. Latest repo code on v2 branch.

If applicable, paste the log output

No response

Additional Notes

This is the route that's not responding https://github.com/EvolutionAPI/evolution-api/blob/v2.0.0/src/api/integrations/event/webhook/routes/webhook.router.ts#L35

denisroldan avatar Aug 22 '24 10:08 denisroldan

Try this url in meta webhook {{base_url}}/webwook/meta/{{instance_name}}

If it still doesn't work, change the following code:

src/api/integrations/event/webhook/routes/webhook.router.ts

before:

.get('meta', async (req, res) => { if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK) res.send(req.query['hub.challenge']); else res.send('Error, wrong validation token'); }) .post('meta', async (req, res) => { const { body } = req; const response = await webhookController.receiveWebhook(body);

return res.status(200).json(response); });

after:

.get(this.routerPath('meta'),async (req, res) => { if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK) res.send(req.query['hub.challenge']); else res.send('Error, wrong validation token'); }) .post(this.routerPath('meta'), async (req, res) => { const { body } = req; const response = await webhookController.receiveWebhook(body);

return res.status(200).json(response); });

gustavosantana1 avatar Aug 22 '24 14:08 gustavosantana1

Try this url in meta webhook {{base_url}}/webwook/meta/{{instance_name}}

Didn't worked.

If it still doesn't work, change the following code:

src/api/integrations/event/webhook/routes/webhook.router.ts

before:

.get('meta', async (req, res) => { if (req.query['hub.verify_token'] === configService.get('WA_BUSINESS').TOKEN_WEBHOOK) res.send(req.query['hub.challenge']); else res.send('Error, wrong validation token'); }) .post('meta', async (req, res) => { const { body } = req; const response = await webhookController.receiveWebhook(body);

return res.status(200).json(response); });

after:

.get(this.routerPath('meta'),async (req, res) => { if (req.query['hub.verify_token'] === configService.get('WA_BUSINESS').TOKEN_WEBHOOK) res.send(req.query['hub.challenge']); else res.send('Error, wrong validation token'); }) .post(this.routerPath('meta'), async (req, res) => { const { body } = req; const response = await webhookController.receiveWebhook(body);

return res.status(200).json(response); });

I did the change, but it didn't work for me neither :/

Thanks for the quick response!

denisroldan avatar Aug 22 '24 15:08 denisroldan

@DavidsonGomes maybe you can light up a bit here? I'm happy to help and contribute, but I have no clue why it's not working right now. 😅

denisroldan avatar Aug 27 '24 08:08 denisroldan

@denisroldan Working in version v2.1.1-homolog

vagkaefer avatar Sep 18 '24 03:09 vagkaefer

try to use an recent version of evolution @denisroldan, than answer here if its running fine. i will close this issue until second order

dpaes avatar Dec 03 '24 20:12 dpaes

I have the same problem, I have a self-hosted instance of evolutionAPI, I checked my token, when I replicate the meta request, it returns the same code sent in the challenger parameter, I imagine it is the expected return, but when I define the callback URL and token on the META platform, I get this error:

"Could not validate the callback URL or verification token. Review the information provided or try again later."

i'm using "https://myinstanceurl.com/webhook/meta" (API v2) and my token, that i verified in container docker, plz help

KevennyJS avatar Apr 03 '25 14:04 KevennyJS