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: truein the command config. - Choose
dispatch-type: repository-dispatchorworkflow-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"