Skip to content

Commit 01b6033

Browse files
committed
Add Twilio websocket
1 parent 6a10d90 commit 01b6033

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/index.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from fastapi import FastAPI, Request
1+
from fastapi import FastAPI, Request, WebSocket
22
from fastapi.responses import Response
33
from twilio.twiml.messaging_response import MessagingResponse
44
import requests
55
import json
6+
import base64
67

78
url = "https://apps.beam.cloud/e928s"
89
headers = {
@@ -23,7 +24,23 @@ async def root():
2324
async def say_hello(name: str):
2425
return {"message": f"Hello {name}"}
2526

26-
@app.post('/webhook')
27+
@app.post('/webhook/call')
28+
async def webhook(request: Request):
29+
print('ICI', request)
30+
31+
@app.websocket("/stream")
32+
async def websocket_endpoint(websocket: WebSocket):
33+
await websocket.accept()
34+
while True:
35+
data = await websocket.receive_text()
36+
data = json.loads(data)
37+
if 'payload' in data:
38+
audio_data = base64.b64decode(data['payload'])
39+
print(type(audio_data))
40+
# Maintenant, `audio_data` contient l'audio brut que vous pouvez passer à votre fonction de transcription
41+
# transcription = your_transcription_function(audio_data)
42+
43+
@app.post('/webhook/whatsapp')
2744
async def webhook(request: Request):
2845
print('ICI', request)
2946

0 commit comments

Comments
 (0)