feat(config): update n8n webhook handling #366

Merged
luke merged 1 commits from bugfix/post-get-urls into main 2025-08-04 09:59:54 +02:00
Owner

Okay, I will explain the code changes presented in the diff. The primary focus of this pull request appears to be refactoring the N8N webhook URL configuration to use separate URLs for GET and POST requests. Additionally, several files in the .github directory have been moved to an .archive/.github directory.

1. Directory Changes:

  • A number of files related to GitHub configuration (CODEOWNERS, issue templates, dependabot configuration, renovate configuration, and workflow files) have been moved from the .github directory to .archive/.github. This suggests that these configurations are no longer actively used or are being superseded by other configurations.

2. Environment Variable Changes (.env.default):

--- a/.env.default
+++ b/.env.default
@@ -5,5 +5,6 @@
  APPROVED_DOMAINS="example.com,hello.com"
  APPROVED_ROOMS="abc123,def456"
  APPROVED_USERS="bob@example.com,john@me.com"
  BOT_NAME=""
 -N8N_WEBHOOK_URL=""
 +N8N_GET_WEBHOOK_URL=""
 +N8N_POST_WEBHOOK_URL=""
  WEBEX_API_KEY=""
  • The .env.default file, which provides default values for environment variables, has been modified.
  • The single N8N_WEBHOOK_URL environment variable has been removed.
  • Two new environment variables, N8N_GET_WEBHOOK_URL and N8N_POST_WEBHOOK_URL, have been added. This indicates the application now requires separate webhook URLs for GET and POST requests to the N8N service.

3. Configuration Class Changes (app/utils/config.py):

--- a/app/utils/config.py
+++ b/app/utils/config.py
@@ -42,9 +42,14 @@ class Config:
          return os.environ["ADMIN_EMAIL"].split(",")
  
      @property
-    def n8n_webhook_url(self) -> str:
-        """Returns the n8n webhook URL."""
-        return os.environ["N8N_WEBHOOK_URL"]
+    def n8n_get_webhook_url(self) -> str:
+        """Returns the n8n GET webhook URL."""
+        return os.environ["N8N_GET_WEBHOOK_URL"]
+
+    @property
+    def n8n_post_webhook_url(self) -> str:
+        """Returns the n8n POST webhook URL."""
+        return os.environ["N8N_POST_WEBHOOK_URL"]
  
      @property
      def approved_users(self) -> list:
  • The Config class in app/utils/config.py has been updated to reflect the environment variable changes.
  • The n8n_webhook_url property has been removed.
  • Two new properties, n8n_get_webhook_url and n8n_post_webhook_url, have been added. These properties retrieve the corresponding environment variables and provide access to the individual webhook URLs.

4. N8N Utility Changes (app/utils/n8n.py):

--- a/app/utils/n8n.py
+++ b/app/utils/n8n.py
@@ -16,7 +16,7 @@ def __n8n_post(data: dict) -> bool:
      """
      headers: dict = {"Content-Type": "application/json"}
      resp: requests.Response = requests.post(
-        url=config.n8n_webhook_url,
+        url=config.n8n_post_webhook_url,
          headers=headers,
          json=data,
          timeout=10,
@@ -58,7 +58,7 @@ def get_tasks(requestor) -> bool:
      """
      headers: dict = {"Content-Type": "application/json"}
      resp: requests.Response = requests.get(
-        url=config.n8n_webhook_url,
+        url=config.n8n_get_webhook_url,
          headers=headers,
          timeout=10,
          verify=True,
  • The app/utils/n8n.py file has been modified to use the new configuration properties.
  • In the __n8n_post function, the url parameter in the requests.post call now uses config.n8n_post_webhook_url instead of the old config.n8n_webhook_url.
  • Similarly, in the get_tasks function, the url parameter in the requests.get call now uses config.n8n_get_webhook_url.

5. Test Changes (tests/test_config_1.py and tests/test_config_2.py):

--- a/tests/test_config_1.py
+++ b/tests/test_config_1.py
@@ -16,7 +16,8 @@ def test_config() -> None:
          "WEBEX_API_KEY": "testing",
          "ADMIN_FIRST_NAME": "Test",
          "ADMIN_EMAIL": "test@test.com",
-        "N8N_WEBHOOK_URL": "https://n8n.test.com/webhook/abcdefg",
+        "N8N_GET_WEBHOOK_URL": "https://n8n.test.com/webhook/abc",
+        "N8N_POST_WEBHOOK_URL": "https://n8n.test.com/webhook/def",
          "APPROVED_USERS": "test@test.com",
          "APPROVED_DOMAINS": "test.com",
          "APPROVED_ROOMS": "test",
@@ -34,7 +35,8 @@ def test_config() -> None:
      assert config.approved_rooms == config_vars["APPROVED_ROOMS"].split(",")
      assert config.approved_users == config_vars["APPROVED_USERS"].split(",")
      assert config.bot_name == config_vars["BOT_NAME"]
-    assert config.n8n_webhook_url == config_vars["N8N_WEBHOOK_URL"]
+    assert config.n8n_get_webhook_url == config_vars["N8N_GET_WEBHOOK_URL"]
+    assert config.n8n_post_webhook_url == config_vars["N8N_POST_WEBHOOK_URL"]
      assert config.version == config_vars["APP_VERSION"]
      assert config.webex_token == config_vars["WEBEX_API_KEY"]
  • The test files have been updated to use the new environment variables and configuration properties. The old N8N_WEBHOOK_URL is removed and N8N_GET_WEBHOOK_URL and N8N_POST_WEBHOOK_URL are added and asserted.

Summary:

This pull request introduces a separation of N8N webhook URLs for GET and POST requests. This likely allows for more specific control and potentially different workflows depending on the HTTP method used to interact with the N8N service. The .github directory changes suggest cleaning up the repository by archiving old or unused configuration files. The tests are updated to align with the new configuration structure.

Okay, I will explain the code changes presented in the diff. The primary focus of this pull request appears to be refactoring the N8N webhook URL configuration to use separate URLs for GET and POST requests. Additionally, several files in the `.github` directory have been moved to an `.archive/.github` directory. **1. Directory Changes:** * A number of files related to GitHub configuration (CODEOWNERS, issue templates, dependabot configuration, renovate configuration, and workflow files) have been moved from the `.github` directory to `.archive/.github`. This suggests that these configurations are no longer actively used or are being superseded by other configurations. **2. Environment Variable Changes (.env.default):** ```diff --- a/.env.default +++ b/.env.default @@ -5,5 +5,6 @@ APPROVED_DOMAINS="example.com,hello.com" APPROVED_ROOMS="abc123,def456" APPROVED_USERS="bob@example.com,john@me.com" BOT_NAME="" -N8N_WEBHOOK_URL="" +N8N_GET_WEBHOOK_URL="" +N8N_POST_WEBHOOK_URL="" WEBEX_API_KEY="" ``` * The `.env.default` file, which provides default values for environment variables, has been modified. * The single `N8N_WEBHOOK_URL` environment variable has been removed. * Two new environment variables, `N8N_GET_WEBHOOK_URL` and `N8N_POST_WEBHOOK_URL`, have been added. This indicates the application now requires separate webhook URLs for GET and POST requests to the N8N service. **3. Configuration Class Changes (app/utils/config.py):** ```diff --- a/app/utils/config.py +++ b/app/utils/config.py @@ -42,9 +42,14 @@ class Config: return os.environ["ADMIN_EMAIL"].split(",") @property - def n8n_webhook_url(self) -> str: - """Returns the n8n webhook URL.""" - return os.environ["N8N_WEBHOOK_URL"] + def n8n_get_webhook_url(self) -> str: + """Returns the n8n GET webhook URL.""" + return os.environ["N8N_GET_WEBHOOK_URL"] + + @property + def n8n_post_webhook_url(self) -> str: + """Returns the n8n POST webhook URL.""" + return os.environ["N8N_POST_WEBHOOK_URL"] @property def approved_users(self) -> list: ``` * The `Config` class in `app/utils/config.py` has been updated to reflect the environment variable changes. * The `n8n_webhook_url` property has been removed. * Two new properties, `n8n_get_webhook_url` and `n8n_post_webhook_url`, have been added. These properties retrieve the corresponding environment variables and provide access to the individual webhook URLs. **4. N8N Utility Changes (app/utils/n8n.py):** ```diff --- a/app/utils/n8n.py +++ b/app/utils/n8n.py @@ -16,7 +16,7 @@ def __n8n_post(data: dict) -> bool: """ headers: dict = {"Content-Type": "application/json"} resp: requests.Response = requests.post( - url=config.n8n_webhook_url, + url=config.n8n_post_webhook_url, headers=headers, json=data, timeout=10, @@ -58,7 +58,7 @@ def get_tasks(requestor) -> bool: """ headers: dict = {"Content-Type": "application/json"} resp: requests.Response = requests.get( - url=config.n8n_webhook_url, + url=config.n8n_get_webhook_url, headers=headers, timeout=10, verify=True, ``` * The `app/utils/n8n.py` file has been modified to use the new configuration properties. * In the `__n8n_post` function, the `url` parameter in the `requests.post` call now uses `config.n8n_post_webhook_url` instead of the old `config.n8n_webhook_url`. * Similarly, in the `get_tasks` function, the `url` parameter in the `requests.get` call now uses `config.n8n_get_webhook_url`. **5. Test Changes (tests/test\_config\_1.py and tests/test\_config\_2.py):** ```diff --- a/tests/test_config_1.py +++ b/tests/test_config_1.py @@ -16,7 +16,8 @@ def test_config() -> None: "WEBEX_API_KEY": "testing", "ADMIN_FIRST_NAME": "Test", "ADMIN_EMAIL": "test@test.com", - "N8N_WEBHOOK_URL": "https://n8n.test.com/webhook/abcdefg", + "N8N_GET_WEBHOOK_URL": "https://n8n.test.com/webhook/abc", + "N8N_POST_WEBHOOK_URL": "https://n8n.test.com/webhook/def", "APPROVED_USERS": "test@test.com", "APPROVED_DOMAINS": "test.com", "APPROVED_ROOMS": "test", @@ -34,7 +35,8 @@ def test_config() -> None: assert config.approved_rooms == config_vars["APPROVED_ROOMS"].split(",") assert config.approved_users == config_vars["APPROVED_USERS"].split(",") assert config.bot_name == config_vars["BOT_NAME"] - assert config.n8n_webhook_url == config_vars["N8N_WEBHOOK_URL"] + assert config.n8n_get_webhook_url == config_vars["N8N_GET_WEBHOOK_URL"] + assert config.n8n_post_webhook_url == config_vars["N8N_POST_WEBHOOK_URL"] assert config.version == config_vars["APP_VERSION"] assert config.webex_token == config_vars["WEBEX_API_KEY"] ``` * The test files have been updated to use the new environment variables and configuration properties. The old `N8N_WEBHOOK_URL` is removed and `N8N_GET_WEBHOOK_URL` and `N8N_POST_WEBHOOK_URL` are added and asserted. **Summary:** This pull request introduces a separation of N8N webhook URLs for GET and POST requests. This likely allows for more specific control and potentially different workflows depending on the HTTP method used to interact with the N8N service. The `.github` directory changes suggest cleaning up the repository by archiving old or unused configuration files. The tests are updated to align with the new configuration structure.
luke added 1 commit 2025-08-04 09:54:36 +02:00
feat: update n8n webhook handling
All checks were successful
Validate PR Title / validate (pull_request) Successful in 4s
CI / ci (pull_request) Successful in 1m9s
1052b47625
Member

Decision: Accept
Change Score: 9/10

The changes refactor the N8N webhook URL configuration to use separate URLs for GET and POST requests, improving flexibility. The old github files are being archived.

However, ensure that the N8N workflows are correctly configured to handle requests on both GET and POST endpoints. Also ensure there are no other areas in the code that still use the old N8N_WEBHOOK_URL parameter. If there are, these need to be migrated.

No changes necessary.

**Decision: Accept** **Change Score: 9/10** The changes refactor the N8N webhook URL configuration to use separate URLs for GET and POST requests, improving flexibility. The old github files are being archived. However, ensure that the N8N workflows are correctly configured to handle requests on both GET and POST endpoints. Also ensure there are no other areas in the code that still use the old `N8N_WEBHOOK_URL` parameter. If there are, these need to be migrated. No changes necessary.
luke changed title from feat: update n8n webhook handling to feat(config): update n8n webhook handling 2025-08-04 09:58:26 +02:00
luke merged commit d5a366c4f2 into main 2025-08-04 09:59:54 +02:00
luke deleted branch bugfix/post-get-urls 2025-08-04 09:59:54 +02:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: repos/roboluke#366
No description provided.