Quickstart

This guide takes a new account to an agent talking with a live person. It uses fictional data and 555-01xx numbers. With a test key every step works the same and no calls are placed.

Get your API keys

Your test and live keys are in the dashboard once your account is set up. Request API access if you do not have an account yet. Export the key in your shell or your server's environment as LIVELEG_API_KEY. Details are in Authentication.

Load leads

Create a lead list, then add leads. Each lead needs a phone number and a state. The state sets the lead's calling hours. Up to 500 leads per request.

curl
curl https://api.liveleg.dev/v1/lead_lists \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -d id=lst_roofing_tx \
  -d name="Roofing, Texas"
POST/v1/lead_lists/lst_roofing_tx/leads
curl https://api.liveleg.dev/v1/lead_lists/lst_roofing_tx/leads \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "leads": [
      {
        "phone": "+15125550147",
        "state": "TX",
        "name": "Dana Ruiz",
        "company": "Ridgeline Roofing",
        "external_id": "crm_88213"
      },
      {
        "phone": "+15125550163",
        "state": "TX",
        "name": "Luis Ortega",
        "external_id": "crm_88219"
      }
    ]
  }'

Buy local numbers

Buy numbers in the area codes you call and put them in a caller ID pool. Each call picks a number from the pool by the lead's area code and state.

POST/v1/numbers
curl https://api.liveleg.dev/v1/numbers \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -d area_code=512 \
  -d quantity=3 \
  -d pool_id=pool_local_presence

Add a webhook endpoint

Tell us where to send events. Store the secret from the response to verify deliveries.

POST/v1/webhook_endpoints
curl https://api.liveleg.dev/v1/webhook_endpoints \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://app.example.com/hooks/liveleg",
    "events": [
      "call.bridged",
      "call.completed",
      "call.blocked",
      "recording.ready"
    ]
  }'

Connect the agent

Your server mints a token for the agent. The page passes it to the Voice SDK, which opens the agent's line for the whole session.

POST/v1/agents/agt_114/tokens
curl https://api.liveleg.dev/v1/agents/agt_114/tokens \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -d ttl_seconds=3600
Browser
import { Agent } from '@liveleg/voice';

const { token } = await fetch('/api/liveleg-token').then((r) => r.json());
const agent = await Agent.connect(token);
agent.on('call.bridged', (call) => showLead(call.leadId));

Start dialing

One request starts parallel dialing for the agent. The first person to answer is connected, and the agent hears them about 1 second after they finish saying hello.

POST/v1/dial_sessions
curl https://api.liveleg.dev/v1/dial_sessions \
  -H "Authorization: Bearer $LIVELEG_API_KEY" \
  -H "Idempotency-Key: agent-114-morning" \
  -d agent_id=agt_114 \
  -d lead_list_id=lst_roofing_tx \
  -d lines=auto \
  -d caller_id_pool=pool_local_presence \
  -d amd=true \
  -d recording=smart

Handle events

Verify the signature, store the event by webhook-id and return 2xx quickly. Do the slow work after you respond.

Node.js
import { Webhook } from 'standardwebhooks';

const wh = new Webhook(process.env.LIVELEG_WEBHOOK_SECRET);

app.post('/hooks/liveleg', express.raw({ type: 'application/json' }), (req, res) => {
  const event = wh.verify(req.body, req.headers); // throws if the signature is wrong
  queue.add(event.type, event, { jobId: req.headers['webhook-id'] });
  res.sendStatus(204);
});

Next steps