Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Twilio example #200

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified images/examples/twilio-agent/twilio-deployment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions v4/examples/twilio-voice-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ In your IDE, run the following command to create our Cerebrium starter project:

- **main.py** - Our entrypoint file where our code lives
- **cerebrium.toml** - A configuration file that contains all our build and environment settings
Add the following pip packages near the bottom of your cerebrium.toml. This will be used in creating our deployment environment.

```
Expand Down Expand Up @@ -47,7 +46,7 @@ from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import HTMLResponse

from .bot import main
from bot import main

app = FastAPI()

Expand All @@ -63,7 +62,7 @@ app.add_middleware(
@app.post("/")
async def start_call():
print("POST TwiML")
return HTMLResponse(content=open("app/templates/streams.xml").read(), media_type="application/xml")
return HTMLResponse(content=open("templates/streams.xml").read(), media_type="application/xml")


@app.websocket("/ws")
Expand All @@ -78,14 +77,15 @@ async def websocket_endpoint(websocket: WebSocket):
await main(websocket, stream_sid)
```

Don't worry about the line `from .bot import main` - we will add this later. In your current directory, create a folder called 'templates' and inside it a file called 'stream.xml'.
Don't worry about the line `from bot import main` - we will add this later. In your current directory, create a folder called 'templates' and inside it a file called 'stream.xml'.
We need to send back a xml response to Twilio in order to upgrade the connection to the websocket connection. Add the following code to the streams.xml file:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect>
<Stream url="wss://api.cortex.cerebrium.ai/v4/p-xxxxxxx/twilio-agent/ws"></Stream>
<!--Update with your project ID below-->
<Stream url="wss://api.cortex.cerebrium.ai/v4/p-xxxxxxx/4-twilio-agent/ws"></Stream>
</Connect>
<Pause length="40"/>
</Response>
Expand Down
Loading