EvolutionAPI / evolution-api

Evolution API is an open-source WhatsApp integration API
https://evolution-api.com
GNU General Public License v3.0
1.41k stars 674 forks source link

Meta Webhook for WhatsApp Cloud API not working #807

Open denisroldan opened 3 weeks ago

denisroldan commented 3 weeks ago

Welcome!

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

gustavosantana1 commented 3 weeks ago

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('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); });

denisroldan commented 3 weeks ago

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 commented 2 weeks ago

@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. 😅