inbound calls

This commit is contained in:
Ajay Raj 2023-03-04 13:59:33 -08:00
commit 2893ba9780
8 changed files with 58 additions and 20 deletions

View file

@ -1,11 +1,15 @@
from vocode.models.model import BaseModel
from vocode.models.agent import AgentConfig, InformationRetrievalAgentConfig
from vocode.models.agent import AgentConfig
class CallEntity(BaseModel):
phone_number: str
class CreateCallRequest(BaseModel):
class CreateInboundCall(BaseModel):
agent_config: AgentConfig
twilio_sid: str
class CreateOutboundCall(BaseModel):
recipient: CallEntity
caller: CallEntity
agent_config: AgentConfig
agent_config: AgentConfig
# TODO add IVR/etc.

View 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)

View file

@ -1,6 +1,6 @@
from .models.telephony import CallEntity, CreateCallRequest
from ..models.telephony import CallEntity, CreateOutboundCall
import requests
from . import api_key, BASE_URL
from .. import api_key, BASE_URL
VOCODE_OUTBOUND_CALL_URL = f"https://{BASE_URL}/create_outbound_call"
@ -17,7 +17,7 @@ class OutboundCall:
headers={
"Authorization": f"Bearer {api_key}"
},
json=CreateCallRequest(
json=CreateOutboundCall(
recipient=self.recipient,
caller=self.caller,
agent_config=self.agent_config

View file

@ -1,4 +1,4 @@
from fastapi import FastAPI, APIRouter
from fastapi import FastAPI
import uvicorn
class BaseAgent():