bot.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:WineHelper 作者: scorelabio 项目源码 文件源码
def auth(self, code):
        """
        Authenticate with OAuth and assign correct scopes.
        Save a dictionary of authed team information in memory on the bot
        object.

        Parameters
        ----------
        code : str
            temporary authorization code sent by Slack to be exchanged for an
            OAuth token

        """
        # After the user has authorized this app for use in their Slack team,
        # Slack returns a temporary authorization code that we'll exchange for
        # an OAuth token using the oauth.access endpoint
        auth_response = self.client.api_call(
                                "oauth.access",
                                client_id=self.oauth["client_id"],
                                client_secret=self.oauth["client_secret"],
                                code=code
                                )
        # To keep track of authorized teams and their associated OAuth tokens,
        # we will save the team ID and bot tokens to the global
        # authed_teams object
        team_id = auth_response["team_id"]
        self.authed_teams[team_id] = {"bot_token":
                                 auth_response["bot"]["bot_access_token"]}
        # Then we'll reconnect to the Slack Client with the correct team's
        # bot token
        self.slacker = Slacker(self.authed_teams[team_id]["bot_token"])
        team = self.find_team(team_id)
        if team is None:
            team = Team(team_id=team_id, 
                name=auth_response["team_name"], 
                bot_user_id=auth_response["bot"]["bot_user_id"],
                bot_access_token=auth_response["bot"]["bot_access_token"])
            team.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号