| 1 | @client.on(events.INCOMING_CALL) |
| 2 | async def interactive_notification(call: ActiveCall): |
| 3 | await call.answer() |
| 4 | |
| 5 | customer = await db.get_customer_by_phone(call.caller_number) |
| 6 | pending_notifications = await db.get_pending_notifications(customer.id) |
| 7 | |
| 8 | for notification in pending_notifications: |
| 9 | await call.send_audio( |
| 10 | await tts.synthesize(notification.message) |
| 11 | ) |
| 12 | |
| 13 | # AI listens for confirmation/response |
| 14 | response = await ai_model.get_caller_response(call) |
| 15 | |
| 16 | if response.confirmed: |
| 17 | await db.mark_notification_acknowledged(notification.id) |
| 18 | await call.send_audio( |
| 19 | await tts.synthesize("Got it, that's been confirmed.") |
| 20 | ) |
| 21 | else: |
| 22 | await db.flag_for_followup(notification.id) |
| 23 | await call.send_audio( |
| 24 | await tts.synthesize( |
| 25 | "No problem, someone from our team will follow up." |
| 26 | ) |
| 27 | ) |
| 28 | |
| 29 | await call.send_audio( |
| 30 | await tts.synthesize("That's everything. Have a great day!") |
| 31 | ) |
| 32 | await call.disconnect() |