inbound calls
This commit is contained in:
parent
de6d76c955
commit
2893ba9780
8 changed files with 58 additions and 20 deletions
|
|
@ -20,12 +20,7 @@ if __name__ == "__main__":
|
|||
input_device=microphone_input,
|
||||
output_device=speaker_output,
|
||||
transcriber_config=DeepgramTranscriberConfig.from_input_device(microphone_input),
|
||||
agent_config=WebSocketUserImplementedAgentConfig(
|
||||
initial_message="Hello!",
|
||||
respond=WebSocketUserImplementedAgentConfig.RouteConfig(
|
||||
url="ws://localhost:3001/respond"
|
||||
)
|
||||
),
|
||||
agent_config=EchoAgentConfig(initial_message="Hello!"),
|
||||
synthesizer_config=AzureSynthesizerConfig.from_output_device(speaker_output)
|
||||
)
|
||||
signal.signal(signal.SIGINT, lambda _0, _1: conversation.deactivate())
|
||||
|
|
|
|||
8
simple_inbound_call_server.py
Normal file
8
simple_inbound_call_server.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from vocode.telephony.inbound_call_server import InboundCallServer
|
||||
from vocode.models.agent import EchoAgentConfig
|
||||
|
||||
if __name__ == '__main__':
|
||||
server = InboundCallServer(
|
||||
agent_config=EchoAgentConfig(initial_message="hello!")
|
||||
)
|
||||
server.run(port=3001)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from vocode.outbound_call import OutboundCall
|
||||
from vocode.telephony.outbound_call import OutboundCall
|
||||
from vocode.models.telephony import CallEntity
|
||||
from vocode.models.agent import EchoAgentConfig, WebSocketUserImplementedAgentConfig
|
||||
|
||||
|
|
@ -10,10 +10,6 @@ if __name__ == '__main__':
|
|||
caller=CallEntity(
|
||||
phone_number="+14086600744",
|
||||
),
|
||||
agent_config=WebSocketUserImplementedAgentConfig(
|
||||
respond=WebSocketUserImplementedAgentConfig.RouteConfig(
|
||||
url="ws://localhost:3001/respond"
|
||||
)
|
||||
)
|
||||
agent_config=EchoAgentConfig(initial_message="Hello!")
|
||||
)
|
||||
call.start()
|
||||
|
|
@ -24,4 +24,4 @@ class TestWebSocketAgent(WebSocketAgent):
|
|||
|
||||
if __name__ == "__main__":
|
||||
agent = TestWebSocketAgent()
|
||||
agent.run(port=3001)
|
||||
agent.run(port=3000)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
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)
|
||||
|
|
@ -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
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
from fastapi import FastAPI, APIRouter
|
||||
from fastapi import FastAPI
|
||||
import uvicorn
|
||||
|
||||
class BaseAgent():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue