apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: slack-post-message
  labels:
    dagweave.io/catalog-item: slack-post-message
  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:
          # Slack channel ID or name (e.g. "C0123456789" or "#alerts").
          - name: channel
          # The message text to post.
          - name: message
          # Name of the Kubernetes Secret in the run namespace holding the Slack
          # bot token. Defaults let a user leave them blank in the Inspector.
          - name: token-secret-name
            default: slack-bot-token
          - name: token-secret-key
            default: token
      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 a message containing quotes or shell metacharacters is safe. Slack's
        # Web API accepts form-encoded params, and --data-urlencode escapes them,
        # so no jq / JSON assembly is needed.
        args:
          - |
            set -eu
            curl -sSf -X POST https://slack.com/api/chat.postMessage \
              -H "Authorization: Bearer ${SLACK_TOKEN}" \
              --data-urlencode "channel=${SLACK_CHANNEL}" \
              --data-urlencode "text=${SLACK_MESSAGE}"
        env:
          - name: SLACK_CHANNEL
            value: "{{inputs.parameters.channel}}"
          - name: SLACK_MESSAGE
            value: "{{inputs.parameters.message}}"
          - name: SLACK_TOKEN
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.token-secret-name}}"
                key: "{{inputs.parameters.token-secret-key}}"
