How to answer a call in Azure Communications Services using Python?

Young Yee Er 0 Reputation points
2023-11-13T02:34:50.8366667+00:00

I am following this guide https://learn.microsoft.com/en-us/python/api/overview/azure/communication-callautomation-readme?view=azure-python to answer a call in Azure Communications Services using Python.

After creating a call and retrieving the connection ID successfully, I am struggling with answering/starting the call. Regardless of how I format the incoming_call_context, I receive the following error:

File ~\Anaconda3\lib\site-packages\azure\communication\callautomation\_generated\operations\_operations.py:967, in AzureCommunicationCallAutomationServiceOperationsMixin.answer_call(self, answer_call_request, repeatability_request_id, repeatability_first_sent, **kwargs)
    965     map_error(status_code=response.status_code, response=response, error_map=error_map)
    966     error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, pipeline_response)
--> 967     raise HttpResponseError(response=response, model=error)
    969 deserialized = self._deserialize("CallConnectionProperties", pipeline_response)
    971 if cls:

HttpResponseError: (8523) Incoming Call Context is invalid.
Code: 8523
Message: Incoming Call Context is invalid.

I have been unable to find any resources on how to correctly format the incoming call context. My goal is to establish a call between two authenticated ACS clients using the same ACS subscription, without encountering this error. Ultimately, I plan to set up a test environment for a LLM powered voice bot to answer calls from one end, and a human from the other.

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,242 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2023-12-01T06:43:11.6266667+00:00

    CallAutomationClient in Azure Communication Services only requires a callback_url parameter to answer a call. The callback_url is the URL that the service will use to send events related to the call, such as incoming video or audio streams.

    However, if you have a WebSocket server that you want to use to handle the incoming video or audio streams, you will need to implement the WebSocket connection in your own code and pass the necessary information to the CallAutomationClient to use your WebSocket server instead of the default one.

    Also as mentioned-

    we are releasing more samples in Python in the coming weeks (Can not share ETA here) but you can refer to the documentation for the WebSocket library you are using to implement the WebSocket connection, and then pass the WebSocket URL to the CallAutomationClient as a custom header or parameter.

    see- https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-websocket-connect?tabs=browser

    I hope this helps! Let me know if you have any further questions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.