@layouts.dash.app({ title: 'WEBHOOK' })
Webhook
A webhook is a mechanism that allows one application (source) to automatically send data to another application (recipient) immediately after a message upsert event.
# n8n
# Example Webhook NodeJS
Endpoint: http://localhost:3335/webhook
const express = require("express");
const app = express();
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));

const port = 3335;

async function sendMessage(data) {
  const url = "{{ `${request.protocol()}://${request.host()}/api/message` }}";

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  });
  console.log(await response.json());
}

app.post("/webhook", function (req, res) {
  const body = req.body;
  if (body.msg.text == "ping") {
    sendMessage({
        token: body.token,
        to: body.chat,
        message: "pong",
    });
  }
  res.end();
});

app.listen(port, function (err) {
  if (err) console.log(err);
  console.log("Server listening on PORT", port);
});
# Example data from Webhook
{
  key: {
    remoteJid: '120363351184073195@g.us',
    fromMe: false,
    id: '3FFBF7252669239DC49E',
    senderLid: undefined,
    senderPn: undefined,
    participant: '210900309037136@lid',
    participantPn: '6285174902345@s.whatsapp.net',
    participantLid: undefined
  },
  chat: '120363351184073195@g.us',
  fromMe: false,
  pushName: 'Ilsya',
  senderLid: '210900309037136@lid',
  senderPn: '6285174902345@s.whatsapp.net',
  botLid: '10123909054630@lid',
  botPn: '6281513922227@s.whatsapp.net',
  token: 'TOKEN_FOR_API',
  isGroup: true,
  isSenderBot: false,
  isSenderSuperAdmin: false,
  isSenderAdmin: true,
  isBotSuperAdmin: false,
  isBotAdmin: true,
  groupMetadata: {
    id: '120363351184073195@g.us',
    addressingMode: 'lid',
    subject: 'Developer Test',
    subjectOwner: '210900309037136@lid',
    subjectOwnerJid: '6285174902345@s.whatsapp.net',
    subjectTime: 1759655643,
    size: 4,
    creation: 1729959196,
    owner: '210900309037136@lid',
    ownerJid: '6285174902345@s.whatsapp.net',
    owner_country_code: 'ID',
    desc: '',
    descId: 'da1852ce-aad5-4bf1-b800-ff391093b13f',
    descOwner: '210900309037136@lid',
    descOwnerJid: '6285174902345@s.whatsapp.net',
    descTime: 1759056746,
    linkedParent: undefined,
    restrict: false,
    announce: false,
    isCommunity: false,
    isCommunityAnnounce: false,
    joinApprovalMode: false,
    memberAddMode: false,
    participants: [ [Object], [Object], [Object], [Object] ],
    ephemeralDuration: 86400
  },
  mtype: 'extendedTextMessage',
  msg: {
    text: 'test',
    textWithoutCommand: '',
    command: 'test',
    mentionedJid: [],
    expiration: 86400,
    isText: true,
    isSticker: false,
    isImage: false,
    isVideo: false,
    isAudio: false,
    isDocument: false,
    isMedia: false
  },
  quoted: [QuotedMessage],
}
@end @pushTo('head') @end @pushTo('body') @end