how to use phone buttons in sip to raise events in...
# ask-ai
b
how to use phone buttons in sip to raise events in agent
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To use phone buttons in SIP to raise events in an agent, you can handle DTMF (Dual-Tone Multi-Frequency) tones as follows: 1. Set up DTMF event handlers: Use the
setup_dtmf_handlers
function to register handlers for DTMF events in the room. 2. Register a handler for the "sip_dtmf_received" event: This event is triggered when a DTMF tone is received. For example:
Copy code
@room.on("sip_dtmf_received")
def handle_dtmf(dtmf_event: rtc.SipDTMF):
    asyncio.create_task(_async_handle_dtmf(dtmf_event))
3. Process DTMF events: In the handler, you can access the DTMF code, digit, and participant identity to perform actions such as interrupting the agent or transferring calls. For example:
Copy code
async def _async_handle_dtmf(dtmf_event: rtc.SipDTMF):
    await phone_assistant.session.interrupt()
    <http://logger.info|logger.info>("Interrupted agent due to DTMF")

    code = dtmf_event.code
    digit = dtmf_event.digit
    identity = dtmf_event.participant.identity

    # Map digits to departments and handle transfers
    department_numbers = {
        "1": ("BILLING_PHONE_NUMBER", "Billing"),
        "2": ("TECH_SUPPORT_PHONE_NUMBER", "Tech Support"),
        "3": ("CUSTOMER_SERVICE_PHONE_NUMBER", "Customer Service")
    }

    if digit in department_numbers:
        # Handle transfer logic
    else:
        # Handle invalid input
This setup allows callers to press buttons on their phone keypad to interact with the agent, such as selecting departments for call transfers. Sources: Company directory phone assistant | LiveKit Docs | livekit.rtc.room API documentation