Dizzle
Dizzle

Reputation: 1016

Microsoft botframework and slack channel

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?

Upvotes: 1

Views: 389

Answers (2)

Nicolas R
Nicolas R

Reputation: 14589

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
        }
    }
}

Upvotes: 1

Erik Kalkoken
Erik Kalkoken

Reputation: 32698

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"
}

Upvotes: 1

Related Questions