1
votes

I am creating a slack bot and want to be able to link the slack user with the github account.

Is there a way I can link the 2 either via slack or github API's?

I was thinking if of storing users slack username and github username in a JSON object, i.e.:

{
    "slack_username": "JoeBlogs",
    "github_username": "JoeBlogs123"
}

In order to do this, I would need to retrieve the users' username from slack API when the user authorises the app / bot.

I was thinking if I add a redirect_url to my slack app then it would redirect user to http://example.com/redirect if the users data is sent along to this redirect url, I would be able save it in a database of sorts.

If I then did the same with the github API then I could reference database in order to find slack users JoeBlogs github account and vice versa.

Is it possible to use the redirect_url like this? I couldn't see any user data being sent to but maybe it is nested somewhere I couldn't see it?

Is there a better way to link the 2 accounts?

1

1 Answers

1
votes

Assuming you are using Install button to install your Slack app into the workspace, this is a payload which will be sent to your response_url:

{
    "access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
    "scope": "incoming-webhook,commands,bot",
    "team_name": "Team Installing Your Hook",
    "team_id": "XXXXXXXXXX",
    "incoming_webhook": {
        "url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
        "channel": "#channel-it-will-post-to",
        "configuration_url": "https://teamname.slack.com/services/BXXXXX"
    },
    "bot":{
        "bot_user_id":"UTTTTTTTTTTR",
        "bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
    }
}

See for details.

Then, using access_token in combination with users.identity API method you will get basic information about Slack user (playing with the scopes you requested during the install process you can get different fields of Slack user identity).