Your phone rings. A potential customer wants a quote for a kitchen remodel: $15,000 job. Your AI receptionist answers, asks the right questions, captures their name, email, project details, and budget. Then what?
If you're manually logging this information into your CRM hours later (or worse, days later), you're losing leads. For contractors and other service businesses, automated CRM integration means customer information flows into the system within seconds of the call ending, not when someone "gets around to it," so fewer leads go cold while they wait to be entered by hand.
This guide shows you exactly how to connect your AI receptionist to any platform using webhooks, with complete code examples, platform-specific integrations for Salesforce and custom APIs (HubSpot connects to NextPhone directly), and clear guidance on when custom webhooks are worth it versus using Zapier.
When Custom Integrations Make Sense
Before you write a single line of code, let's answer the real question: Do you even need custom webhooks?
Most businesses start with no-code tools like Zapier or Make. That's perfectly fine, and often the right choice. NextPhone's own Zapier app, "NextPhone AI," connects it to 8,000+ apps, sets up in 15 minutes, and handles straightforward workflows like "new call → create CRM contact."
But custom webhooks are worth the extra effort when you have:
The Integration Decision Framework

Choose Zapier/Make when:
- You're connecting to popular platforms (Salesforce, Slack, Google Sheets)
- Your workflow is straightforward (1-3 steps)
- You don't have technical resources
- Call volume is moderate (under 1,000/month)
Choose custom webhooks when:
- You have proprietary or custom-built systems
- You need complex data transformation before storing
- You're in a regulated industry requiring SOC 2 compliance
- Call volume is high (Zapier charges per task, webhooks are unlimited)
- You want the raw call payload in your own code
When Zapier Is Better (Be Honest)
If you're a solo contractor using standard tools, Zapier is faster. A plumber with Google Calendar and Gmail doesn't need custom webhooks. Zapier connects both in minutes without code.
Research shows SMBs use an average of 253 SaaS applications, and 2.2M+ businesses use Zapier with access to 8,000+ integrations. Most of those apps already have Zapier integrations. Use what works.
When Custom Webhooks Are Worth It
Custom webhooks shine for specialized scenarios:
Proprietary Systems: A general contractor built custom dispatch software in 2015. No Zapier integration exists. They need incoming leads to flow directly into their proprietary database with specific field mappings. Custom webhook solution: 3 hours of development, unlimited calls on the $299/month Growth plan.
Complex Workflows: A law firm needs caller information to: (1) Check if caller is existing client in proprietary case management system, (2) Assign the appropriate attorney based on practice area mentioned in call, (3) Create intake form with custom questions, (4) Trigger conflict check. This multi-step, conditional logic requires custom code.
Cost at Scale: Zapier charges per task. At $29.99/month, you get 750 tasks. If you're processing 2,000 calls/month with 2 actions per call (create contact + send notification), that's 4,000 tasks = $99/month in Zapier fees alone. Custom webhooks are unlimited on the $299/month Growth plan.
Team Notifications: For businesses using Slack (which has 2,400+ app integrations and helps reduce emails by 32%), webhook notifications post an alert to the right channel right after each call.
In our data, approximately one in four callers explicitly asks for a callback. If your business processes 100 calls/month, that's roughly 25 callback requests you can't afford to lose. Whether you use Zapier or custom webhooks, automating this flow is critical.
Understanding Webhooks (The Basics)
If you're new to webhooks, here's what you need to know.
What Are Webhooks?
A webhook is an automated HTTP callback that fires when a specific event occurs. Instead of your application constantly checking "did anything happen yet?" (polling), the sending system notifies you the instant something happens (push).
Think of it like this: APIs are like checking your mailbox every hour to see if mail arrived. Webhooks are like getting a notification on your phone the moment mail is delivered.
Webhooks vs APIs: Push vs Pull
Traditional API (Pull): Your system: "Any new leads?" CRM: "No." (5 minutes pass) Your system: "Any new leads?" CRM: "No." (5 minutes pass) Your system: "Any new leads?" CRM: "Yes, here's one from 7 minutes ago."
Webhook (Push): (New lead arrives) CRM → instantly sends data to your system
The difference? Webhooks deliver data in real-time with zero wasted requests. According to Enterprise Integration Patterns, webhook-based integrations can reduce latency by up to 95% compared to polling-based approaches.
Why Webhooks Matter for Real-Time Communication
When a customer calls your AI receptionist asking about emergency HVAC repair at 9 PM, you don't want that lead sitting in a queue for 5 minutes until your next API poll. You want it in your CRM immediately, notification sent to your on-call technician within seconds.
Webhooks make this possible. The AI answers the call, determines it's an emergency (urgent calls using language like "emergency," "urgent," or "ASAP" rank among the top reasons people call, according to our data), collects caller details, and sends them to your system seconds after the call ends. For the caller who needs a person right now, the AI transfers the call live.
That's the power of event-driven architecture, and why 73% of developers prefer REST APIs with webhook callbacks for modern integrations, according to the Stack Overflow Developer Survey 2024.
How NextPhone Webhooks Work
Now let's get specific about NextPhone's webhook implementation.
The AI Data Collection Process

Here's what happens during a call:
- Caller contacts your business via your NextPhone number
- AI answers on the first ring and starts the conversation
- AI asks custom questions you've configured: "Can I get your name?" "What service are you interested in?" "What's your email address?" "When would you like us to call you back?"
- AI collects structured data from the caller's responses (name, email, company, project details, budget, timeline: whatever you've defined)
- NextPhone sends the webhook after the call ends, with the summary and the answers it collected
The key difference from generic webhook systems: NextPhone's AI understands context. If you ask for an email and the caller says "john at example dot com," the AI correctly formats it as john@example.com. If you ask for a phone number and they say "five five five twelve thirty-four," it's stored as 555-1234.
When Webhooks Fire
NextPhone's Custom Webhook fires once per call, after the call ends. You choose which call outcomes fire it (all calls, or only new leads, bookings, transfers, messages taken, and so on). Typical uses:
- Send full conversation summary to CRM
- Create support ticket with caller details
- Log callback request with timestamp
During the call, the AI handles the live actions itself: it transfers urgent callers, books appointments on your connected calendar, and texts links.
Fail-safe design: the webhook runs after the caller has hung up, so whatever happens at your endpoint, the call experience is never interrupted. Every call also stays in your NextPhone dashboard with its recording, transcript and summary.
HTTP Configuration Options
Setting up the Custom Webhook takes four fields:
- URL: Your HTTPS endpoint. NextPhone sends a POST with a JSON body.
- Secret (optional): Sent with every request as the
X-NextPhone-Secretheader, so your receiver can reject anything else. - Which calls: The call outcomes that fire the webhook.
- Send test: Posts a sample payload built from your own intake questions, so you can check your receiver before a real call.
According to Postman's State of APIs 2024 report, 86% of developers report that API quality directly impacts product success. NextPhone keeps the payload fixed and predictable, so your receiver code stays simple.
The Payload: What NextPhone Sends
This is where webhooks get powerful.
Standard Call Fields
Every webhook carries the same set of call fields:
caller_name- The caller's name, if they gave itcaller_number- The caller's phone number (e.g.,+15551234567)receiving_number- The business number they calledsummary- AI-generated summary of the calltranscript- The full conversationrecording_url- Link to the call recordingstarted_at/ended_at- Call times (ISO 8601)call_duration- Length of the call in secondsoutcome- What happened:NEW_LEAD,BOOKED,TRANSFERRED,MESSAGE_CAPTURED,ANSWEREDand so on
These fields are automatically populated for every call.
Intake Answers from AI Conversations
This is the real magic: every intake question you set up comes back as its own field.
Example conversation: AI: "Thanks for calling ABC Plumbing. Can I get your name?" Caller: "Yeah, it's Mike Johnson." AI: "Great, Mike. What can I help you with today?" Caller: "I have a leaky pipe in my kitchen." AI: "Got it. Can I get your email so we can send you a quote?" Caller: "Sure, mjohnson@email.com." AI: "Perfect. And what's your address?" Caller: "123 Main Street."
Resulting intake answers (with intake questions labeled "Email", "Issue" and "Address"):
{
"email": "mjohnson@email.com",
"issue": "leaky pipe in kitchen",
"address": "123 Main Street"
}
Each answer arrives as a top-level field named after its question in lower snake case ("Project type" becomes project_type). The same answers also arrive together in structured_data, as a JSON string keyed by the question labels. Unanswered questions are left out.
Putting It Together: Example Payload
What your endpoint receives after Mike's call:
{
"outcome": "NEW_LEAD",
"summary": "Mike Johnson has a leaky pipe in his kitchen and wants a quote. Email and address collected.",
"started_at": "2026-03-02T21:04:11.000Z",
"ended_at": "2026-03-02T21:06:36.000Z",
"call_duration": "145",
"transcript": "AI: Thanks for calling ABC Plumbing. Can I get your name?\nCaller: Yeah, it's Mike Johnson...",
"caller_name": "Mike Johnson",
"caller_number": "+15559876543",
"receiving_number": "+15551234567",
"recording_url": "https://www.getnextphone.com/r/abc123",
"structured_data": "{\"Email\":\"mjohnson@email.com\",\"Issue\":\"leaky pipe in kitchen\",\"Address\":\"123 Main Street\"}",
"email": "mjohnson@email.com",
"issue": "leaky pipe in kitchen",
"address": "123 Main Street"
}
The core call fields are the same on every call, so you write your receiver once. Your receiver (or a Zapier or Make step) maps these fields to whatever format your system expects.
Remember: approximately one in four callers explicitly asks for a callback, according to our data. With the summary and intake answers in every payload, you can automatically log these callback requests with full caller context (name, number, reason for call, preferred callback time), so you never lose track.
Complete Code Examples: Building Webhook Receivers
Now let's build the receiving end. These are complete, working examples you can deploy.
NextPhone Webhook Configuration
First, connect the webhook in NextPhone:
- Open Agent > Actions and add Custom Webhook
- Paste your endpoint URL, for example
yourdomain.com/api/nextphone - Add a secret (optional, recommended). NextPhone sends it as the
X-NextPhone-Secretheader - Choose which call outcomes fire the webhook
- Click Send test and check that your receiver logs the sample payload
From then on, NextPhone POSTs the JSON payload shown above to your endpoint after every matching call.
JavaScript/Node.js Receiver (Express.js)
Here's a complete Express.js server that receives NextPhone webhooks:
const express = require('express');
const crypto = require('crypto');
const app = express();
// Middleware to parse JSON bodies
app.use(express.json());
// The secret you entered in NextPhone (sent as X-NextPhone-Secret)
const WEBHOOK_SECRET = process.env.NEXTPHONE_WEBHOOK_SECRET;
// Constant-time compare of the shared secret (security best practice)
function verifySecret(received) {
if (!WEBHOOK_SECRET || typeof received !== 'string') return false;
const a = Buffer.from(received);
const b = Buffer.from(WEBHOOK_SECRET);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Webhook endpoint
app.post('/api/webhooks/nextphone', async (req, res) => {
try {
// 1. Verify the shared secret
if (!verifySecret(req.headers['x-nextphone-secret'])) {
console.error('Invalid webhook secret');
return res.status(403).json({ error: 'Invalid secret' });
}
// 2. Build a lead from the NextPhone payload
const call = req.body;
const leadData = {
name: call.caller_name,
phone: call.caller_number,
email: call.email, // intake answer for a question labeled "Email"
notes: call.summary,
recording: call.recording_url,
outcome: call.outcome,
calledAt: call.started_at,
};
console.log('Received lead:', leadData);
// 3. Validate required fields
if (!leadData.phone) {
return res.status(400).json({ error: 'Phone number required' });
}
// 4. Process the lead (save to database, send to CRM, etc.)
await saveLeadToCRM(leadData);
// 5. Send success response
res.status(200).json({
success: true,
message: 'Lead processed successfully'
});
} catch (error) {
console.error('Webhook processing error:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Example CRM save function
async function saveLeadToCRM(leadData) {
// Your CRM integration logic here
// Could be: Database insert, API call to Salesforce, etc.
console.log('Saving lead to CRM:', leadData);
// Example: Insert into PostgreSQL
// await db.query(
// 'INSERT INTO leads (name, phone, email, notes) VALUES ($1, $2, $3, $4)',
// [leadData.name, leadData.phone, leadData.email, leadData.notes]
// );
}
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Webhook receiver listening on port ${PORT}`);
});
Key points:
- Always return 200 OK for successful processing, and respond fast
- Check the
X-NextPhone-Secretheader to ensure webhooks are from NextPhone (security) - Handle errors gracefully (log, alert, but don't crash)
- Process asynchronously if possible (don't block the webhook response)
Python Receiver (Flask)
Same functionality in Python with Flask:
from flask import Flask, request, jsonify
import hmac
import os
app = Flask(__name__)
# The secret you entered in NextPhone (sent as X-NextPhone-Secret)
WEBHOOK_SECRET = os.environ.get('NEXTPHONE_WEBHOOK_SECRET', '')
def verify_secret(received):
"""Constant-time compare of the shared secret"""
return bool(WEBHOOK_SECRET) and hmac.compare_digest(received or '', WEBHOOK_SECRET)
@app.route('/api/webhooks/nextphone', methods=['POST'])
def nextphone_webhook():
try:
# 1. Verify the shared secret
if not verify_secret(request.headers.get('X-NextPhone-Secret')):
return jsonify({'error': 'Invalid secret'}), 403
# 2. Build a lead from the NextPhone payload
call = request.json
lead_data = {
'name': call.get('caller_name'),
'phone': call.get('caller_number'),
'email': call.get('email'), # intake answer for a question labeled "Email"
'notes': call.get('summary'),
'recording': call.get('recording_url'),
'outcome': call.get('outcome'),
}
print(f'Received lead: {lead_data}')
# 3. Validate required fields
if not lead_data.get('phone'):
return jsonify({'error': 'Phone number required'}), 400
# 4. Process the lead
save_lead_to_crm(lead_data)
# 5. Return success
return jsonify({
'success': True,
'message': 'Lead processed successfully'
}), 200
except Exception as e:
print(f'Webhook processing error: {e}')
return jsonify({'error': 'Internal server error'}), 500
def save_lead_to_crm(lead_data):
"""Save lead to your CRM or database"""
print(f'Saving lead to CRM: {lead_data}')
# Your integration logic here
# Example: Insert into database, call CRM API, etc.
pass
if __name__ == '__main__':
app.run(port=3000, debug=False)
Error Handling and Validation
Both examples include critical error handling:
Secret Verification: Prevents malicious requests pretending to be from NextPhone Input Validation: Ensures required fields are present before processing Try/Catch Blocks: Gracefully handle unexpected errors Proper HTTP Status Codes: 200 = success, 4xx = bad request, 5xx = your server failed (log it and alert yourself)
These patterns align with OWASP API Security best practices, which identify broken authentication as the #1 API vulnerability.
