Skip to content

Commit b8d0886

Browse files
Merge pull request #203 from restackio/fixTwilio
Fix livekit Twilio example
2 parents 86b7196 + e29e027 commit b8d0886

File tree

16 files changed

+214
-17
lines changed

16 files changed

+214
-17
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TWILIO_ACCOUNT_SID=
22
TWILIO_AUTH_TOKEN=
33
TWILIO_PHONE_NUMBER="+000000000000"
4-
LIVEKIT_SIP_URI="sip:XXXXX.sip.livekit.cloud;transport=tcp"
4+
LIVEKIT_SIP_URI="sip:XXXXX.sip.livekit.cloud;transport=tcp"
5+
TRUNK_NAME="LiveKit Trunk"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"trunk": {
3+
"name": "Inbound LiveKit Trunk",
4+
"numbers": [
5+
"+12096194281"
6+
]
7+
}
8+
}

agent_telephony/twilio/livekit-trunk-setup/twilio_trunk.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ def get_env_var(var_name):
1616
return value
1717

1818

19-
def create_livekit_trunk(client, sip_uri):
19+
def create_livekit_trunk(client, sip_uri, trunk_name):
2020
domain_name = f"livekit-trunk-{os.urandom(4).hex()}.pstn.twilio.com"
2121
trunk = client.trunking.v1.trunks.create(
22-
friendly_name="LiveKit Trunk",
22+
friendly_name=trunk_name,
2323
domain_name=domain_name,
2424
)
2525
trunk.origination_urls.create(
2626
sip_url=sip_uri,
2727
weight=1,
2828
priority=1,
2929
enabled=True,
30-
friendly_name="LiveKit SIP URI",
30+
friendly_name=f"{trunk_name} SIP URI",
3131
)
32-
logging.info("Created new LiveKit Trunk.")
32+
logging.info(f"Created new {trunk_name} trunk.")
3333
return trunk
3434

3535

36-
def create_inbound_trunk(phone_number):
37-
trunk_data = {"trunk": {"name": "Inbound LiveKit Trunk", "numbers": [phone_number]}}
36+
def create_inbound_trunk(phone_number, trunk_name):
37+
trunk_data = {"trunk": {"name": f"Inbound {trunk_name}", "numbers": [phone_number]}}
3838
with open("inbound_trunk.json", "w") as f:
3939
json.dump(trunk_data, f, indent=4)
4040

@@ -58,9 +58,9 @@ def create_inbound_trunk(phone_number):
5858
return None
5959

6060

61-
def create_dispatch_rule(trunk_sid):
61+
def create_dispatch_rule(trunk_sid, trunk_name):
6262
dispatch_rule_data = {
63-
"name": "Inbound Dispatch Rule",
63+
"name": f"Inbound {trunk_name} Dispatch Rule",
6464
"trunk_ids": [trunk_sid],
6565
"rule": {"dispatchRuleIndividual": {"roomPrefix": "call-"}},
6666
}
@@ -89,23 +89,25 @@ def main():
8989
auth_token = get_env_var("TWILIO_AUTH_TOKEN")
9090
phone_number = get_env_var("TWILIO_PHONE_NUMBER")
9191
sip_uri = get_env_var("LIVEKIT_SIP_URI")
92+
trunk_name = get_env_var("TRUNK_NAME")
9293

9394
client = Client(account_sid, auth_token)
9495

9596
existing_trunks = client.trunking.v1.trunks.list()
9697
livekit_trunk = next(
97-
(trunk for trunk in existing_trunks if trunk.friendly_name == "LiveKit Trunk"),
98+
(trunk for trunk in existing_trunks if trunk.friendly_name == trunk_name),
9899
None,
99100
)
100101

101102
if not livekit_trunk:
102-
livekit_trunk = create_livekit_trunk(client, sip_uri)
103+
livekit_trunk = create_livekit_trunk(client, sip_uri, trunk_name)
103104
else:
104-
logging.info("LiveKit Trunk already exists. Using the existing trunk.")
105+
logging.info(f"{trunk_name} already exists. Using the existing trunk.")
105106

106-
inbound_trunk_sid = create_inbound_trunk(phone_number)
107+
108+
inbound_trunk_sid = create_inbound_trunk(phone_number, trunk_name)
107109
if inbound_trunk_sid:
108-
create_dispatch_rule(inbound_trunk_sid)
110+
create_dispatch_rule(inbound_trunk_sid, trunk_name)
109111

110112

111113
if __name__ == "__main__":

agent_telephony/twilio/livekit_pipeline/src/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def on_metrics_collected(agent_metrics: metrics.AgentMetrics) -> None:
124124
cli.run_app(
125125
WorkerOptions(
126126
entrypoint_fnc=entrypoint,
127-
agent_name="AgentStream",
127+
agent_name="AgentTwilio",
128128
prewarm_fnc=prewarm,
129129
)
130130
)

agent_telephony/twilio/readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Build an AI agent that do an outbound call with Twilio and can interact with in
77

88
- Docker (for running Restack)
99
- Python 3.10 or higher
10-
- Vapi account (for outbound calls)
10+
- Twilio account (for outbound calls)
11+
- Livekit account (for WebRTC pipeline)
12+
- Deepgram account (for transcription)
13+
- ElevenLabs account (for TTS)
1114

1215
### Trunk setup for outbound calls with Twilio
1316

agent_voice/livekit/livekit_pipeline/src/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def on_metrics_collected(agent_metrics: metrics.AgentMetrics) -> None:
124124
cli.run_app(
125125
WorkerOptions(
126126
entrypoint_fnc=entrypoint,
127-
agent_name="AgentStream",
127+
agent_name="AgentVoice",
128128
prewarm_fnc=prewarm,
129129
)
130130
)

community/docling/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
poetry.lock
2+
.env

community/docling/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.12-bookworm
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update && apt-get install -y \
6+
git build-essential gcc libc-dev \
7+
&& apt-get clean
8+
9+
RUN pip install --no-cache-dir --timeout=60 --retries=5 poetry
10+
11+
COPY pyproject.toml ./
12+
13+
COPY . .
14+
15+
# Configure poetry to not create virtual environment
16+
RUN poetry config virtualenvs.create false
17+
18+
ENV PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu
19+
20+
# Install dependencies
21+
RUN poetry install --no-interaction --no-ansi
22+
23+
# Expose port 80
24+
EXPOSE 80
25+
26+
CMD poetry run python -m src.services

community/docling/pyproject.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[tool.poetry]
2+
name = "docling-test"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Your Name <[email protected]>"]
6+
readme = "readme.md"
7+
packages = [
8+
{ include = "src" }
9+
]
10+
11+
[[tool.poetry.source]]
12+
name = "pytorch"
13+
url = "https://download.pytorch.org/whl/cpu"
14+
priority = "supplemental"
15+
16+
[tool.poetry.dependencies]
17+
python = "^3.12"
18+
pydantic-settings = "^2.7.1"
19+
aiohttp = "^3.11.11"
20+
pydantic = "^2.10.6"
21+
tavily-python = "^0.5.1"
22+
openai = "^1.61.1"
23+
mistune = "^3.1.1"
24+
requests = "^2.32.3"
25+
beautifulsoup4 = "^4.13.3"
26+
gitpython = "^3.1.44"
27+
validators = "^0.34.0"
28+
restack-ai = "0.0.62"
29+
docling = "^2.25.0"
30+
31+
[build-system]
32+
requires = ["poetry-core"]
33+
build-backend = "poetry.core.masonry.api"
34+
35+
[tool.poetry.scripts]
36+
services = "src.services:run_services"
37+

community/docling/readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
4+
poetry env use 3.12
5+
6+
poetry install
7+
8+
poetry run services
9+

0 commit comments

Comments
 (0)