Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plivo support for telephony as it supports both US and India for phone numbers and outbound calling #148

Closed
bevenky opened this issue May 13, 2024 · 8 comments · Fixed by #199
Labels

Comments

@bevenky
Copy link

bevenky commented May 13, 2024

No description provided.

@prateeksachan
Copy link
Member

Hey @bevenky, we've documented the approach to add telephony providers in readme: https://github.com/bolna-ai/bolna?tab=readme-ov-file#extending-with-other-telephony-providers

For reference, you may check out Twilio/Exotel integrations (assuming Plivo's would be similar and supporting similar events/packets): https://github.com/bolna-ai/bolna/tree/master/bolna/output_handlers/telephony_providers

@prateeksachan prateeksachan linked a pull request May 14, 2024 that will close this issue
@prateeksachan
Copy link
Member

hey @bevenky , was trying to integrate with plivo but wasn't sure on how to stream outbound calls. have reached out to your support team for this.

example gist: https://gist.github.com/prateeksachan/816cfe1e8416e86d08980026a7eee7e8

@chrigui
Copy link

chrigui commented May 23, 2024

hey @bevenky , was trying to integrate with plivo but wasn't sure on how to stream outbound calls. have reached out to your support team for this.

example gist: https://gist.github.com/prateeksachan/816cfe1e8416e86d08980026a7eee7e8

Have you managed to fix the stream outbound calls ?

@prateeksachan
Copy link
Member

hey @chrigui , we managed to stream an outbound call using plivo. Will push the PR in the next couple of hours.

@chrigui
Copy link

chrigui commented May 23, 2024

hey @chrigui , we managed to stream an outbound call using plivo. Will push the PR in the next couple of hours.

Glad it worked out, Looking forward to it. Thank you

@prateeksachan
Copy link
Member

prateeksachan commented May 23, 2024

Hey @bevenky , I have now integrated plivo as part of #157 but facing an issue where a 2nd /post_callback is triggered opening up another websocket connection just after the initial call is finished. Have reached out to the support.

plivo code for triggering the API call and streaming an outbound call over websocket:

@app.post('/call')
async def make_call(request: Request):
try:
call_details = await request.json()
agent_id = call_details.get('agent_id', None)
if not agent_id:
raise HTTPException(status_code=404, detail="Agent not provided")
if not call_details or "recipient_phone_number" not in call_details:
raise HTTPException(status_code=404, detail="Recipient phone number not provided")
user_id = str(uuid.uuid4())
app_callback_url, websocket_url = populate_ngrok_tunnels()
print(f'app_callback_url: {app_callback_url}')
print(f'websocket_url: {websocket_url}')
call = plivo_client.calls.create(
from_=plivo_phone_number,
to_=call_details.get('recipient_phone_number'),
answer_url=f"{app_callback_url}/plivo_callback?ws_url={websocket_url}&agent_id={agent_id}",
answer_method='POST')
# persisting user details
await redis_client.set(user_id, json.dumps(call_details))
await close_redis_connection()
return PlainTextResponse("done", status_code=200)
except Exception as e:
print(f"Exception occurred in make_call: {e}")
raise HTTPException(status_code=500, detail="Internal Server Error")
@app.post('/plivo_callback')
async def plivo_callback(request: Request, ws_url: str = Query(...), agent_id: str = Query(...)):
try:
websocket_plivo_route = f'{ws_url}/chat/v1/{agent_id}'
response = '''
<Response>
<Stream bidirectional="true">{}</Stream>
<MultiPartyCall role="customer">mpc_name</MultiPartyCall>
</Response>
'''.format(websocket_plivo_route)
return PlainTextResponse(str(response), status_code=200, media_type='text/xml')
except Exception as e:
print(f"Exception occurred in plivo_callback: {e}")

Related logs:

wss://cd72-2405-201-4012-a2-e981-d67a-f4e6-fec6.ngrok-free.app/chat/v1/f22b5780-3261-46a2-a2f0-21d029ed0f48
INFO:     18.136.128.252:0 - "POST /plivo_callback?ws_url=wss://cd72-2405-201-4012-a2-e981-d67a-f4e6-fec6.ngrok-free.app&agent_id=f22b5780-3261-46a2-a2f0-21d029ed0f48 HTTP/1.1" 200 OK
wss://cd72-2405-201-4012-a2-e981-d67a-f4e6-fec6.ngrok-free.app/chat/v1/f22b5780-3261-46a2-a2f0-21d029ed0f48
INFO:     18.136.128.252:0 - "POST /plivo_callback?ws_url=wss://cd72-2405-201-4012-a2-e981-d67a-f4e6-fec6.ngrok-free.app&agent_id=f22b5780-3261-46a2-a2f0-21d029ed0f48 HTTP/1.1" 200 OK

@prateeksachan prateeksachan linked a pull request May 26, 2024 that will close this issue
@prateeksachan prateeksachan reopened this May 26, 2024
@prateeksachan
Copy link
Member

prateeksachan commented May 26, 2024

hey @bevenky this is now merged and integrated. However, streaming audio chunks back to Plivo isn't working and hence there's a limitation to interruption handling during conversations. If someone from Plivo can check - it would be great!

bolna/README.md

Lines 205 to 211 in 00f3ca0

<summary>Telephony Providers</summary><br>
These are the current supported Telephony Providers:
| Provider | Environment variable to be added in `.env` file |
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Twilio | `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_PHONE_NUMBER` |
| Plivo | `PLIVO_AUTH_ID`, `PLIVO_AUTH_TOKEN`, `PLIVO_PHONE_NUMBER`<br/><br/> *Currently, sending audio packets in chunks isn't possible for Plivo limiting interruption handling |

Additionally, if there's any official Plivo blog to setup a Trial account we can add the link here:

bolna/README.md

Lines 50 to 52 in b160e7c

1. Telephony web server:
* Choosing Twilio: for initiating the calls one will need to set up a [Twilio account](https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account)
* Choosing Plivo: for initiating the calls one will need to set up a [Plivo account](https://www.plivo.com/)

@prateeksachan
Copy link
Member

Closing this now. Plivo will be releasing improvements which might enable interruptions in couple of days. We can pick it up when it goes GA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants