python-sdks icon indicating copy to clipboard operation
python-sdks copied to clipboard

Answer SIP call

Open Kedaqusa1604 opened this issue 1 year ago • 0 comments

Hi there, I'd like to know how can I answer a SIP call using the sdk...

what I'd like to do is attach a "controller" to a room created by a SIP call, and listen to room events and then do some stuff, but I'm facing the problem that the call isn't answered.

this is some code, which I hope provides more context:

### main.py
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli

async def entrypoint(ctx: JobContext):

    # Connect to the LiveKit room
    # indicating that the agent will only subscribe to audio tracks
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)

    agent = TestAgent()

    await asyncio.sleep(1)

    agent.start(ctx.room)

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

### TestAgent.py

class TestAgent:

    def start(self, room: rtc.Room):
        print("Room: ", room)
        
        @room.on("participant_connected")
        def on_participant_connected(participant: RemoteParticipant):
            self._on_participant_connected(participant)
        
        @room.on("sip_dtmf_received")
        def on_sip_dtmf(dtmf: rtc.SipDTMF):
            self._on_sip_dtmf(dtmf)

Thanks in advance for any help.

Kedaqusa1604 avatar Oct 03 '24 20:10 Kedaqusa1604