Skip to Content
Wapitick developers

Capture a lead into the inbox

Save leads from your own forms, tag them, and have the chat waiting in the Wapitick inbox.

POST /v1/contacts:upsert with a tag (website-lead) and source. The business sees the lead in Customers; the moment the person writes on WhatsApp the chat opens in the inbox with that history. Do not message a lead first unless they agreed to it: record consent with POST /v1/contacts/{id}/consents, or use a Wapitick lead form, which records the exact wording they agreed to.

cURL

curl.sh
#!/usr/bin/env bash
# Capture a lead into the inbox: contacts_upsert, test_inbound_create, conversations_list (runs in test mode)
set -euo pipefail
API="${WAPITICK_API_URL:-https://api.wapitick.com}"
AUTH="Authorization: Bearer $WAPITICK_API_KEY"

# From your own form: save the lead with a tag
curl -sf "$API/v1/contacts:upsert" -H "$AUTH" -H "Content-Type: application/json" -H "Idempotency-Key: lead-$(date +%s)" \
  -d '{"match":{"kind":"phone","value":"+15550100007"},"create_if_missing":true,"data":{"name":"Ravi","phones":["+15550100007"],"tags":["website-lead"],"source":"lead"}}' | jq '{id: .contact.id, created}'
# In test mode, simulate the lead messaging you; the chat opens in the inbox
curl -sf "$API/v1/test/inbound" -H "$AUTH" -H "Content-Type: application/json" -H "Idempotency-Key: lead-in-$(date +%s)" \
  -d '{"from":"+15550100007","text":"I filled your form, please call me","name":"Ravi"}' >/dev/null
sleep 3
curl -sf "$API/v1/conversations?limit=3" -H "$AUTH" | jq '[.data[] | {id, status}]'

Node

node.mjs
// biome-ignore-all lint/suspicious/noConsole: a docs sample prints its result
// Capture a lead into the inbox: contacts_upsert, test_inbound_create, conversations_list
import { Wapitick } from "@wapitick/node";

const wapitick = new Wapitick({
  apiKey: process.env.WAPITICK_API_KEY,
  baseUrl: process.env.WAPITICK_API_URL,
});
const lead = await wapitick.contacts.upsert({ phone: "+15550100007", name: "Ravi", tags: ["website-lead"] });
if (wapitick.testMode)
  await wapitick.test.inbound({
    from: "+15550100007",
    text: "I filled your form, please call me",
    name: "Ravi",
  });
await new Promise((r) => setTimeout(r, 3000));
const chats = await wapitick.conversations.list({ limit: 3 });
console.log(JSON.stringify({ lead: lead.contact.id, conversations: chats.data.length }));

Python

python.py
# Capture a lead into the inbox: contacts_upsert, test_inbound_create, conversations_list
import json
import os
import time

from wapitick import Wapitick

w = Wapitick(api_key=os.environ["WAPITICK_API_KEY"], base_url=os.environ.get("WAPITICK_API_URL", "https://api.wapitick.com"))
lead = w.contacts.upsert("+15550100007", name="Ravi", tags=["website-lead"])
if w.test_mode:
    w.test.inbound("+15550100007", "I filled your form, please call me", name="Ravi")
time.sleep(3)
chats = w.call("conversations_list", query={"limit": 3})
print(json.dumps({"lead": lead["contact"]["id"], "conversations": len(chats["data"])}))

PHP

php.php
<?php
// Capture a lead into the inbox: contacts_upsert, test_inbound_create, conversations_list
require __DIR__ . '/vendor/autoload.php';

$w = new Wapitick\Client(getenv('WAPITICK_API_KEY'), getenv('WAPITICK_API_URL') ?: 'https://api.wapitick.com');
$lead = $w->upsertContact('+15550100007', 'Ravi', null, ['website-lead']);
if ($w->isTestMode()) {
    $w->simulateInbound('+15550100007', 'I filled your form, please call me');
}
sleep(3);
$chats = $w->call('conversations_list', [], ['limit' => 3]);
echo json_encode(['lead' => $lead['contact']['id'], 'conversations' => count($chats['data'])]), "\n";

Google Apps Script

apps-script.gs
// biome-ignore-all lint/correctness/noUnusedVariables: Apps Script runs these functions by name
// Google Forms -> Wapitick lead: install as an onFormSubmit trigger. contacts_upsert.
// Script properties: WAPITICK_API_KEY (wk_test_...), optional WAPITICK_API_URL.
function wapitick_(method, path, body) {
  const props = PropertiesService.getScriptProperties();
  const base = props.getProperty("WAPITICK_API_URL") || "https://api.wapitick.com";
  const res = UrlFetchApp.fetch(base + path, {
    method: method,
    contentType: "application/json",
    headers: {
      Authorization: `Bearer ${props.getProperty("WAPITICK_API_KEY")}`,
      "Idempotency-Key": Utilities.getUuid(),
    },
    payload: body ? JSON.stringify(body) : undefined,
    muteHttpExceptions: true,
  });
  const json = JSON.parse(res.getContentText() || "null");
  if (res.getResponseCode() >= 300) throw new Error(`${json.code}: ${json.detail}`);
  return json;
}

function onFormSubmit(e) {
  const r = e.namedValues; // form questions "Name" and "WhatsApp number"
  const phone = String(r["WhatsApp number"][0]).replace(/[^0-9+]/g, "");
  wapitick_("post", "/v1/contacts:upsert", {
    match: { kind: "phone", value: phone },
    create_if_missing: true,
    data: { name: r.Name[0], phones: [phone], tags: ["google-form-lead"], source: "lead" },
  });
}

Operations: contacts_upsert, test_inbound_create (test mode only), conversations_list.

This page as Markdown