Repository navigation
Expand file tree
/
Copy pathwarm_transfer.py
More file actions
45 lines (33 loc) · 1.56 KB
/
Copy pathwarm_transfer.py
File metadata and controls
45 lines (33 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
from dotenv import load_dotenv
from support_agent import SUMMARY_INSTRUCTIONS, SupportAgent, start_session
from livekit.agents import AgentServer, JobContext, cli
from livekit.agents.beta.workflows import WarmTransferResult, WarmTransferTask
load_dotenv()
# ensure the following variables/env vars are set
SIP_TRUNK_ID = os.getenv("LIVEKIT_SIP_OUTBOUND_TRUNK") # "ST_abcxyz"
SUPERVISOR_PHONE_NUMBER = os.getenv("LIVEKIT_SUPERVISOR_PHONE_NUMBER") # "+12003004000"
SIP_NUMBER = os.getenv("LIVEKIT_SIP_NUMBER") # "+15005006000" - caller ID shown to supervisor
class SIPSupportAgent(SupportAgent):
async def _start_transfer(self) -> WarmTransferResult:
assert SIP_TRUNK_ID is not None
assert SUPERVISOR_PHONE_NUMBER is not None
return await WarmTransferTask(
sip_call_to=SUPERVISOR_PHONE_NUMBER,
sip_trunk_id=SIP_TRUNK_ID,
sip_number=SIP_NUMBER,
chat_ctx=self.chat_ctx,
# to reach an extension behind an IVR, pass DTMF tones to send once
# answered, e.g. dtmf="wwww1234#" (each `w` pauses ~0.5s):
# dtmf=SUPERVISOR_EXTENSION,
# give up if the supervisor doesn't pick up within 25s:
# ringing_timeout=25,
# add extra instructions for summarization
extra_instructions=SUMMARY_INSTRUCTIONS,
)
server = AgentServer()
@server.rtc_session(agent_name="sip-inbound")
async def entrypoint(ctx: JobContext) -> None:
await start_session(ctx, SIPSupportAgent())
if __name__ == "__main__":
cli.run_app(server)