| 1 | import asyncio |
| 2 | from agentao_sdk import AgenTaoClient, AgenTaoClientConfig, ActiveCall |
| 3 | import agentao_sdk.events as events |
| 4 | |
| 5 | @client.on(events.INCOMING_CALL) |
| 6 | async 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) |