add sms verification example#216
Conversation
markbackman
left a comment
There was a problem hiding this comment.
Nice! Few comments on ways to simplify this code and align with other example patterns.
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| async def bot_twilio(websocket: WebSocket) -> None: |
There was a problem hiding this comment.
Rather than have two entry points, we should have a single bot() method, which is required to be Pipecat Cloud compatible.
Once 1.4.0 is available, you'll be able to replace L292-L337 with:
async def bot(runner_args: RunnerArguments):
"""Main bot entry point."""
transport_params = {
"webrtc": lambda: TransportParams(
audio_in_enabled=True,
audio_out_enabled=True,
),
# create_transport sets the twilio serializer and add_wav_header automatically.
"twilio": lambda: FastAPIWebsocketParams(
audio_in_enabled=True,
audio_out_enabled=True,
),
}
transport = await create_transport(runner_args, transport_params)
await run_bot(transport, runner_args)
if __name__ == "__main__":
from pipecat.runner.run import main
main()
Note the main being imported from pipecat.runner.run. This is the pattern in all examples. It's the local development runner, which runs a FastAPI server at port 7860. This does magic which simulates things that Pipecat Cloud does. It also makes local dev much easier. This allows you to remove most (maybe all) of what's in server.py.
Then, you can get access to the caller info via:
call_data = runner_args.call_data
call_info = await get_call_info(call_data.call_id) if call_data else None
if call_info:
logger.info(f"Call from: {call_info.from_number} to: {call_info.to_number}")
| readme = "README.md" | ||
| requires-python = ">=3.11" | ||
| dependencies = [ | ||
| "pipecat-ai[websocket,webrtc,cartesia,google,openai,silero,deepgram,runner]>=1.0.0", |
There was a problem hiding this comment.
You'll want 1.4.0 for the simplification I mentioned:
| "pipecat-ai[websocket,webrtc,cartesia,google,openai,silero,deepgram,runner]>=1.0.0", | |
| "pipecat-ai[websocket,webrtc,cartesia,google,openai,silero,deepgram,runner]>=1.4.0", |
| requires-python = ">=3.11" | ||
| dependencies = [ | ||
| "pipecat-ai[websocket,webrtc,cartesia,google,openai,silero,deepgram,runner]>=1.0.0", | ||
| "fastapi>=0.115.0", |
There was a problem hiding this comment.
You can simplify since these are already installed by Pipecat:
"fastapi>=0.115.0",
"python-dotenv>=1.0.1",
"aiohttp>=3.10.0",
"uvicorn[standard]>=0.32.0",
aiohttpis installed bypipecat-aifastapiis installed bypipecat-ai[websocket]python-dotenvanduvicornare installed bypipecat-ai[runner]
| [tool.ruff] | ||
| line-length = 100 | ||
| [tool.ruff.lint] | ||
| select = ["I"] |
There was a problem hiding this comment.
Just for conformance, we're using modern Python syntax everywhere now:
| select = ["I"] | |
| select = ["I" , "UP"] |
| return StreamingResponse(event_stream(), media_type="text/event-stream") | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- |
There was a problem hiding this comment.
You shouldn't need this either. It's done by the runner.run. It exposes a /ws endpoint.
| app.mount("/static", StaticFiles(directory=CLIENT_DIR), name="static") | ||
|
|
||
|
|
||
| @app.get("/api/config") |
There was a problem hiding this comment.
You shouldn't need this.
| app.mount("/static", StaticFiles(directory=CLIENT_DIR), name="static") | ||
|
|
||
|
|
||
| @app.get("/api/config") |
There was a problem hiding this comment.
You shouldn't need this.
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| @app.get("/events") |
There was a problem hiding this comment.
I'm not sure what this is, but seems unique to this demo, so you probably need this :)
A Pipecat voice agent that sends a 6-digit SMS verification code, asks the
caller to read the digits back, and confirms or rejects the match. Runs in two
modes from a single bot file; Browser mode & Phone mode. Both modes send
an actual SMS message via Twilio.