diff options
| -rw-r--r-- | SCHEMA.md | 18 | ||||
| -rw-r--r-- | backend/routes/forms/submit.py | 12 | 
2 files changed, 27 insertions, 3 deletions
| @@ -33,9 +33,21 @@ In this document:  | `WEBHOOK_ENABLED`  | The form should notify the webhook. Has no effect if no webhook is set.       |  ### Meta options -| Field     | Description                                                                                          | Example                                                                                                   | -| --------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | -| `webhook` | Mapping of webhook url and message. Message can use `_USER_MENTION_` to mention the submitting user. | `"webhook": {"url": "https://discord.com/api/webhooks/id/key", "message": "Hello World! _USER_MENTION_"}` | +| Field     | Description                                                                                          | Example                                                                                                | +| --------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | +| `webhook` | Mapping of webhook url and message. Message can use certain [context variables](#webhook-variables). | `"webhook": {"url": "https://discord.com/api/webhooks/id/key", "message": "{user} submitted a form."}` | + + +#### Webhook Variables +The following variables can be used in a webhook's message. The variables must be wrapped by braces (`{}`). + +| Name          | Description                                                                  | +| ------------- | ---------------------------------------------------------------------------- | +| `user`        | A discord mention of the user submitting the form, or "User" if unavailable. | +| `response_id` | ID of the submitted response.                                                | +| `form`        | Name of the submitted form.                                                  | +| `form_id`     | ID of the submitted form.                                                    | +| `time`        | ISO submission timestamp.                                                    |  ### Form question diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index 3b22155..5c0cfdd 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -197,6 +197,18 @@ class SubmitForm(Route):          # Set hook message          message = form.meta.webhook.message          if message: +            # Available variables, see SCHEMA.md +            ctx = { +                "user": mention, +                "response_id": response.id, +                "form": form.name, +                "form_id": form.id, +                "time": response.timestamp, +            } + +            for key in ctx: +                message = message.replace(f"{{{key}}}", str(ctx[key])) +              hook["content"] = message.replace("_USER_MENTION_", mention)          # Post hook | 
