Skip to content
Latchkey

How to Use Dispatch Types and Named Args in slash-command-dispatch

slash-command-dispatch parses positional and named arguments and puts them under client_payload.slash_command for the handler to read.

Define per-command config with named-args: true so /deploy env=staging yields client_payload.slash_command.named.env. Use dispatch-type to choose repository_dispatch or workflow_dispatch.

Steps

  • Set named-args: true in the command config.
  • Choose dispatch-type: repository-dispatch or workflow-dispatch.
  • Read args from client_payload.slash_command.named.

Command config

.github/workflows/ci.yml
- uses: peter-evans/slash-command-dispatch@v4
  with:
    token: ${{ secrets.PAT }}
    config: >
      [{
        "command": "deploy",
        "permission": "write",
        "dispatch-type": "repository-dispatch",
        "named-args": true
      }]

Reading the args

.github/workflows/deploy-command.yml
# in the handler workflow
ENV="${{ github.event.client_payload.slash_command.named.env }}"
ARG1="${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}"
echo "Deploying to $ENV"

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →