JackoPlane / action-slack-lookupByEmail

GitHub Action to lookup a slack user by their email address

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub Action - Lookup Slack user by email

action slack lookupByEmail status

This action can be used to find a Slack user by their email address. In the event of a match, it will return a User hash object for the registered Slack user.

The profile hash contains as much information as the user has supplied in the default profile fields: display_name, avatar, real_name, etc.

If you're using this action to lookup a user to send a direct message to using the chat.postMessage API or Slack's Send Action, the id field is most useful.

Authentication

This action requires the users:read.email scope on either a Bot Token or User Token to make authenticated calls to the Slack API.

There is more information on Slack's lookupByEmail API here: https://api.slack.com/methods/users.lookupByEmail

Usage

email is the only required action input parameter.

Like described in Slack's Send Action, the authentication token should be added as a secret in your repo settings named SLACK_BOT_TOKEN. It is passed in using env.

- name: Lookup Slack user
  id: slack-user
  uses: danielbowden/action-slack-lookupByEmail@v1
  with:
    email: 'daniel@email.com'
  env:
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

You can also dynamically pass in email from the output result of a previous step. eg.

- name: Lookup Slack user
  id: slack-user
  uses: danielbowden/action-slack-lookupByEmail@v1
  with:
    email: ${{ steps.commit-author.outputs.result }}

You can access the user hash object result in follow up steps.

steps.slack-user.outputs.user

or specific fields

${{ fromJSON(steps.slack-user.outputs.user).id }}

Development

Install the dependencies

npm install

Run tests

$ npm test

 PASS  ./index.test.js
  lookupUser
    ✓ should set an error if no token is provided (1 ms)
    ✓ should handle success query email using lookupByEmail API (2 ms)
    ✓ should handle fail query email using lookupByEmail API with unknown email (3 ms)

  Test Suites: 1 passed, 1 total
  Tests:       3 passed, 3 total
  Snapshots:   0 total
  Time:        0.268 s
  Ran all test suites.

Package for distribution

Packaging the action will create a packaged action in the dist folder.

npm run prepare

Create a release branch

Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.

git checkout -b v1
git commit -a -m "v1 release"
git push origin v1

See the versioning documentation

See the actions tab for runs of this action! 🚀

Author

Daniel Bowden

github.com/danielbowden

twitter.com/danielgbowden

About

GitHub Action to lookup a slack user by their email address

License:MIT License


Languages

Language:JavaScript 100.0%