westy412
03/29/2024, 1:08 PMSahil
03/30/2024, 2:17 AMwesty412
03/30/2024, 8:18 AMSahil
03/30/2024, 10:28 AMwesty412
04/03/2024, 5:39 PMwesty412
04/03/2024, 5:41 PMpython
class FunctionsAPIView(APIView):
def post(self, request, *args, **kwargs):
data = request.data # DRF uses request.data instead of request.json
payload = data.get('message')
if payload['type'] == 'end-of-call-report':
# Handle end-of-call report by sending the data to the call analysis view
return self.handle_end_of_call_report(request, data)
elif payload["type"] == "function-call":
function_call = payload.get('functionCall')
if not function_call:
raise ValueError("Invalid function call")
function_name = function_call.get('name')
parameters = function_call.get('parameters')
if function_name == "get_availability":
timezone = parameters.get('timezone')
availability = get_free_slots(timezone)
print("AVAILABILITY FUNCTION CALLED", "\n")
return Response({"result": f"{availability}"})
elif payload["type"] == 'status-update':
return Response({"result": "ignore"})
elif payload['type'] == 'hang':
return Response({"result": "ignore"})
else:
print(f"{payload['type']}", "\n")
raise ValueError("Unhandled message type")
westy412
04/03/2024, 5:42 PM