diff --git a/.github/workflows/test-slack-send.yml b/.github/workflows/test-slack-send.yml index 2af0490..d8189bf 100644 --- a/.github/workflows/test-slack-send.yml +++ b/.github/workflows/test-slack-send.yml @@ -58,3 +58,15 @@ jobs: Test some characters: & and * and < > \n \r Failed to assign <${{ github.event.repository.html_url }}|SDH #my-issue>. + + - uses: ./slack/send + id: slack-multi-with-double-quotes + with: + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + channel-id: "#observablt-bots" + thread-timestamp: ${{ steps.slack-send.outputs.thread-timestamp || '' }} + message: | + :wave: ! + I have assigned you the following SDH, as to my knowledge you are currently on duty for `area::observability`: + + *`urgency:48h` * diff --git a/slack/send/action.yml b/slack/send/action.yml index 1eb7a1a..ce6d546 100644 --- a/slack/send/action.yml +++ b/slack/send/action.yml @@ -47,6 +47,7 @@ runs: # https://api.slack.com/reference/surfaces/formatting#escaping import os from urllib.parse import unquote + import json if os.environ["MESSAGE"]: message = os.environ.get('MESSAGE', 'No message') @@ -55,11 +56,12 @@ runs: else: raise Exception("message must be set.") - # Escape special characters for GitHub Actions output - message = message.replace('\n', '\\n').replace('\r', '\\r') + print("message={}".format(message)) + sanitizedMessage = json.dumps(message) + print("sanitized message={}".format(sanitizedMessage)) with open(os.environ.get('GITHUB_OUTPUT'), "a") as f: - f.write("message={}".format(message)) + f.write("message={}".format(sanitizedMessage)) - uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0 id: slack_message @@ -71,9 +73,9 @@ runs: unfurl_media: false channel: "${{ inputs.channel-id }}" thread_ts: "${{ inputs.thread-timestamp }}" - text: "${{ steps.prepare.outputs.message }}" + text: ${{ steps.prepare.outputs.message }} blocks: - type: "section" text: type: mrkdwn - text: "${{ steps.prepare.outputs.message }}" + text: ${{ steps.prepare.outputs.message }}