def received_text_messages_callback(service_id): if not current_service.has_permission("inbound_sms"): return redirect(url_for(".api_integration", service_id=service_id)) received_text_messages_callback = get_received_text_messages_callback() form = ServiceReceiveMessagesCallbackForm( url=received_text_messages_callback.get("url") if received_text_messages_callback else "", bearer_token=dummy_bearer_token if received_text_messages_callback else "", ) if form.validate_on_submit(): if received_text_messages_callback and form.url.data: if received_text_messages_callback.get( "url" ) != form.url.data or form.bearer_token.data != dummy_bearer_token: service_api_client.update_service_inbound_api( service_id, url=form.url.data, bearer_token=check_token_against_dummy_bearer( form.bearer_token.data), user_id=current_user.id, inbound_api_id=received_text_messages_callback.get("id"), ) elif received_text_messages_callback and not form.url.data: service_api_client.delete_service_inbound_api( service_id, received_text_messages_callback["id"], ) elif form.url.data: service_api_client.create_service_inbound_api( service_id, url=form.url.data, bearer_token=form.bearer_token.data, user_id=current_user.id, ) return redirect(url_for(".api_callbacks", service_id=service_id)) return render_template( "views/api/callbacks/received-text-messages-callback.html", form=form, )
def received_text_messages_callback(service_id): if not current_service.has_permission('inbound_sms'): return redirect(url_for('.api_integration', service_id=service_id)) received_text_messages_callback = get_received_text_messages_callback() form = ServiceReceiveMessagesCallbackForm( url=received_text_messages_callback.get('url') if received_text_messages_callback else '', bearer_token=dummy_bearer_token if received_text_messages_callback else '' ) if form.validate_on_submit(): if received_text_messages_callback and form.url.data: if ( received_text_messages_callback.get('url') != form.url.data or form.bearer_token.data != dummy_bearer_token ): service_api_client.update_service_inbound_api( service_id, url=form.url.data, bearer_token=check_token_against_dummy_bearer(form.bearer_token.data), user_id=current_user.id, inbound_api_id=received_text_messages_callback.get('id') ) elif received_text_messages_callback and not form.url.data: service_api_client.delete_service_inbound_api( service_id, received_text_messages_callback['id'], ) elif form.url.data: service_api_client.create_service_inbound_api( service_id, url=form.url.data, bearer_token=form.bearer_token.data, user_id=current_user.id ) return redirect(url_for('.api_callbacks', service_id=service_id)) return render_template( 'views/api/callbacks/received-text-messages-callback.html', form=form, )