Documentation

Project Overview

I am building a WhatsApp bot using the Meta Cloud API. This document tracks my implementation process and troubleshoots an unexpected access token invalidation issue.

Initial Setup

whatsapp-test-number.png

Webhook Implementation

I implemented webhook connectivity using NestJS with the following approach:

// GET endpoint to verify webhook with Meta Cloud API
@Get('webhook')
async verifyWebhook(@Query() query: any, @Res() res: any) {
  const mode = query['hub.mode'];
  const token = query['hub.verify_token'];
  const challenge = query['hub.challenge'];
  
  // Verification logic
  if (mode === 'subscribe' && token === process.env.VERIFY_TOKEN) {
    return res.status(200).send(challenge);
  }
  
  return res.sendStatus(403);
}

Permanent Access Token Setup

To avoid daily token renewal, I:

meta-system-user.png

Local Development Environment

Initially used ngrok for exposing my local server to the internet, but switched to VS Code's port forwarding feature due to inconsistent public URL issues with ngrok.This public URL is required when setting up the webhook in the Meta Webhooks dashboard.

vscode port.png

Message Handling Implementation