Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to update messages #75

Closed
4 of 10 tasks
AngellusMortis opened this issue Mar 18, 2022 · 9 comments
Closed
4 of 10 tasks

Add support to update messages #75

AngellusMortis opened this issue Mar 18, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@AngellusMortis
Copy link

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

It would be great to add support for the chat.update endpoint. Idea came from trying to make better GHA deploy messages.

Something like:

- id: slack
  uses: slackapi/[email protected]
  with:
    channel-id: "#channel"
    payload: |
      {
        "attachments": [
          {
            "pretext": "Deployment started",
            "color": "dbab09",
            "fields": [
              {
                "title": "Status",
                "short": true,
                "value": "In Progress"
              }
            ]
          }
        ]
      }
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN}}
- uses: slackapi/[email protected]
  with:
    channel-id: "#channel"
    time: ${{ steps.slack.outputs.time }}
    payload: |
      {
        "attachments": [
          {
            "pretext": "Deployment finished",
            "color": "28a745",
            "fields": [
              {
                "title": "Status",
                "short": true,
                "value": "Completed"
              }
            ]
          }
        ]
      }
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN}}
@seratch seratch added the enhancement New feature or request label Mar 20, 2022
@seratch seratch added this to the 1.x milestone Mar 20, 2022
@stevengill
Copy link
Member

@AngellusMortis we just added support for threading in follow up steps with version v1.19.0. Would that be sufficient for you vs chat.update? See https://github.com/slackapi/slack-github-action/blob/main/.github/workflows/main.yml#L35-L46

@AngellusMortis
Copy link
Author

Not really. Posting in a thread kind of works, but if you have seen how the Github notifications works (updates the OP in real time as things change), they really are superior.

We are just using raw curl requests right now, so we have a viable workaround.

@NicolasTobias
Copy link

Me neither, would be nice to have that specifically option

@seratch seratch modified the milestones: 1.x, 1.20 Jul 25, 2022
stevengill pushed a commit that referenced this issue Jul 27, 2022
* Add support to update messages #75

* fix lint & test

* update README

* update README
@magnattic
Copy link

magnattic commented Jul 27, 2022

I just found this update option in the README and was trying it out, but it doesn't work for me:

Warning: Unexpected input(s) 'update-ts', valid inputs are ['channel-id', 'slack-message', 'payload', 'payload-file-path']
Run slackapi/[email protected]
  with:
    channel-id: U02D1JY1Y1Z
    update-ts: 165896170.317839
    slack-message: Hey magnattic, your PR for branch `XYZ` was just merged to master! 🎉🎉🎉

Error: Error: An API error occurred: message_not_found

Any idea what I might be doing wrong? I pretty much followed the example. The channel id is my user id in slack.

            - name: Send slack start message
              id: slack
              if: env.slackUserId != ''
              uses: slackapi/[email protected]
              with:
                  channel-id: ${{env.slackUserId}}
                  slack-message: |
                      Hey ${{ github.actor }}, your PR for branch `${{github.head_ref}}` is now being checked!
              env:
                  SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
[...]
            - name: Send slack success message
              if: env.slackUserId != ''
              uses: slackapi/[email protected]
              with:
                  channel-id: ${{env.slackUserId}}
                  update-ts: ${{ steps.slack.outputs.ts }}
                  slack-message: |
                      Hey ${{ github.actor }}, your PR for branch `${{github.head_ref}}` was just merged to master! 🎉🎉🎉
              env:
                  SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

@stevengill
Copy link
Member

@magnattic just pushed up v1.21.0 to fix this. Let me know if it works

@magnattic
Copy link

magnattic commented Jul 28, 2022

@stevengill Thanks for the quick response!
Unfortunately, I still get this error:

Error: Error: An API error occurred: message_not_found

Does updating maybe not work in slack when sending messages directly to a user?

EDIT: Just tried to send the messages to a channel instead, there it works flawlessly. It seems to be a problem when sending messages directly to a userId

@seratch
Copy link
Member

seratch commented Jul 29, 2022

@magnattic Yeah, you can use user_id for chat.postMessage but unfortunately user_id is not supported in chat.update (sorry for the confusing difference here!).

@seratch
Copy link
Member

seratch commented Jul 29, 2022

Now that the message updating feature is available, let me close this issue. Thanks again @kuboon for your great contribution!

@seratch seratch closed this as completed Jul 29, 2022
@magnattic
Copy link

I see, would be cool to mention in the docs. Anyway, great job adding this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants