Skip to content

Commit

Permalink
bump telephony app 0.1.110 (#167)
Browse files Browse the repository at this point in the history
* checkpoint

* update docs and bump version
  • Loading branch information
ajar98 authored May 28, 2023
1 parent 7cf9436 commit c67908e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
13 changes: 11 additions & 2 deletions apps/telephony_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from speller_agent import SpellerAgentFactory
import sys

# if running from python, this will load the local .env
# docker-compose will load the .env file by itself
from dotenv import load_dotenv

load_dotenv()

app = FastAPI(docs_url=None)

logging.basicConfig()
Expand All @@ -20,7 +26,7 @@

config_manager = RedisConfigManager()

BASE_URL = os.environ["BASE_URL"]
BASE_URL = os.getenv("BASE_URL")

if not BASE_URL:
ngrok_auth = os.environ.get("NGROK_AUTH_TOKEN")
Expand All @@ -30,7 +36,10 @@

# Open a ngrok tunnel to the dev server
BASE_URL = ngrok.connect(port).public_url.replace("https://", "")
logger.info("ngrok tunnel \"{}\" -> \"http://127.0.0.1:{}\"".format(BASE_URL, port))
logger.info('ngrok tunnel "{}" -> "http://127.0.0.1:{}"'.format(BASE_URL, port))

if not BASE_URL:
raise ValueError("BASE_URL must be set in environment if not using pyngrok")

telephony_server = TelephonyServer(
base_url=BASE_URL,
Expand Down
5 changes: 3 additions & 2 deletions apps/telephony_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vocode==0.1.108
vocode==0.1.110
redis
twilio
pyngrok==6.0.0
pyngrok
python-dotenv
4 changes: 2 additions & 2 deletions apps/telephony_app/speller_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import typing
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
from vocode.streaming.models.agent import AgentConfig, AgentType, ChatGPTAgentConfig
from vocode.streaming.agent.base_agent import BaseAgent
from vocode.streaming.agent.base_agent import BaseAgent, RespondAgent
from vocode.streaming.agent.factory import AgentFactory


class SpellerAgentConfig(AgentConfig, type="agent_speller"):
pass


class SpellerAgent(BaseAgent[SpellerAgentConfig]):
class SpellerAgent(RespondAgent[SpellerAgentConfig]):
def __init__(self, agent_config: SpellerAgentConfig):
super().__init__(agent_config=agent_config)

Expand Down
23 changes: 11 additions & 12 deletions docs/telephony.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,7 @@ Or if you prefer to use Docker for this part:
docker run -dp 6379:6379 -it redis/redis-stack:latest
```

3. Load the environment variables

```
source .env
```

4. Run the server with `uvicorn` (should be already installed in step 1).
3. Run the server with `uvicorn` (should be already installed in step 1).

```
uvicorn main:app --port 3000
Expand Down Expand Up @@ -270,23 +264,27 @@ if __name__ == '__main__':
Here's what happens under the hood for an outbound call.

The `OutboundCall` calls Twilio to initiate the call, giving it a URL to call after the call is initiated:

```
twilio_call = self.twilio_client.calls.create(
url=f"https://{self.base_url}/twiml/initiate_call/{self.conversation_id}",
```

In your main.py you create and start a `TelephonyServer`. The TelephonyServer itself includes a couple of routers:
* `TwiMLRouter`
* `CallsRouter`
In your main.py you create and start a `TelephonyServer`. The TelephonyServer itself includes a couple of routers:

- `TwiMLRouter`
- `CallsRouter`

`TwiMLRouter` includes the matching route:

```
self.router.add_api_route(
"/twiml/initiate_call/{id}", self.call_twiml, methods=["POST"]
)
```

This route returns the template `connect_call.xml` which uses TwiML to tell Twilio to establish a websocket with a given URL:

```
<?xml version="1.0" encoding="UTF-8"?>
<Response>
Expand All @@ -297,18 +295,19 @@ This route returns the template `connect_call.xml` which uses TwiML to tell Twil
```

CallsRouter includes that second route:

```
self.router.websocket("/connect_call/{id}")(self.connect_call)
```

This is where we get the websocket connection. We then create the `Call` object and start it:
This is where we get the websocket connection. We then create the `Call` object and start it:

```
await call.attach_ws_and_start(websocket)
```

The `Call` is a kind of `StreamingConversation` that manages the various pieces: transcriber, synthesizer, agent, etc.


## Inbound Calls

The `InboundCallServer` class provides a simple abstraction to create an endpoint that can host your agent
Expand Down

0 comments on commit c67908e

Please sign in to comment.