def app_status_change_event_handler(ctx, conf, event): # type: (Context, Config, ApplicationAppStatusChangeEvent) -> None print(ctx.get_request_id()) print(conf.app_settings) print(event.event.type) def user_change(ctx, conf, event): # type: (Context, Config, Dict) -> None print(ctx.get_request_id()) print(conf.app_settings) print(event) set_event_callback(conf, 'app_status_change', app_status_change_event_handler, ApplicationAppStatusChangeEvent) set_event_callback(conf, 'user_update', user_change) @method_decorator(csrf_exempt, name='dispatch') class SampleWebhookEventHandler(View): def post(self, request): # type: (HttpRequest) -> HttpResponse oapi_request = OapiRequest(uri=request.path, body=request.body, header=OapiHeader(request.headers)) oapi_resp = handle_event(conf, oapi_request) resp = HttpResponse(oapi_resp.body, status=oapi_resp.status_code, content_type=oapi_resp.content_type) return resp urlpatterns = [ path('webhook/event', SampleWebhookEventHandler.as_view()),
# for memory store and logger(level=debug) conf = Config(DOMAIN_FEISHU, app_settings, log_level=LEVEL_DEBUG) app = Flask(__name__) def app_open_event_handle(ctx, conf, event): # type: (Context, Config, dict) -> None print(ctx.get_request_id()) print(conf.app_settings) print(event) # set event type 'app_status_change' handle set_event_callback(conf, 'app_open', app_open_event_handle) @app.route('/webhook/event', methods=['POST']) def webhook_event(): oapi_request = OapiRequest(uri=request.path, body=request.data, header=OapiHeader(request.headers)) resp = make_response() oapi_resp = handle_event(conf, oapi_request) resp.headers['Content-Type'] = oapi_resp.content_type resp.data = oapi_resp.body resp.status_code = oapi_resp.status_code return resp