I’m trying to integrate a webhook with BigBlueButton (BBB) after successfully creating a meeting via the BBB API. However, when attempting to register the webhook, I encounter an IncompleteRead(0 bytes read) error.
My Code:
@login_required
def CreateEventsByBBB():
try:
if g.role == ‘teacher’:
data = request.get_json()
q = Classroom.query.filter(Classroom.teacher_id == g.user_id).all()
check = 0 # to check if client 'classroom_id' is actually in the classroom table corresponding to teacher_id
for elem in q:
if elem.id == int(data['classroom_id']):
check = 1
if data['event_name'] != '' and data['event_desc'] != '' and check:
if 'link' not in data:
data['link'] = None
if 'password' not in data:
data['password'] = None
if 'demo' not in data:
data['demo'] = None
if 'end_timestamp' not in data:
data['end_timestamp'] = None
if data['external_link_check'] == False:
eventName = data['event_name']
replacedEventName = eventName.replace(' ', '_')
meetingID = replacedEventName + str(int(datetime.now().timestamp() * 1000))
# Define your parameters for creating the meeting
create_params = {
'allowStartStopRecording': 'true',
'attendeePW': 'ap',
'autoStartRecording': 'false',
'meetingID': meetingID,
'moderatorPW': 'mp',
'name': meetingID,
'record': 'false',
}
# Construct the query string for checksum calculation
query_string = '&'.join([f"{key}={value}" for key, value in create_params.items()])
shared_secret = current_app.config['BBB_SHARED_SECRET']
# Calculate the checksum
checksum_string = f"create{query_string}{shared_secret}"
checksum = sha1(checksum_string.encode()).hexdigest()
# Add the checksum to the parameters
create_params['checksum'] = checksum
# Construct the URL with parameters
url = current_app.config['BIGBLUEBUTTON_PATH'] + 'create?' + '&'.join([f"{key}={value}" for key, value in create_params.items()])
response = requests.get(url, verify=False)
print(meetingID, url, response)
# Define your parameters for webhook
webhook_create_param = {
'callbackURL': 'https://examcourse.medhasvi.com/webhook',
'meetingID': meetingID
}
webhook_query_string = '&'.join([f"{key}={value}" for key, value in webhook_create_param.items()])
webhook_checksum_string = f"hooks/create{webhook_query_string}{shared_secret}"
webhook_checksum = sha1(webhook_checksum_string.encode()).hexdigest()
webhook_create_param['checksum'] = webhook_checksum
print("webhook_create_param checksum = ", webhook_checksum)
hook_create_url = current_app.config['BIGBLUEBUTTON_PATH'] + 'hooks/create?' + urlencode(webhook_create_param)
print(hook_create_url)
response = requests.get(hook_create_url)
# print("Webhook Response = ", response)
obj = MasterEvents(event_name=data['event_name'], event_desc=data['event_desc'],
classroom_id=int(data['classroom_id']), link=data['link'], demo=data['demo'],
password=data['password'], end_timestamp=data['end_timestamp'],
external_link_check=data['external_link_check'], meetingId=meetingID)
else:
obj = MasterEvents(event_name=data['event_name'], event_desc=data['event_desc'],
classroom_id=int(data['classroom_id']), link=data['link'], demo=data['demo'],
password=data['password'], end_timestamp=data['end_timestamp'],
external_link_check=data['external_link_check'])
db.session.add(obj)
db.session.flush()
for child in data['events']:
if child['start_timestamp'] < time.time() * 1000:
raise JsonApiException(detail="invalid", status=400)
child_obj = ChildEvents(event_id=obj.id, start_timestamp=child['start_timestamp'],
end_delta=child['end_delta'], delta=child['delta'])
db.session.add(child_obj)
db.session.commit()
return jsonify("success"), 200
else:
return jsonify("invalid data"), 400
else:
return jsonify("should be a teacher"), 401
except Exception as e:
print(e)
What I Tried:
- Parameter Construction: I ensured that the parameters for both the meeting creation and the webhook registration were correctly constructed, including the checksum calculations.
- URL Construction: I verified that the URLs were correctly formed and that the requests were properly sent to the BBB server.
- Print Statements: Added print statements to check the URLs and parameters before making the requests.
- Error Handling: Checked for any obvious mistakes in error handling or in the request logic.
Expected Outcome:
The expected outcome is that the webhook should be registered successfully, and the server should return a valid response indicating that the webhook has been created.
Actual Outcome:
I receive an IncompleteRead(0 bytes read) error when attempting to register the webhook.
Could anyone please help me in it.