1msg official logo

WhatsApp Business API for new lead manager notification

The scenario sends the sales manager a personalised WhatsApp template when a new lead is captured.

Use case overview

The scenario sends the sales manager a personalised WhatsApp template when a new lead is captured. The message includes the lead name, contact details, and source label. A static URL button opens the lead record in CRM.

Template example

🔔 New lead: {{1}}

Contact: {{2}}

Source: {{3}}

Contact the client as soon as possible while interest is high.

[Open in CRM]

The CRM URL button is fixed in the Meta template — only body variables are sent via the API.

Variables and purpose

  • {{1}} — lead name or short label (e.g. Alexey K., B2B request)
  • {{2}} — lead contact (phone, email, or combined contact line)
  • {{3}} — lead source (e.g. website form, Instagram ad, partner referral)

Filled-in example

🔔 New lead: Alexey K.

Contact: +998901234567

Source: website form

Contact the client as soon as possible while interest is high.

[Open in CRM]

When to use it

  • inside sales
  • agencies
  • small teams

Business value

  • CRM or form integration captures a new lead event
  • System resolves the manager phone and lead summary fields
  • Internal notification template is built with name, contact, and source
  • WhatsApp message is delivered to the sales manager
  • Manager can open CRM immediately and contact the lead while interest is high

Workflow

  1. CRM or the lead capture integration emits a new-lead event.
  2. The system resolves the manager phone number and lead summary fields.
  3. An internal notification template is built with three body variables and a static URL button.
  4. The manager receives the WhatsApp alert on their phone.
  5. Delivery result is logged; the manager opens CRM via the button to follow up.
  6. Delivery progress is reported asynchronously — typically sent, then delivered (or failed/undelivered).
  7. Your system receives status via webhook (hooks[]) or polls GET …/hookInfo?messageId=<id> and handles failures if needed.

Technical implementation

Prerequisites

  • A 1MSG account with WhatsApp Business API connected and an approved message template.
  • Manager phone number in international format (without + and spaces) — MANAGER_PHONE in generated code.
  • New-lead payload: lead name, contact, source; CRM URL fixed in the Meta template button.

Code examples

Node.js

#!/usr/bin/env node

// === Configuration (replace "___" placeholders) ===

const API_BASE_URL = "https://api.1msg.io"; // production 1MSG API base URL
const CHANNEL_ID = "___";                   // channel ID from 1MSG dashboard
const API_TOKEN = "___";                    // channel JWT token (Bearer)

const TEMPLATE_NAME = "___";                // approved template name
const TEMPLATE_NAMESPACE = "___";           // template namespace (422 without it)
const TEMPLATE_LANGUAGE = "___";            // template language code, e.g. "en"



// === Test data ===
const MANAGER_PHONE = "___";            // manager phone in international format
const TEST_LEADNAME = "___";    // {{1}} lead name
const TEST_LEADCONTACT = "___";    // {{2}} lead contact
const TEST_LEADSOURCE = "___";    // {{3}} lead source

function normalizePhone(phone) {
  return String(phone).replace(/\D/g, "");
}

function assertConfigured(values) {
  for (const [key, value] of Object.entries(values)) {
    if (value === "___" || value === "" || value === undefined || value === null) {
      throw new Error(`Missing configuration value: ${key}`);
    }
  }
}

async function sendTemplateMessage({ phone, leadName, leadContact, leadSource }) {
  assertConfigured({
    CHANNEL_ID,
    API_TOKEN,
    TEMPLATE_NAME,
    TEMPLATE_NAMESPACE,
    TEMPLATE_LANGUAGE,
    phone,
    leadName,
    leadContact,
    leadSource,
  });

  const url = `${API_BASE_URL}/${CHANNEL_ID}/sendTemplate`;

  // params carries body ONLY. Button text is fixed in the Meta template — no button param.
  const requestBody = {
    phone: normalizePhone(phone),
    template: TEMPLATE_NAME,
    namespace: TEMPLATE_NAMESPACE,
    language: {
      policy: "deterministic",
      code: TEMPLATE_LANGUAGE,
    },
    params: [
      {
        type: "body",
        parameters: [
          { type: "text", text: String(leadName) }, // {{1}} lead name
          { type: "text", text: String(leadContact) }, // {{2}} lead contact
          { type: "text", text: String(leadSource) }, // {{3}} lead source
        ],
      },
    ],
  };

  const res = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_TOKEN}`,
    },
    body: JSON.stringify(requestBody),
  });

  const raw = await res.text();
  let data;
  try {
    data = JSON.parse(raw);
  } catch {
    data = null;
  }

  if (!res.ok || !data || data.sent !== true) {
    console.error("Send failed. API response:");
    console.error(raw);
    process.exit(1);
  }

  console.log("Message sent to manager.");
  console.log("API response:", raw);
  return data;
}

if (require.main === module) {
  sendTemplateMessage({
    phone: MANAGER_PHONE,
    leadName: TEST_LEADNAME,
    leadContact: TEST_LEADCONTACT,
    leadSource: TEST_LEADSOURCE,
  }).catch((err) => {
    console.error("Execution failed:", err.message);
    process.exit(1);
  });
}

module.exports = { sendTemplateMessage };

Immediate API response (synchronous)

  • HTTP 2xx and JSON "sent": true mean 1MSG accepted the message for sending — not that it already reached the customer's phone.
  • Save the `id` field from the response (value looks like wamid.…). Use it to correlate delivery callbacks or polling.
  • The response may also include message and description — informational only.

Delivery status (asynchronous)

  • Register a webhook (POST …/webhook) so 1MSG POSTs delivery updates to your HTTPS endpoint in a separate `hooks[]` payload (sent, delivered, read, or failed/undelivered when applicable).
  • Optionally poll: GET {base}/{channel}/hookInfo?messageId=<id from sendTemplate>.
  • In practice, delivery often completes within a few seconds — but that is not guaranteed by the API contract.

Common errors

  • Invalid or non-normalized phone number
  • Unapproved or missing template name / namespace
  • No customer opt-in for WhatsApp business messages
  • Template variable count mismatch (422 from API)
  • Delivery failure — check status webhook and retry policy

FAQ

  • Do I need an approved template? Yes — cold-start WhatsApp messages require a Meta-approved template.
  • Can I customize the message text? Body variables are dynamic; fixed text and button labels are set in the Meta template.
  • How do I check delivery? sent: true only confirms acceptance. Track delivery via webhook hooks[] or GET …/hookInfo?messageId=<id>.
  • What if the message is not delivered? Log the failed/undelivered hook, verify opt-in and template status, then retry or fall back to another channel.
  • Can I connect this to my CRM or backend? Yes — trigger the API call from your platform webhook or event handler.

CTA

Ready to use new lead manager notification? Connect your 1MSG channel and run the code examples above.

Related

Build WhatsApp automation in minutes

Use 1MSG to automate this workflow and try it with our free demo.

Try the demo →