inbound calls
This commit is contained in:
parent
de6d76c955
commit
2893ba9780
8 changed files with 58 additions and 20 deletions
35
vocode/telephony/inbound_call_server.py
Normal file
35
vocode/telephony/inbound_call_server.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from fastapi import FastAPI, Response, Form
|
||||
import requests
|
||||
import uvicorn
|
||||
from .. import api_key, BASE_URL
|
||||
|
||||
from ..models.agent import AgentConfig
|
||||
from ..models.telephony import CreateInboundCall
|
||||
|
||||
VOCODE_INBOUND_CALL_URL = f"https://{BASE_URL}/create_inbound_call"
|
||||
|
||||
class InboundCallServer():
|
||||
|
||||
def __init__(self, agent_config: AgentConfig):
|
||||
self.agent_config = agent_config
|
||||
self.app = FastAPI()
|
||||
self.app.post("/vocode")(self.handle_call)
|
||||
|
||||
async def handle_call(self, twilio_sid: str = Form(alias='CallSid')):
|
||||
response = requests.post(
|
||||
VOCODE_INBOUND_CALL_URL,
|
||||
headers={
|
||||
"Authorization": f"Bearer {api_key}"
|
||||
},
|
||||
json=CreateInboundCall(
|
||||
agent_config=self.agent_config,
|
||||
twilio_sid=twilio_sid
|
||||
).dict()
|
||||
)
|
||||
return Response(
|
||||
response.text,
|
||||
media_type="application/xml",
|
||||
)
|
||||
|
||||
def run(self, host="localhost", port=3000):
|
||||
uvicorn.run(self.app, host=host, port=port)
|
||||
27
vocode/telephony/outbound_call.py
Normal file
27
vocode/telephony/outbound_call.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from ..models.telephony import CallEntity, CreateOutboundCall
|
||||
import requests
|
||||
from .. import api_key, BASE_URL
|
||||
|
||||
VOCODE_OUTBOUND_CALL_URL = f"https://{BASE_URL}/create_outbound_call"
|
||||
|
||||
class OutboundCall:
|
||||
|
||||
def __init__(self, recipient: CallEntity, caller: CallEntity, agent_config):
|
||||
self.recipient = recipient
|
||||
self.caller = caller
|
||||
self.agent_config = agent_config
|
||||
|
||||
def start(self):
|
||||
return requests.post(
|
||||
VOCODE_OUTBOUND_CALL_URL,
|
||||
headers={
|
||||
"Authorization": f"Bearer {api_key}"
|
||||
},
|
||||
json=CreateOutboundCall(
|
||||
recipient=self.recipient,
|
||||
caller=self.caller,
|
||||
agent_config=self.agent_config
|
||||
).dict()
|
||||
)
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue