apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: microsoft-teams-post
  labels:
    dagweave.io/catalog-item: microsoft-teams-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.0"
    dagweave.io/catalog-category: "Notifications"
spec:
  entrypoint: post
  templates:
    - name: post
      inputs:
        parameters:
          # The message text to post to the Teams channel.
          - name: message
          # Name/key of the Kubernetes Secret in the run namespace holding the Teams
          # incoming-webhook URL. Defaults let a user leave them blank in the Inspector.
          - name: webhook-secret-name
            default: teams-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.
        # python:3.15-alpine — a Teams incoming webhook expects a JSON body, so the
        # payload is built with json.dumps (which correctly escapes any quotes,
        # newlines or control characters in the message) rather than shell string
        # assembly. urllib performs the POST, so no extra image is needed.
        image: python@sha256:20a82dbc2783112ddb91d1534603f802d222a3e63e593cd002eb2ac534e70211
        command: [python3, -c]
        # Values arrive as env vars (below), never interpolated into the program
        # source, so a message with any content is safe.
        args:
          - |
            import json, os, urllib.request
            payload = json.dumps({"text": os.environ["MESSAGE"]}).encode("utf-8")
            req = urllib.request.Request(
                os.environ["WEBHOOK_URL"],
                data=payload,
                headers={"Content-Type": "application/json"},
                method="POST",
            )
            with urllib.request.urlopen(req) as resp:
                print("Teams webhook responded:", resp.status)
        env:
          - name: MESSAGE
            value: "{{inputs.parameters.message}}"
          - name: WEBHOOK_URL
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.webhook-secret-name}}"
                key: "{{inputs.parameters.webhook-secret-key}}"
