{"id":2177,"date":"2026-11-24T19:29:48","date_gmt":"2026-11-24T19:29:48","guid":{"rendered":"https:\/\/vectalk.com.br\/blog\/whatsapp-api-nestjs\/"},"modified":"2026-11-24T19:29:52","modified_gmt":"2026-11-24T19:29:52","slug":"whatsapp-api-nestjs","status":"publish","type":"post","link":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/","title":{"rendered":"WhatsApp API with NestJS: webhook and sending module"},"content":{"rendered":"\n<p><em>Updated on November 24, 2026<\/em><\/p>\n\n\n\n<p>To use the WhatsApp Business API with NestJS, build a <code>WhatsappModule<\/code> with three pieces: a controller that verifies the webhook and validates the <code>X-Hub-Signature-256<\/code> signature against the raw body (enabled with <code>rawBody: true<\/code> in <code>NestFactory.create<\/code>), a service that sends the <code>POST<\/code> to the <code>\/messages<\/code> endpoint, and a BullMQ queue that processes events and outgoing messages with retry. Two details break most integrations: Nest&#8217;s POST handlers return <code>201<\/code> by default, and the signature won&#8217;t match if you compute it over the already-parsed JSON.<\/p>\n\n\n\n<p>The <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-bot-nodejs-express\/\">WhatsApp bot with Node.js and Express<\/a> walks through the basic flow in plain JavaScript. Here the goal is to fit the same logic into Nest&#8217;s structure: modules, dependency injection, queues and tests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Module structure<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">npm install --save @nestjs\/bullmq bullmq ioredis<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">src\/\n  main.ts\n  app.module.ts\n  whatsapp\/\n    whatsapp.module.ts\n    whatsapp.controller.ts\n    whatsapp.service.ts\n    whatsapp.processor.ts\n    signature.ts<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>File<\/th><th>Responsibility<\/th><\/tr><\/thead><tbody><tr><td><code>main.ts<\/code><\/td><td>Create the application with <code>rawBody: true<\/code><\/td><\/tr><tr><td><code>whatsapp.controller.ts<\/code><\/td><td>Verification <code>GET<\/code> and webhook <code>POST<\/code><\/td><\/tr><tr><td><code>signature.ts<\/code><\/td><td>Validate the HMAC-SHA256 in constant time<\/td><\/tr><tr><td><code>whatsapp.service.ts<\/code><\/td><td>Send text and template messages to the API<\/td><\/tr><tr><td><code>whatsapp.processor.ts<\/code><\/td><td>Consume the queue: process events and send replies<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">main.ts: enabling the raw body<\/h2>\n\n\n\n<p>The webhook signature is an HMAC-SHA256 of the exact body Meta sent, according to <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Meta&#8217;s webhook endpoint page<\/a>. Nest&#8217;s body parser turns that body into an object, and re-serializing it with <code>JSON.stringify<\/code> does not give you back the same bytes. The <a href=\"https:\/\/docs.nestjs.com\/faq\/raw-body\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS raw body page<\/a> solves this with a single option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/main.ts\nimport { NestFactory } from '@nestjs\/core';\nimport type { NestExpressApplication } from '@nestjs\/platform-express';\nimport { AppModule } from '.\/app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create&lt;NestExpressApplication&gt;(AppModule, {\n    rawBody: true,\n  });\n  await app.listen(process.env.PORT ?? 3000);\n}\nbootstrap();<\/code><\/pre>\n\n\n\n<p>The documentation warns that this only works with the global body parser enabled, so don&#8217;t pass <code>bodyParser: false<\/code>. With <code>rawBody: true<\/code>, <code>req.rawBody<\/code> is available as a <code>Buffer<\/code> and <code>@Body()<\/code> keeps working normally on every other route.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">app.module.ts and whatsapp.module.ts<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/app.module.ts\nimport { Module } from '@nestjs\/common';\nimport { BullModule } from '@nestjs\/bullmq';\nimport { WhatsappModule } from '.\/whatsapp\/whatsapp.module';\n\n@Module({\n  imports: [\n    BullModule.forRoot({\n      connection: {\n        host: process.env.REDIS_HOST ?? 'localhost',\n        port: Number(process.env.REDIS_PORT ?? 6379),\n      },\n    }),\n    WhatsappModule,\n  ],\n})\nexport class AppModule {}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/whatsapp.module.ts\nimport { Module } from '@nestjs\/common';\nimport { BullModule } from '@nestjs\/bullmq';\nimport { WhatsappController } from '.\/whatsapp.controller';\nimport { WhatsappService } from '.\/whatsapp.service';\nimport { WhatsappProcessor } from '.\/whatsapp.processor';\n\n@Module({\n  imports: [BullModule.registerQueue({ name: 'whatsapp' })],\n  controllers: [WhatsappController],\n  providers: [WhatsappService, WhatsappProcessor],\n  exports: [WhatsappService],\n})\nexport class WhatsappModule {}<\/code><\/pre>\n\n\n\n<p><code>forRoot<\/code> and <code>registerQueue<\/code> follow the <a href=\"https:\/\/docs.nestjs.com\/application\/queues\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS queues page<\/a>. Exporting <code>WhatsappService<\/code> lets other modules (orders, billing) send messages without knowing the API details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Signature validation<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/signature.ts\nimport { createHmac, timingSafeEqual } from 'node:crypto';\n\nexport function isValidSignature(\n  raw: Buffer | undefined,\n  header: string | undefined,\n  secret: string,\n): boolean {\n  if (!raw || !header) return false;\n  const expected = Buffer.from(\n    'sha256=' + createHmac('sha256', secret).update(raw).digest('hex'),\n  );\n  const received = Buffer.from(header);\n  return expected.length === received.length &amp;&amp; timingSafeEqual(expected, received);\n}<\/code><\/pre>\n\n\n\n<p>Node&#8217;s <code>timingSafeEqual<\/code> throws when the buffers have different lengths, which is why the <code>length<\/code> check comes first. Keeping the function in its own file makes it easy to unit test. The same algorithm in other languages is covered in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-signature-validation\/\">how to validate the webhook signature<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The controller<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/whatsapp.controller.ts\nimport {\n  Controller,\n  Get,\n  Header,\n  Headers,\n  HttpCode,\n  Post,\n  Query,\n  Req,\n  ForbiddenException,\n  UnauthorizedException,\n  type RawBodyRequest,\n} from '@nestjs\/common';\nimport { InjectQueue } from '@nestjs\/bullmq';\nimport { Queue } from 'bullmq';\nimport type { Request } from 'express';\nimport { isValidSignature } from '.\/signature';\n\n@Controller('whatsapp')\nexport class WhatsappController {\n  constructor(@InjectQueue('whatsapp') private readonly queue: Queue) {}\n\n  @Get('webhook')\n  @Header('Content-Type', 'text\/plain')\n  verify(@Query() query: Record&lt;string, string&gt;): string {\n    if (\n      query['hub.mode'] === 'subscribe' &amp;&amp;\n      query['hub.verify_token'] === process.env.WA_VERIFY_TOKEN\n    ) {\n      return query['hub.challenge'] ?? '';\n    }\n    throw new ForbiddenException();\n  }\n\n  @Post('webhook')\n  @HttpCode(200)\n  async receive(\n    @Req() req: RawBodyRequest&lt;Request&gt;,\n    @Headers('x-hub-signature-256') signature: string | undefined,\n  ): Promise&lt;{ ok: true }&gt; {\n    if (!isValidSignature(req.rawBody, signature, process.env.META_APP_SECRET ?? '')) {\n      throw new UnauthorizedException();\n    }\n    await this.queue.add('inbound', req.body, {\n      attempts: 5,\n      backoff: { type: 'exponential', delay: 1000 },\n      removeOnComplete: 1000,\n    });\n    return { ok: true };\n  }\n}<\/code><\/pre>\n\n\n\n<p>The points that generate the most support tickets:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>@HttpCode(200)<\/code>.<\/strong> The <a href=\"https:\/\/docs.nestjs.com\/controllers\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS controllers documentation<\/a> says the default status is <code>200<\/code>, except for <code>POST<\/code>, which returns <code>201<\/code>. Meta expects <code>200<\/code>, so make it explicit.<\/li>\n\n\n<li><strong>The whole <code>@Query()<\/code> object.<\/strong> The verification parameters have dots in their names (<code>hub.mode<\/code>, <code>hub.verify_token<\/code>, <code>hub.challenge<\/code>). Reading the whole object and accessing <code>query['hub.mode']<\/code> avoids surprises with the query string parser.<\/li>\n\n\n<li><strong><code>@Header('Content-Type', 'text\/plain')<\/code>.<\/strong> The challenge must be returned as-is, without JSON quotes.<\/li>\n\n\n<li><strong>No heavy logic in the handler.<\/strong> The controller only validates and enqueues. Calling an AI model, a CRM or the WhatsApp API itself before responding delays the <code>200<\/code> and triggers redeliveries.<\/li>\n\n<\/ul>\n\n\n\n<p><code>req.body<\/code> is still available because the JSON parser stays active. If you&#8217;d rather process exactly the signed bytes, enqueue <code>req.rawBody.toString('utf8')<\/code> and run <code>JSON.parse<\/code> in the worker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The sending service<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/whatsapp.service.ts\nimport { Injectable, Logger } from '@nestjs\/common';\n\nconst RETRYABLE = new Set([130429, 131000, 131016, 131056]);\n\nexport class WhatsappApiError extends Error {\n  constructor(\n    message: string,\n    readonly code: number | undefined,\n    readonly retryable: boolean,\n  ) {\n    super(message);\n  }\n}\n\n@Injectable()\nexport class WhatsappService {\n  private readonly logger = new Logger(WhatsappService.name);\n  private readonly url = process.env.WA_SEND_URL ?? '';\n  private readonly token = process.env.WA_TOKEN ?? '';\n\n  sendText(to: string, body: string): Promise&lt;string&gt; {\n    return this.send({ to, type: 'text', text: { body } });\n  }\n\n  sendTemplate(to: string, name: string, lang: string, params: string[]): Promise&lt;string&gt; {\n    return this.send({\n      to,\n      type: 'template',\n      template: {\n        name,\n        language: { code: lang },\n        components: [\n          { type: 'body', parameters: params.map((text) =&gt; ({ type: 'text', text })) },\n        ],\n      },\n    });\n  }\n\n  private async send(message: Record&lt;string, unknown&gt;): Promise&lt;string&gt; {\n    const res = await fetch(this.url, {\n      method: 'POST',\n      headers: {\n        Authorization: `Bearer ${this.token}`,\n        'Content-Type': 'application\/json',\n      },\n      body: JSON.stringify({ messaging_product: 'whatsapp', ...message }),\n      signal: AbortSignal.timeout(15_000),\n    });\n    const data = await res.json().catch(() =&gt; ({}));\n\n    if (!res.ok) {\n      const code: number | undefined = data?.error?.code;\n      const retryable = res.status &gt;= 500 || (code !== undefined &amp;&amp; RETRYABLE.has(code));\n      this.logger.warn(`Send failed: ${code} ${data?.error?.message}`);\n      throw new WhatsappApiError(data?.error?.message ?? res.statusText, code, retryable);\n    }\n    return data.messages[0].id as string;\n  }\n}<\/code><\/pre>\n\n\n\n<p>The service uses Node.js&#8217;s native <code>fetch<\/code>, with no extra dependency. The URL comes from <code>WA_SEND_URL<\/code>: on the WhatsApp Cloud API directly, that&#8217;s <code>https:\/\/graph.facebook.com\/v27.0\/&lt;PHONE_NUMBER_ID&gt;\/messages<\/code>, per <a href=\"https:\/\/developers.facebook.com\/docs\/whatsapp\/cloud-api\/guides\/send-messages\" target=\"_blank\" rel=\"noreferrer noopener\">Meta&#8217;s send messages page<\/a>. A successful response includes the <code>wamid<\/code> in <code>messages[0].id<\/code>, but that only means Meta accepted the request; delivery is confirmed later, through the statuses in the webhook.<\/p>\n\n\n\n<p>The codes in <code>RETRYABLE<\/code> come from <a href=\"https:\/\/developers.facebook.com\/docs\/whatsapp\/cloud-api\/support\/error-codes\" target=\"_blank\" rel=\"noreferrer noopener\">Meta&#8217;s error code list<\/a>: <code>130429<\/code> (throughput limit), <code>131056<\/code> (too many messages to the same contact in a short time), <code>131016<\/code> (service unavailable) and <code>131000<\/code> (unknown error). Errors such as <code>131047<\/code> (outside the 24-hour window), <code>132000<\/code> (parameters don&#8217;t match the template) and <code>190<\/code> (expired token) don&#8217;t get better with a retry. See the annotated list in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-error-codes\/\">WhatsApp API error codes<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The queue processor<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/whatsapp.processor.ts\nimport { InjectQueue, Processor, WorkerHost } from '@nestjs\/bullmq';\nimport { Job, Queue, UnrecoverableError } from 'bullmq';\nimport { WhatsappApiError, WhatsappService } from '.\/whatsapp.service';\n\ntype SendJob = { to: string; body: string };\n\n@Processor('whatsapp')\nexport class WhatsappProcessor extends WorkerHost {\n  constructor(\n    private readonly wa: WhatsappService,\n    @InjectQueue('whatsapp') private readonly queue: Queue,\n  ) {\n    super();\n  }\n\n  async process(job: Job): Promise&lt;unknown&gt; {\n    if (job.name === 'inbound') return this.handleInbound(job.data);\n    if (job.name === 'send-text') return this.handleSend(job.data as SendJob);\n    return undefined;\n  }\n\n  private async handleInbound(payload: any): Promise&lt;void&gt; {\n    for (const entry of payload?.entry ?? []) {\n      for (const change of entry.changes ?? []) {\n        const value = change.value ?? {};\n\n        for (const msg of value.messages ?? []) {\n          if (!(await markAsSeen(msg.id))) continue; \/\/ duplicate\n          if (msg.type === 'text') {\n            await this.queue.add(\n              'send-text',\n              { to: msg.from, body: 'We got your message. We will reply shortly.' },\n              { jobId: `reply-${msg.id}`, attempts: 5, backoff: { type: 'exponential', delay: 2000 } },\n            );\n          }\n        }\n\n        for (const st of value.statuses ?? []) {\n          await saveStatus(st.id, st.status, st.errors?.[0]?.code);\n        }\n      }\n    }\n  }\n\n  private async handleSend(data: SendJob): Promise&lt;string&gt; {\n    try {\n      return await this.wa.sendText(data.to, data.body);\n    } catch (err) {\n      if (err instanceof WhatsappApiError &amp;&amp; !err.retryable) {\n        throw new UnrecoverableError(err.message);\n      }\n      throw err;\n    }\n  }\n}\n\n\/\/ Implement with Redis (SET NX) or a unique index in the database.\ndeclare function markAsSeen(wamid: string): Promise&lt;boolean&gt;;\ndeclare function saveStatus(wamid: string, status: string, code?: number): Promise&lt;void&gt;;<\/code><\/pre>\n\n\n\n<p>According to the <a href=\"https:\/\/docs.nestjs.com\/application\/queues\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS queues page<\/a>, the consumer is a class decorated with <code>@Processor('queue-name')<\/code> that extends <code>WorkerHost<\/code> and implements <code>process()<\/code>, registered as a provider in the module. The <code>attempts<\/code> and <code>backoff<\/code> (fixed or exponential) options come from BullMQ: without <code>attempts<\/code> the job is not retried, and without <code>backoff<\/code> it is retried immediately, according to the <a href=\"https:\/\/docs.bullmq.io\/guide\/retrying-failing-jobs\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ retry documentation<\/a>.<\/p>\n\n\n\n<p>Two things to watch:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>jobId<\/code> helps, but it doesn&#8217;t replace deduplication in the database.<\/strong> BullMQ ignores a job with a repeated <code>jobId<\/code>, but the <a href=\"https:\/\/docs.bullmq.io\/guide\/jobs\/job-ids\" target=\"_blank\" rel=\"noreferrer noopener\">Job IDs documentation<\/a> warns that jobs already removed (by <code>removeOnComplete<\/code>, for example) don&#8217;t count as duplicates. That&#8217;s why <code>markAsSeen<\/code> stores the <code>wamid<\/code> in Redis or in the database under a unique key. The full topic is covered in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-duplicate-events-idempotency\/\">duplicate webhooks and idempotency<\/a>.<\/li>\n\n\n<li><strong>Permanent errors should not be retried.<\/strong> BullMQ&#8217;s <code>UnrecoverableError<\/code> moves the job to the failed set without further attempts, ignoring <code>attempts<\/code>, according to the <a href=\"https:\/\/docs.bullmq.io\/patterns\/stop-retrying-jobs\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ documentation<\/a>. Use it for <code>131047<\/code>, <code>132000<\/code>, <code>190<\/code> and similar errors.<\/li>\n\n<\/ul>\n\n\n\n<p>To control the sending pace in large campaigns, the BullMQ worker accepts the <code>limiter<\/code> option (<code>max<\/code> jobs every <code>duration<\/code> milliseconds), which applies to the whole queue, even with multiple workers, according to the <a href=\"https:\/\/docs.bullmq.io\/guide\/rate-limiting\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ rate limiting documentation<\/a>. The complete architecture is in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-queue-redis-bullmq\/\">WhatsApp API sending queue with Redis and BullMQ<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending from another module<\/h2>\n\n\n\n<p>With <code>WhatsappService<\/code> exported, any module that imports <code>WhatsappModule<\/code> can send templates:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/orders\/orders.service.ts\nimport { Injectable } from '@nestjs\/common';\nimport { WhatsappService } from '..\/whatsapp\/whatsapp.service';\n\n@Injectable()\nexport class OrdersService {\n  constructor(private readonly wa: WhatsappService) {}\n\n  async confirm(order: { phone: string; customer: string; number: string }) {\n    \/\/ save the order first; only then notify the customer\n    return this.wa.sendTemplate(order.phone, 'confirmacao_pedido', 'pt_BR', [\n      order.customer,\n      order.number,\n    ]);\n  }\n}<\/code><\/pre>\n\n\n\n<p>Outside the 24-hour window, only approved templates can be sent. In production, put this send on the queue as well, so you get retries without blocking the request that created the order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing the controller<\/h2>\n\n\n\n<p>A unit test for the signature needs neither Nest nor the network:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-ts\">\/\/ src\/whatsapp\/signature.spec.ts\nimport { createHmac } from 'node:crypto';\nimport { isValidSignature } from '.\/signature';\n\nconst secret = 'test-secret';\nconst body = Buffer.from('{\"object\":\"whatsapp_business_account\",\"entry\":[]}');\nconst sign = (b: Buffer) =&gt; 'sha256=' + createHmac('sha256', secret).update(b).digest('hex');\n\ndescribe('isValidSignature', () =&gt; {\n  it('accepts a correct signature', () =&gt; {\n    expect(isValidSignature(body, sign(body), secret)).toBe(true);\n  });\n\n  it('rejects a modified body', () =&gt; {\n    const altered = Buffer.from(body.toString().replace('[]', '[{}]'));\n    expect(isValidSignature(altered, sign(body), secret)).toBe(false);\n  });\n\n  it('rejects a missing header or one with a different length', () =&gt; {\n    expect(isValidSignature(body, undefined, secret)).toBe(false);\n    expect(isValidSignature(body, 'sha256=abc', secret)).toBe(false);\n  });\n});<\/code><\/pre>\n\n\n\n<p>For end-to-end tests, NestJS integrates with Supertest through <code>Test.createTestingModule<\/code> and <code>createNestApplication<\/code>, as shown in the <a href=\"https:\/\/docs.nestjs.com\/fundamentals\/testing\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS testing documentation<\/a>. Payload fixtures, flow tests and using Meta&#8217;s test number are covered in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/test-whatsapp-bot-automated-tests\/\">how to test a WhatsApp bot<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to do this with Vectalk<\/h2>\n\n\n\n<p>Vectalk is a proxy for the official WhatsApp Cloud API with the same payloads, so the module doesn&#8217;t change. Just adjust the variables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>WA_SEND_URL=https:\/\/apis.vectalk.com.br\/api\/messages<\/code> and <code>WA_TOKEN<\/code> set to the token created under <strong>Settings \u2192 API Tokens (Configura\u00e7\u00f5es \u2192 API Tokens)<\/strong>, as in the <a href=\"https:\/\/docs.vectalk.com.br\/quickstart\">quickstart guide<\/a>.<\/li>\n\n\n<li>With an instance token, the <code>phone_number_id<\/code> is resolved automatically; with an organization token, include <code>phone_number_id<\/code> in the body, per the <a href=\"https:\/\/docs.vectalk.com.br\/authentication\">authentication page<\/a>. Media uploads and templates require an instance token.<\/li>\n\n\n<li>Register the controller URL with <code>POST https:\/\/apis.vectalk.com.br\/api\/webhooks<\/code> (<code>instance_id<\/code>, <code>url<\/code>, <code>name<\/code>). The Hub forwards the same payload Meta sends and expects a <code>200<\/code> within 20 seconds, according to the <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk webhooks documentation<\/a>.<\/li>\n\n<\/ul>\n\n\n\n<p>Vectalk&#8217;s documentation does not describe a signature header on forwarded requests. Protect the route with your own secret in the registered URL (for example, <code>?key=...<\/code> validated in a guard) and confirm with the team through the <a href=\"https:\/\/vectalk.com.br\/contato.html\">contact page<\/a>. To get started, <a href=\"https:\/\/apps.vectalk.com.br\/register\">create your account<\/a>. For the big picture, see the <a href=\"https:\/\/vectalk.com.br\/blog\/en\/official-whatsapp-api\/\">official WhatsApp API<\/a> guide; the same integration in Python is in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-django\/\">WhatsApp API with Django<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Why doesn&#8217;t the signature match even with the correct app secret?<\/h3>\n\n\n\n<p>Almost always because the hash is being computed over <code>JSON.stringify(req.body)<\/code> instead of <code>req.rawBody<\/code>. Make sure <code>rawBody: true<\/code> is set in <code>NestFactory.create<\/code> and that no custom middleware has disabled the body parser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does it work with Fastify instead of Express?<\/h3>\n\n\n\n<p>Yes. The <a href=\"https:\/\/docs.nestjs.com\/faq\/raw-body\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS raw body page<\/a> shows the same option with <code>FastifyAdapter<\/code>, typing the request as <code>RawBodyRequest&lt;FastifyRequest&gt;<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need Redis to get started?<\/h3>\n\n\n\n<p>For a prototype, you can call the service directly from the controller after responding, but you lose retries and reprocessing. In production, use the queue: BullMQ persists jobs in Redis and resumes pending ones when the application restarts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I keep the same customer from getting a duplicate reply?<\/h3>\n\n\n\n<p>Deduplicate by the <code>wamid<\/code> of the incoming message using shared storage (Redis with <code>SET NX<\/code> or a unique index in the database). Local memory won&#8217;t work when you run more than one instance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Where can I see the fields for each message type and status?<\/h3>\n\n\n\n<p>In <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-payload-examples\/\">webhook payload examples<\/a> and in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-message-status-webhook\/\">message status via webhook<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Official sources consulted on November 24, 2026:<\/strong> <a href=\"https:\/\/developers.facebook.com\/docs\/whatsapp\/cloud-api\/guides\/send-messages\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: send messages<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: create a webhook endpoint<\/a>, <a href=\"https:\/\/developers.facebook.com\/docs\/whatsapp\/cloud-api\/support\/error-codes\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: error codes<\/a>, <a href=\"https:\/\/docs.nestjs.com\/faq\/raw-body\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS: raw body<\/a>, <a href=\"https:\/\/docs.nestjs.com\/controllers\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS: controllers<\/a>, <a href=\"https:\/\/docs.nestjs.com\/application\/queues\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS: queues<\/a>, <a href=\"https:\/\/docs.nestjs.com\/fundamentals\/testing\" target=\"_blank\" rel=\"noreferrer noopener\">NestJS: testing<\/a>, <a href=\"https:\/\/docs.bullmq.io\/guide\/retrying-failing-jobs\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ: retrying jobs<\/a>, <a href=\"https:\/\/docs.bullmq.io\/guide\/jobs\/job-ids\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ: Job IDs<\/a>, <a href=\"https:\/\/docs.bullmq.io\/guide\/rate-limiting\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ: rate limiting<\/a>, <a href=\"https:\/\/docs.bullmq.io\/patterns\/stop-retrying-jobs\" target=\"_blank\" rel=\"noreferrer noopener\">BullMQ: stop retrying jobs<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/quickstart\">Vectalk: quickstart<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/authentication\">Vectalk: authentication<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk: webhooks<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A complete NestJS module for the official WhatsApp Business API: webhook verification, raw body signature check, sending service and a queue with retry.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-2177","post","type-post","status-publish","format-standard","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WhatsApp API with NestJS: webhook and sending | Vectalk<\/title>\n<meta name=\"description\" content=\"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WhatsApp API with NestJS: webhook and sending | Vectalk\" \/>\n<meta property=\"og:description\" content=\"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Vectalk\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-24T19:29:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-24T19:29:52+00:00\" \/>\n<meta name=\"author\" content=\"wanderleyfcunha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"wanderleyfcunha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/\"},\"author\":{\"name\":\"wanderleyfcunha\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"headline\":\"WhatsApp API with NestJS: webhook and sending module\",\"datePublished\":\"2026-11-24T19:29:48+00:00\",\"dateModified\":\"2026-11-24T19:29:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/\"},\"wordCount\":1221,\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/\",\"name\":\"WhatsApp API with NestJS: webhook and sending | Vectalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\"},\"datePublished\":\"2026-11-24T19:29:48+00:00\",\"dateModified\":\"2026-11-24T19:29:52+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"description\":\"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-nestjs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WhatsApp API with NestJS: webhook and sending module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\",\"name\":\"Blog Vectalk\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\",\"name\":\"wanderleyfcunha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"caption\":\"wanderleyfcunha\"},\"sameAs\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WhatsApp API with NestJS: webhook and sending | Vectalk","description":"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/","og_locale":"en_US","og_type":"article","og_title":"WhatsApp API with NestJS: webhook and sending | Vectalk","og_description":"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.","og_url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/","og_site_name":"Blog Vectalk","article_published_time":"2026-11-24T19:29:48+00:00","article_modified_time":"2026-11-24T19:29:52+00:00","author":"wanderleyfcunha","twitter_card":"summary_large_image","twitter_misc":{"Written by":"wanderleyfcunha","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/#article","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/"},"author":{"name":"wanderleyfcunha","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"headline":"WhatsApp API with NestJS: webhook and sending module","datePublished":"2026-11-24T19:29:48+00:00","dateModified":"2026-11-24T19:29:52+00:00","mainEntityOfPage":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/"},"wordCount":1221,"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/","url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/","name":"WhatsApp API with NestJS: webhook and sending | Vectalk","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/#website"},"datePublished":"2026-11-24T19:29:48+00:00","dateModified":"2026-11-24T19:29:52+00:00","author":{"@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"description":"WhatsApp API NestJS guide: webhook controller, raw body for signature validation, sending service and a BullMQ queue with retry. Full TypeScript code.","breadcrumb":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-nestjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vectalk.com.br\/blog\/"},{"@type":"ListItem","position":2,"name":"WhatsApp API with NestJS: webhook and sending module"}]},{"@type":"WebSite","@id":"https:\/\/vectalk.com.br\/blog\/#website","url":"https:\/\/vectalk.com.br\/blog\/","name":"Blog Vectalk","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vectalk.com.br\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b","name":"wanderleyfcunha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","caption":"wanderleyfcunha"},"sameAs":["https:\/\/vectalk.com.br\/blog"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/comments?post=2177"}],"version-history":[{"count":1,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2177\/revisions"}],"predecessor-version":[{"id":2180,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2177\/revisions\/2180"}],"wp:attachment":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/media?parent=2177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/categories?post=2177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/tags?post=2177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}