10-23-2023 02:28 AM
I'm working on a Python script with a specific goal in mind: to capture incoming calls or active calls, retrieve the caller's phone number when the user accepts the call, and then use this phone number to search our database for information about the caller. The idea is to display relevant caller information to the user.
Currently, my script is running without any errors. However, it doesn't seem to recognize incoming calls or active calls. I'm wondering if there might be an issue with the way I'm handling call detection.
For the moment, I'm using the Webex API endpoint https://api.ciscospark.com/v1/telephony/calls to detect incoming calls. In my testing, I've authenticated my Python script with my Webex account using an access token. I then attempted to call my Webex account from my personal phone to trigger an incoming call.
However, it appears that the script isn't recognizing incoming calls or active calls. I'm new to the Webex API and this type of development in general, so it's possible that I'm missing something important in the setup or call detection process.
Here my 3 functions for the moment :
# Perform an OAuth authorization request to get the authorization code
def obtain_authorization_code(client_id, redirect_uri, scopes):
auth_url = 'xx'
print('Please access the following URL to authorize your application:')
print(auth_url)
authorization_code = input('Enter the authorization code: ')
return authorization_code
# Exchange the authorization code for an access token
def exchange_authorization_code_for_access_token(client_id, client_secret, redirect_uri, authorization_code):
token_data = {
'grant_type': 'authorization_code',
'client_id': client_id,
'client_secret': client_secret,
'code': authorization_code,
'redirect_uri': redirect_uri
}
response = requests.post(token_url, data=token_data)
if response.status_code == 200:
return response.json().get('access_token')
else:
print(f'Failed to request an access token: {response.status_code} - {response.text}')
return None
# Function to get details of active calls from /v1/telephony/calls
def get_active_calls(access_token):
url = 'https://api.ciscospark.com/v1/telephony/calls'
headers = {
'Authorization': f'Bearer {access_token}'
}
response = requests.get(url, headers=headers)
response_data = response.json()
active_calls = [call for call in response_data.get('items', []) if call.get('state') == 'active']
return active_calls
# Function to monitor incoming calls
def handle_incoming_call():
while True:
print("Entering the while loop")
active_calls = get_active_calls(access_token)
for call in active_calls:
if call.get('direction') == 'in':
phone_number = call.get('remoteAddress')
print(f"Incoming call from: {phone_number}")
time.sleep(5)
# Main
redirect_uri = 'http://localhost'
authorization_code = obtain_authorization_code(client_id, redirect_uri, scopes)
if authorization_code:
access_token = exchange_authorization_code_for_access_token(client_id, client_secret, redirect_uri, authorization_code)
if access_token:
api = WebexTeamsAPI(access_token)
print("Authentication successful. The application is ready to detect incoming calls. Your token: " + access_token)
handle_incoming_call()
Any insights or suggestions on how to troubleshoot this issue would be greatly appreciated. Thanks in advance for your help!
10-23-2023 08:42 AM
Note that the Webex Calling APIs are applicable only for Webex Calling (not 1:1/space ad hoc calls, which are considered 'meetings').
You will definitely not want to get this real-time status info via polling as the code above attempts - implementing a webhook for getting telephony call create/update events is the way to go, see Webhooks
My suspicion is that you may be getting stale/cached info by polling, or that the poll requests are actually failing due to request rate throttling - Python requests will not actually fail/trigger an exception on receiving a 429 Too Many Requests unless you perform raise_for_status()
10-30-2023 05:01 AM - edited 10-30-2023 06:20 AM
Thank you for your reply. I'm coming back to you because I'm wondering about the resource required for my webhook. I have successfully tested with the webhook dedicated to messages, but when I tried to set up webhooks for meetings, telephony_calls or recordings events (creation or update), so every resource that for me can be referenced for calls on this page. The creation of these webhooks was successfully completed, as evidenced by their presence in the list of webhooks list-webhooks .
However, when I make calls from my home number to my Webex number, none of these webhooks seem to trigger when I answer the call. The only webhook that works as expected is the message webhook. I'm not sure if you have any recommendations or advice on how to solve this problem.
11-02-2023 08:15 AM
The telephony_calls resource should trigger if the call is a PSTN from your home number to your Webe Calling number. This resource is a user level resource so the webhook would need to be created by the Webex Calling user who is receiving the call.
12-16-2024 07:27 AM
Since this is a user level resource is there any way to trigger a webhook for an Auto Attendant receiving a call?
12-16-2024 01:11 PM
Unfortunately, there is not. This would need to be a feature request, which you can submit through https://ciscocollabcustomer.ideas.aha.io/.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide