-
Notifications
You must be signed in to change notification settings - Fork 154
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
Feature Request: Get Slack Username from Email #349
Comments
Hey @thejeff77 👋🏻 Thanks for the posting the question - it's a pretty common use-case to try to look up a user based on their email address and totally makes sense that you'd need to do this from our GitHub Action. Since you've done this in Jenkins, I imagine you're already aware of the Slack API method users.lookupByEmail? We don't have a slick way of calling this method from the GitHub Action, but we're playing around with a few ideas for you. Hopefully, together we can find a solution for you until |
@thejeff77 adding to the suggestion of using the - name: Find the Slackbot user ID
run: |
curl -X POST -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \
-H "Content-type: application/json" \
--data '{"email":"slackbot@example.com"}' \
https://slack.com/api/users.lookupByEmail Although making use of the response might require a bit of As @mwbrooks mentioned, we're chipping away at We'll check that this method works well in these updates and will continue to share updates with changes for that version! |
@zimeg looking forward to it! |
@thejeff77 👋 the latest name: Messages
on: push
jobs:
messenger:
name: Send a direct message
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Get the author
run: |
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae')
echo "Author email is: $AUTHOR_EMAIL"
echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV
- name: Lookup by email
id: email
uses: slackapi/slack-github-action@v2.0.0
with:
errors: true
method: users.lookupByEmail
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
email: "${{ env.AUTHOR_EMAIL }}"
- name: Find the user ID
if: ${{ steps.email.outputs.ok }}
run: |
SLACK_USER_ID=$(echo '${{ steps.email.outputs.response }}' | jq -r '.user.id')
echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV
- name: Send a message
if: ${{ steps.email.outputs.ok }}
uses: slackapi/slack-github-action@v2.0.0
with:
errors: true
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ env.SLACK_USER_ID }}
text: "hello again." The following scopes will have to be added to the token too: AFAIK Please also let me know if these steps are working alright! I kinda want to keep this issue open for a bit as a reminder to soon document the |
@zimeg thanks! This is a game changer, can't wait to give this a thorough try. |
👋 This is now included as an example here. Please feel free to suggest changes or share other questions whenever! 📚 ✨ |
Description
I was able to do this in Jenkins, and looking for a way to do it in GHA. I need a way to lookup a slack user's username via their email.
Github actions give context on the committer via email, but obv github doesn't provide slack user data. In order to tag a user directly, being able to lookup the user's slack id so you can tag them or message them directly would be incredibly valuable.
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
package version:
node version:
OS version(s):
Steps to reproduce:
Expected result:
What you expected to happen
Actual result:
What actually happened
Attachments:
Logs, screenshots, screencast, sample project, funny gif, etc.
The text was updated successfully, but these errors were encountered: