Quick Start

View as Markdown

For 0.24.0, the recommended pattern is to create the client config with a factory helper, start the client with async with TelcoflowClient(config), register event handlers, and then call run_forever().

SANDBOX Mode (API Key Authentication)

1import asyncio
2import os
3
4from telcoflow_sdk import ActiveCall, TelcoflowClient, TelcoflowClientConfig
5import telcoflow_sdk.events as events
6
7async def handle_call(call: ActiveCall):
8 @call.on(events.CALL_TERMINATED)
9 def on_terminated():
10 print("Call terminated")
11
12 await call.answer()
13
14 async for audio_chunk in call.audio_stream():
15 response_audio = await ai_model.process(audio_chunk)
16 await call.send_audio(response_audio)
17
18 # Because this flow never calls connect(), close() ends the call.
19 await call.close()
20
21async def main():
22 config = TelcoflowClientConfig.sandbox(
23 api_key=os.getenv("WSS_API_KEY"),
24 connector_uuid=os.getenv("WSS_CONNECTOR_UUID"),
25 sample_rate=24000,
26 )
27
28 async with TelcoflowClient(config) as client:
29 @client.on(events.INCOMING_CALL)
30 async def on_incoming_call(call: ActiveCall):
31 await handle_call(call)
32
33 await client.run_forever()
34
35if __name__ == "__main__":
36 asyncio.run(main())

Separate Receive and Send Pipelines

If your application needs to read from audio_stream() and write with send_audio() independently, use asyncio.TaskGroup and a queue so neither side blocks the other.

PROD Mode (mTLS Authentication)

1from telcoflow_sdk import TelcoflowClientConfig
2
3config = TelcoflowClientConfig.production(
4 cert_path="/etc/certs/client.pem",
5 key_path="/etc/certs/client.key",
6 sample_rate=24000,
7)

Next Steps