无法在Slack bot中打印用户发短信的用户名

问题描述 投票:1回答:1

如何获取“ Jonh”之类的用户名而不是WLLACM2HK?

代码

starterbot_id = web_client.api_call("auth.test")["user_id"]
print("starterbot id------->"+starterbot_id))

以上代码的当前输出

starterbot id------->WLLACM2HK  

我希望代码打印下面的输出内容

starterbot id------->Jonh

web_client.api_call(“ auth.test”)中的数据

{
    'ok': True,
    'url': 'https: //bby-sandbox-general.slack.com/',
    'team': 'SandboxGeneralWorkspace',
    'user': 'ipt-autobot',
    'team_id': 'TFHGD33RV',
    'user_id': 'WLLACM2HK',
    'bot_id': 'BLDVB7EKB',
    'enterprise_id': 'EFGBDRLNP',
    'warning': 'superfluous_charset',
    'response_metadata': {
        'warnings': [
            'superfluous_charset'
        ]
    }
}

我感觉我没有调用正确的api,因为我没有在上面的json中看到用户名,所以user属性实际上是slack bot的名称,我想打印在slack bot中发短信的用户

尝试打印时(web_client.users_info(user = user))

{
    'ok': True,
    'user': {
        'id': 'WGUHC67D1',
        'team_id': 'TJK2GBSC9',
        'name': 'a6002043',
        'deleted': False,
        'color': 'c386df',
        'real_name': 'RaviKanth',
        'tz': 'America/Chicago',
        'tz_label': 'CentralStandardTime',
        'tz_offset': -21600,
        'profile': {
            'title': 'CW-Other',
            'phone': '+15614128585',
            'skype': '',
            'real_name': 'RaviKanth',
            'real_name_normalized': 'RaviKanth',
            'display_name': 'RaviKanth',
            'display_name_normalized': 'RaviKanth',
            'status_text': '',
            'status_emoji': '',
            'status_expiration': 0,
            'avatar_hash': '8f97c61708c1',
            'image_original': 'https: //avatars.slack-edge.com/2019-11-27/852421659589_8f97c61708c1553628c8_original.jpg',
            'is_custom_image': True,

如何获取实名值并打印出来?

python slack
1个回答
1
投票
我正在处理它,如果您有user_id,则可以使用user.info方法来获取特定的用户信息。

这里是一个示例:Image

链接:https://api.slack.com/methods/users.info

© www.soinside.com 2019 - 2024. All rights reserved.