@@ -13,21 +13,37 @@ inputs:
1313 text :
1414 description : " The message text to post"
1515 required : true
16+ unfurl_links :
17+ description : " Whether links in the message should be unfurled"
18+ type : boolean
19+ default : true
1620outputs :
1721 ts :
1822 description : " The timestamp ID of the message that was just posted"
23+ value : ${{steps.slack-post-message.outputs.ts}}
1924branding :
2025 icon : ' tag'
2126 color : ' blue'
2227runs :
2328 using : ' composite'
2429 steps :
25- - run : |
26- {
27- echo "ts=<<EOF"
28- curl --silent --show-error -X POST -H "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" -H "Content-Type: application/json; charset=utf-8" --url https://slack.com/api/chat.postMessage \
29- -d "{\"channel\": \"${{ inputs.channel }}\", \"thread_ts\":\"${{ inputs.thread_ts }}\", \"text\":\"${{ inputs.text }}\"}" \
30- | jq --raw-output '.ts'
31- echo "EOF"
32- } >> "$GITHUB_OUTPUT"
30+ - name : Validate required inputs
3331 shell : bash
32+ run : |
33+ [[ "${{ inputs.channel }}" ]] || { echo "required input 'channel' not specified" ; exit 1; }
34+ [[ "${{ inputs.text }}" ]] || { echo "required input 'text' not specified" ; exit 1; }
35+ - name : POST to chat.postMessage API
36+ id : slack-post-message
37+ shell : bash
38+ run : |
39+ response=$(curl --fail-with-body --silent --show-error \
40+ --request POST \
41+ --header "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" \
42+ --header "Content-Type: application/json; charset=utf-8" \
43+ --url https://slack.com/api/chat.postMessage \
44+ --data '{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \
45+ )
46+ echo "Slack message API response:\n$response"
47+ ts=$(echo "$response" | jq --raw-output '.ts')
48+ echo "Setting ts output to $ts"
49+ echo "ts=$ts" >> $GITHUB_OUTPUT
0 commit comments