tall-autumn-57974
08/18/2025, 9:11 AM#
3. Once this is done, I want the agent session to starttall-airline-16756
08/18/2025, 9:11 AMtall-airline-16756
08/18/2025, 9:12 AMtall-autumn-57974
08/18/2025, 9:12 AMtall-airline-16756
08/18/2025, 9:13 AMparticipant.attributes['sip.phoneNumber']
.
4. Handle DTMF Inputs: Then, add an event listener for DTMF signals to catch the caller’s input. This is super handy for collecting extra info or guiding them through an IVR before you start the agent session.
If you want a hand with the implementation or some code examples, just give me a shout—I’m here to help! Sources: ivr-nagivator/agent.py | agent.py | src/setup-livekit.ts | SIP participant | LiveKit Docstall-autumn-57974
08/18/2025, 9:16 AMparticipant.attributes['sip.phoneNumber']
but this number is hidden or local (ie not mobile), I want to ask the user to input their mobile phone number via DTMF and finish their input by typing #
.
Then I will parse the phone number and correct the input if necessarytall-airline-16756
08/18/2025, 9:17 AM#
.
2. Capture DTMF Input: Listen for the DTMF tones and gather the digits until you detect the #
.
3. Validate the Input: Check the input against a regular expression to confirm it looks like a valid phone number. For example, the pattern ^\+?[1-9]\d{1,14}$
works well for international numbers.
4. Provide Feedback: If the number doesn’t look right, gently ask the user to try again by replaying the prompt. If it’s good, you can move forward with your app’s next steps.
If you’d like, I’m here to help with code examples or any other details you need!tall-autumn-57974
08/18/2025, 9:17 AMtall-airline-16756
08/18/2025, 9:17 AMrefined-appointment-81829
08/18/2025, 12:28 PMimport json
import asyncio
from livekit import api
from livekit import rtc
from your_tts_library import TTS # Replace with your TTS library
from your_dtmf_library import DTMFCollector # Replace with your DTMF collection logic
async def collect_phone_number(ctx):
# Play a prompt asking for the phone number
await ctx.room.local_participant.publish_audio("path/to/your/prompt.mp3") # Play an MP3 file
# Alternatively, use TTS
# await TTS.speak("Please enter your phone number followed by the pound key.")
dtmf_collector = DTMFCollector() # Initialize your DTMF collector
phone_number = ""
while True:
code = await dtmf_collector.wait_for_dtmf() # Wait for DTMF input
if code == "#": # End input on #
break
elif code.isdigit(): # Collect digits
phone_number += code
return phone_number
async def main(ctx):
# Collect the phone number from the caller
phone_number = await collect_phone_number(ctx)
print(f"Collected phone number: {phone_number}")
# Now start the agent session
agent = OutboundCaller(
name="Agent Name",
appointment_time="next Tuesday at 3pm",
dial_info={"phone_number": phone_number},
)
session = AgentSession(
turn_detection=EnglishModel(),
vad=silero.VAD.load(),
stt=deepgram.STT(),
tts=cartesia.TTS(),
llm=openai.LLM(model="gpt-4o"),
)
# Start the session
await session.start()
# Assuming you have a context (ctx) available
# asyncio.run(main(ctx))
Explanation
1. Prompting for Input: The code plays an audio prompt asking the caller to input their phone number. You can use either an MP3 file or TTS to generate the prompt.
2. DTMF Collection: The DTMFCollector
class (which you would need to implement) listens for DTMF tones. It collects digits until the caller presses #
, which indicates the end of input.
3. Starting the Agent Session: After collecting the phone number, the agent session is started with the collected phone number.
Notes
• Make sure to replace the placeholders for TTS and DTMF collection with your actual implementations.
• Ensure that your audio prompt file path is correct.
• This example assumes you have a context (ctx
) available to work with.
This approach allows you to collect the caller's phone number before starting the agent session, as you requested.
References
• livekit-examples/outbound-caller-python/agent.py#L169-L226
• livekit-examples/outbound-caller-python/agent.py#L169-L226
• livekit-examples/agent-demos/ivr-nagivator/agent.py#L57-L111
• livekit-examples/agent-demos/ivr-nagivator/agent.py#L57-L111
• livekit/livekit-omni/livekit-examples/agent-demos/ivr-nagivator/agent.py#L57-L111tall-autumn-57974
08/18/2025, 12:49 PM