slack-github-action icon indicating copy to clipboard operation
slack-github-action copied to clipboard

Feature request: send direct message to a user

Open ndeloof opened this issue 3 years ago • 4 comments

Description

slackapi/slack-github-action can be used to send a message to a channel, but not to send message to a user by it's handle (@ndeloof)

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

  • [X] enhancement (feature request)

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

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

Bug Report

Reproducible in:

package version: v1.16.0

node version: ?

OS version(s): github's ubuntu-latest hosted runner

Steps to reproduce:

  1. create github workflow to send notification to a specific user
      - name: Notify 
        uses: slackapi/[email protected]
        with:
          channel-id: '@ndeloof'          
          slack-message: '🦄'
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

Expected result:

Can send message to user (maybe using a distinct action parameter)

Actual result:

UnhandledPromiseRejectionWarning: Error: An API error occurred: channel_not_found

Attachments:

ndeloof avatar Dec 09 '21 10:12 ndeloof

Hi @ndeloof! Thank you for writing in with this suggestion, and for trying out our git action!

I think this sounds like a good enhancement and have triaged it initially as such. I will defer to other maintainers to give feedback on implementation considerations and prioritization in our milestones.

srajiang avatar Dec 09 '21 19:12 srajiang

Hey @ndeloof!

Under the hood, we use the chat.postMessage api to send messages into Slack. This API only supports userIDs, not usernames. See https://api.slack.com/methods/chat.postMessage#channels. Usernames can be changed in the client. So we don't recommend using these (the same goes for channel names). That is why our recommendation is to use the IDs instead.

stevengill avatar Dec 13 '21 20:12 stevengill

@stevengill - 👋 Reviewing this a bit more. Below are the current usage instructions on the README, which do seem to suggest that the desired behavior is possible (i.e. "name to post message"). So perhaps this documentation can be updated if we don't recommend usernames, but rather user_id

- name: Post to a Slack channel
  id: slack
  uses: slackapi/[email protected]
  with:
    channel-id: 'CHANNEL_ID'  # Slack channel id or name to post message. https://api.slack.com/methods/chat.postMessage#channels
    slack-message: 'posting from a github action!'
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

You should be able to use USER_ID here @ndeloof! See below:

- name: Post to a Slack channel
  id: slack
  uses: slackapi/[email protected]
  with:
    channel-id: 'USER_ID'
    slack-message: 'posting from a github action!'
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

Let us know if this solves your issue, if so feel free to close it out!

srajiang avatar Dec 13 '21 21:12 srajiang

Submitted a modified feature request to support more clarified naming on fields: #41

srajiang avatar Dec 13 '21 21:12 srajiang

Any mechanism available (or easily added) to allow the user to to provide the Slack users email address and have the userID returned?

larryebaum avatar Mar 07 '23 16:03 larryebaum

@larryebaum-nz take a look into scribd/find-slack-user-action

iamstarkov avatar Nov 21 '23 15:11 iamstarkov