mealie-recipes / mealie

Mealie is a self hosted recipe manager and meal planner with a RestAPI backend and a reactive frontend application built in Vue for a pleasant user experience for the whole family. Easily add recipes into your database by providing the url and mealie will automatically import the relevant data or add a family recipe with the UI editor
https://docs.mealie.io
GNU Affero General Public License v3.0
7.27k stars 726 forks source link

[BUG] - Mealplan webhook payload includes all mealplan items, regardless of date #4050

Closed bennettmsherman closed 3 weeks ago

bennettmsherman commented 2 months ago

First Check

What is the issue you are experiencing?

I spun up n8n to test out Mealie's webhook integration. Ultimately my goal is to send daily emails with the mealplan contents for the day.

The webhook config page in mealie says:

The webhooks defined below will be executed when a meal is defined for the day. At the scheduled time the webhooks will be sent with the data from the recipe that is scheduled for the day.

In practice, I'm seeing mealplan items in the webhook body for the current day, but also past and future.

Steps to Reproduce

Please provide relevant logs

Sample payload when using test button:

[
  {
    "headers": {
      "host": "n8n.mysite.com",
      "user-agent": "python-requests/2.32.3",
      "content-length": "1091",
      "accept": "*/*",
      "accept-encoding": "gzip, deflate",
      "content-type": "application/json",
      "true-client-ip": "172.16.0.90",
      "x-forwarded-for": "172.16.0.90",
      "x-forwarded-host": "n8n.mysite.com",
      "x-forwarded-proto": "https",
      "x-real-ip": "172.16.0.90"
    },
    "params": {},
    "query": {},
    "body": {
      "message": {
        "title": "Webhook Task",
        "body": "Test Webhook"
      },
      "eventType": 2,
      "integrationId": "mealie_generic_user",
      "documentData": {
        "documentType": "mealplan",
        "operation": "info",
        "webhookStartDt": "0001-01-01T00:00:00Z",
        "webhookEndDt": "0001-01-01T00:00:00Z",
        "webhookBody": [
          {
            "date": "2025-01-01",
            "entryType": "dinner",
            "title": "Future test meal",
            "text": "",
            "recipeId": null,
            "id": 3,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          },
          {
            "date": "2024-01-01",
            "entryType": "breakfast",
            "title": "Test meal",
            "text": "For testing webhooks",
            "recipeId": null,
            "id": 2,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          },
          {
            "date": "2024-08-18",
            "entryType": "dinner",
            "title": "Pasta w/ sausage",
            "text": "",
            "recipeId": null,
            "id": 1,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          }
        ]
      },
      "eventId": "0be7e432-9832-4768-ab05-30f2b9551512",
      "timestamp": "2024-08-18T17:22:14.271867Z"
    },
    "webhookUrl": "https://n8n.mysite.com/webhook/...",
    "executionMode": "production"
  }
]

Sample payload from a scheduled run:

[
  {
    "headers": {
      "host": "n8n.mysite.com",
      "user-agent": "python-requests/2.32.3",
      "content-length": "1100",
      "accept": "*/*",
      "accept-encoding": "gzip, deflate",
      "content-type": "application/json",
      "true-client-ip": "172.16.0.90",
      "x-forwarded-for": "172.16.0.90",
      "x-forwarded-host": "n8n.mysite.com",
      "x-forwarded-proto": "https",
      "x-real-ip": "172.16.0.90"
    },
    "params": {},
    "query": {},
    "body": {
      "message": {
        "title": "Webhook Task",
        "body": "generic"
      },
      "eventType": 2,
      "integrationId": "mealie_generic_user",
      "documentData": {
        "documentType": "mealplan",
        "operation": "info",
        "webhookStartDt": "2024-08-18T17:21:25.803532Z",
        "webhookEndDt": "2024-08-18T17:26:25.872743Z",
        "webhookBody": [
          {
            "date": "2025-01-01",
            "entryType": "dinner",
            "title": "Future test meal",
            "text": "",
            "recipeId": null,
            "id": 3,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          },
          {
            "date": "2024-01-01",
            "entryType": "breakfast",
            "title": "Test meal",
            "text": "For testing webhooks",
            "recipeId": null,
            "id": 2,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          },
          {
            "date": "2024-08-18",
            "entryType": "dinner",
            "title": "Pasta w/ sausage",
            "text": "",
            "recipeId": null,
            "id": 1,
            "groupId": "e40f4f8f-5d55-4460-9b32-604c13dd32bc",
            "userId": "26f8118a-c1c2-4b7c-aee3-a4acdeca9d86",
            "recipe": null
          }
        ]
      },
      "eventId": "fe533696-fc8b-4445-9b3b-446810e93243",
      "timestamp": "2024-08-18T17:26:25.927366Z"
    },
    "webhookUrl": "https://n8n.mysite.com/webhook/......",
    "executionMode": "production"
  }
]

Mealie Version

v1.11.0 - a41ad8c6ed968b43e5674ce77785dbdf76f77f57

Deployment

Docker (Linux)

Additional Deployment Details

No response

bennettmsherman commented 2 months ago

This looks to be a documentation issue.

I found a TODO covering this: https://github.com/mealie-recipes/mealie/blob/mealie-next/mealie/services/event_bus_service/event_bus_listeners.py#L145

michael-genson commented 2 months ago

Yup that TODO has been around for a hot minute. Gonna leave this open to track it. Thanks for the report!

bennettmsherman commented 2 months ago

You're welcome, thanks for your work on this project!

While setting this up, two additional customizations that could be useful popped into my head:

These two customizations would allow for the expected use case of "send today's meal plan at ${time}" to work, in addition to a use case like "send a notification for the upcoming week's meals each sunday at 9PM".

michael-genson commented 3 weeks ago

FYI this has been resolved in nightly: https://github.com/mealie-recipes/mealie/pull/4111