1

How do I get the url/team name from a bot framework activity/context? Currently I can get the TeamId but can that be translated into the text string for the teams name?

For example testteam.slack.com, how can I extract the "testteam" part from bot framework messages?

Dizzle
  • 1,026
  • 13
  • 26

2 Answers2

1

You are looking for team.info method in Slack API, that you can query with your Bot User OAuth Access Token (visible in OAuth & Permissions menu, and also available in each bot message in the ChannelData, property named ApiToken).

You can get details about this method here: https://api.slack.com/methods/team.info

In particular, have a look to domain field in the response sample:

{
    "ok": true,
    "team": {
        "id": "Txxxxxx",
        "name": "BotDemoCompany",
        "domain": "botdemocompany",
        "email_domain": "xxxxxxx.com",
        "icon": {
            "image_34": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_44": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_68": "https:\/\/a.slack-edge.com\xxx.png",
            "image_88": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_102": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_132": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_230": "https:\/\/a.slack-edge.com\/xxx.png",
            "image_default": true
        }
    }
}
Nicolas R
  • 13,812
  • 2
  • 28
  • 57
1

As already mentioned you can call the Slack API method team.info to get the domain name for a team. However, that requires your token to have specific scopes, which you might not have.

It's therefore better to call auth.test, because it does not require any special scopes (except the bot scope for a bot token, but that is implicit). This API method will return the full URL of the Slack team along with other basic info for the provided Slack token.

Note that you need a Slack token corresponding with the team you want to get the info for. The team ID alone is not sufficient to get info about a team. (same for team.info btw). I am not familiar with the botframework, but since it works with Slack it must have a method to retrieve the current Slack token.

Example output:

{
    "ok": true,
    "url": "https:\/\/subarachnoid.slack.com\/",
    "team": "Subarachnoid Workspace",
    "user": "grace",
    "team_id": "T12345678",
    "user_id": "W12345678"
}
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • The bot is created as a bot user in Slack during the registration process and has a Bot User OAuth Access Token that allows to request `team.info` so if the user wants directly the domain, it may be the right way. I've added details about getting the token in my reply, thanks for the point – Nicolas R Jan 16 '18 at 21:53
  • I agree. If you have a bot user with the bot scope that will work. – Erik Kalkoken Jan 16 '18 at 23:03