diff --git a/memos_webhook/app.py b/memos_webhook/app.py index 320ae68..d6130a4 100644 --- a/memos_webhook/app.py +++ b/memos_webhook/app.py @@ -77,7 +77,6 @@ async def webhook_handler( """The new webhook handler, use protojson.""" dict_json = await req.json() logger.debug(f"webhook handler received request: {dict_json}") - logger.debug(f"type: {type(dict_json)}") proto_payload = v1.WebhookRequestPayload().from_dict(dict_json) background_tasks.add_task(webhook_task, proto_payload, executor) diff --git a/memos_webhook/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py index b82bedb..4bd22d9 100644 --- a/memos_webhook/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -14,12 +14,15 @@ class PluginProtocol(Protocol): """The protocol that plugin executor trully need a plugin to implement. - + You should implement `BasePlugin` instead of this protocol. Unless you know what you are doing.""" + def positive_tag(self) -> str: ... def negative_tag(self) -> str: ... - async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo: ... + async def task( + self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli + ) -> v1.Memo: ... def should_trigger(self, payload: v1.WebhookRequestPayload) -> bool: ... @@ -60,7 +63,9 @@ def tag(self) -> str: ... @abstractmethod - async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo: + async def task( + self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli + ) -> v1.Memo: """The webhook task function. Return the modified memo, and the plugin will auto update the memo with modified content and negative tag. @@ -138,9 +143,7 @@ async def update_memo_content( Once the task triggered, will replace the `#tag` with `#tag/done`. If the `#tag` not exists, will add the `#tag/done` to first line. """ - self.logger.debug( - f"Background task started with param: {payload.to_json()}" - ) + self.logger.debug(f"Background task started with param: {payload.to_json()}") res_memo = await plugin.task(payload, self.memos_cli) self.logger.info("Background task success completed") @@ -169,5 +172,6 @@ async def execute(self, payload: v1.WebhookRequestPayload) -> None: continue await self.update_memo_content(plugin, payload) + return # only execute one plugin self.logger.info("All plugins executed") diff --git a/memos_webhook/plugins/you_get_plugin.py b/memos_webhook/plugins/you_get_plugin.py index 5bb8ff0..9f6bf1b 100644 --- a/memos_webhook/plugins/you_get_plugin.py +++ b/memos_webhook/plugins/you_get_plugin.py @@ -49,7 +49,9 @@ def additional_trigger(self, payload: v1.WebhookRequestPayload) -> bool: return False @override - async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo: + async def task( + self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli + ) -> v1.Memo: memo_name = payload.memo.name self.logger.info(f"Start {self.cfg.name} webhook task for memo: {memo_name}") @@ -66,7 +68,7 @@ async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> urls = extract_urls(payload.memo.content, self.patterns) if not urls: self.logger.info("No urls found") - return + return payload.memo self.logger.info(f"Extracted urls: {urls}") # mkdir @@ -124,7 +126,4 @@ async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> ) self.logger.info(f"Set memo resources: {[res.name for res in all_resources]}") - return v1.Memo( - name=memo_name, - content=payload.memo.content, - ) + return payload.memo # you-get plugin do not modify memo content