AI Receptionist with Database Lookup

View as Markdown

An AI agent answers the call, looks up the caller in your database, and provides personalized service before routing to the right department.

Overview

This use case demonstrates:

  • Database lookup by caller number on call arrival
  • Creating new leads for unknown callers
  • Intent classification to determine routing
  • Seamless handoff via connect() and close()

State flow: PENDING -> ANSWERED -> CONNECTED -> DISCONNECTED

Example

1import asyncio
2from telcoflow_sdk import TelcoflowClient, TelcoflowClientConfig, ActiveCall
3import telcoflow_sdk.events as events
4
5@client.on(events.INCOMING_CALL)
6async def ai_receptionist(call: ActiveCall):
7 await call.answer()
8
9 # Look up caller in your CRM / database
10 customer = await db.get_customer_by_phone(call.caller_number)
11
12 if customer:
13 # Personalized greeting
14 greeting = f"Hello {customer.name}, welcome back."
15 await call.send_audio(await tts.synthesize(greeting))
16
17 # Check for open tickets, pending orders, etc.
18 open_tickets = await db.get_open_tickets(customer.id)
19 if open_tickets:
20 msg = f"I see you have {len(open_tickets)} open support tickets."
21 await call.send_audio(await tts.synthesize(msg))
22 else:
23 # Log new caller to database
24 await db.create_lead(phone=call.caller_number, source="inbound_call")
25 await call.send_audio(await tts.synthesize("Welcome! How can I help you?"))
26
27 # AI listens, determines intent, and decides next action
28 should_connect = await ai_model.classify_intent(call)
29
30 if should_connect:
31 await call.send_audio(
32 await tts.synthesize("Let me connect you now.")
33 )
34 # Connect to the original callee and leave the call
35 await call.connect()
36 await call.close()
37 else:
38 # Continue the AI conversation
39 async for chunk in call.audio_stream():
40 response = await ai_model.generate(chunk)
41 await call.send_audio(response)

How It Works

  1. The call arrives and the AI agent answers immediately
  2. The agent uses call.caller_number to look up the caller in a CRM or database
  3. If found, the agent delivers a personalized greeting and surfaces relevant account info (open tickets, pending orders, etc.)
  4. If not found, the agent creates a new lead record in the database
  5. The AI listens to the caller and classifies their intent
  6. If the caller needs to speak to a human, the AI connects them to the original callee using connect() and then leaves the call with close()
  7. If the intent doesn’t require a human, the AI continues the conversation directly

Key Commands Used

  • answer() - Answer the incoming call
  • send_audio() - Play synthesized speech to the caller
  • connect() - Connect to the original callee
  • close() - Leave the call after connecting the caller to the callee