Hi,
Webhook is not working in the sense that nothing hits my endpoint when an SMS comes in, but when i subscribe, it does send the validation token (so I know the end point is reachable). It was working perfectly fine and then just stopped, I have deleted the subscription and resubscribed.
Any help would be appreciated!
Endpoint:
@app.route('/webhook/ringcentral', methods=['POST']) def ringcentral_webhook(): try: validation_token = request.headers.get('Validation-Token') if validation_token: return make_response('', 200, {'Validation-Token': validation_token}) data = request.get_json(silent=True) logging.info(data) if data: sender = data.get('body', {}).get('from', {}) phone_number = sender.get('phoneNumber', 'Unknown Number') sender_name = sender.get('name', {phone_number}) message_subject = data.get('body', {}).get('subject', 'No subject') text = f"New SMS from: {sender_name}. Message: {message_subject}." slack.slack_sender(text) logging.info(data) return jsonify({'status': 'success'}), 200 else: logging.info("No JSON payload received.") return jsonify({'status': 'error', 'message': 'No JSON payload'}), 400 except Exception as e: logging.error(f"Error processing the webhook data: {e}") return jsonify({'status': 'error', 'message': str(e)}), 500
the subscribe code: def clear_webhook_subscriptions(func): def wrapper(self, *args, **kwargs): self.read_subscriptions() return func(self, *args, **kwargs) return wrapper @clear_webhook_subscriptions def subscribe_for_notification(self, event_filters=['/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS'], delivery_address = 'REDACTED'): try: body_params = { 'eventFilters': event_filters, 'deliveryMode': { 'transportType': 'WebHook', 'address': delivery_address + '/webhook/ringcentral' }, 'expiresIn': 604800 #TODO:Rework this. can be upto 10 yrs. 315360000 } endpoint = "/restapi/v1.0/subscription" resp = self.post(endpoint, json=body_params) resp.raise_for_status() response = resp.json() logging.info(f"Subscription ID: {response['id']}") logging.info("Ready to receive incoming SMS via WebHook.") return response except HTTPError as http_err: logging.error(f"HTTP error occurred: {http_err}") except Exception as err: logging.error(f"An exception occurred: {err}") def read_subscriptions(self): try: endpoint = "/restapi/v1.0/subscription" resp = self.get(endpoint) response = resp.json() if not response['records']: logging.info("No subscription found.") else: for record in response['records']: logging.info(json.dumps(record, indent=2, sort_keys=True)) self.delete_subscription(record['id']) except Exception as e: logging.error(f"An exception occurred while reading subscriptions: {e}") def delete_subscription(self, subscription_id): try: endpoint = f"/restapi/v1.0/subscription/{subscription_id}" self.delete(endpoint) logging.info(f"Subscription {subscription_id} deleted.") except Exception as e: logging.error(f"An exception occurred while deleting subscription {subscription_id}: {e}")