apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: discord-post
  labels:
    dagweave.io/catalog-item: discord-post
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.1"
    dagweave.io/catalog-category: "Notifications"
spec:
  entrypoint: post
  templates:
    - name: post
      inputs:
        parameters:
          # The message content to post to the Discord channel.
          - name: content
          # Name/key of the Kubernetes Secret in the run namespace holding the Discord
          # webhook URL. Defaults let a user leave them blank in the Inspector.
          - name: webhook-secret-name
            default: discord-webhook
          - name: webhook-secret-key
            default: url
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # curlimages/curl:8.23.0
        image: curlimages/curl@sha256:3fb7e13e5d179a845c97d78204f3f1064d1907037f26a3ebf91710571151fd93
        command: [sh, -c]
        # Values are passed as env vars (below), never interpolated into the shell,
        # so content containing quotes or shell metacharacters is safe. Discord's
        # Execute Webhook endpoint accepts application/x-www-form-urlencoded, and
        # --data-urlencode escapes the value, so no jq / JSON assembly is needed.
        args:
          - |
            set -eu
            curl -sSf -X POST "$WEBHOOK_URL" \
              --data-urlencode "content=${CONTENT}"
        env:
          - name: CONTENT
            value: "{{inputs.parameters.content}}"
          - name: WEBHOOK_URL
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.webhook-secret-name}}"
                key: "{{inputs.parameters.webhook-secret-key}}"
