slack获取从conversation.history api返回的消息的消息发件人名称

Sun*_*y G 4 node.js slack-api

我正在调用 slack API(conversations.history) 来获取频道消息。我想在消息响应中检索发件人姓名。我怎么才能得到它?

以下是我的留言回复:

{  "client_msg_id": "0e19ca7d-1072-4f73-a932-9ec7fa9956de",
          "type": "message",
          "text": "Yeah good edge case, I would agree, just mentioning \" no data found\"",
          "user": "U01JW9D10PQ",
          "ts": "1642216920.001100",
          "team": "T01K38V9Q7M", blocks:[]}
Run Code Online (Sandbox Code Playgroud)

Rub*_*epo 5

conversations.history API 不返回用户信息(仅返回用户 ID),您可能需要从频道历史记录中获取每个用户请参阅示例代码:

\n
\n\n\n\n\n\n\n\n
获取 Slack 频道历史记录用户 \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\ xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\ xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\ xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\ xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0Run in Fusebit
\n
\n
const channelId = \'C02TSNCQ2Q2\';\nconst channelHistory = await client.conversations.history({\n  channel: channelId,\n});\n\n// Get the user ids from the history and populate an array with the user details\nconst userList = [];\nfor await (let message of channelHistory.messages) {\n  const userAdded = userList.find(user => user.id === message.user);\n  if (!userAdded) {\n    const response = await slackClient.users.info({\n      user: message.user,\n    });\n\n    if (response.ok) {\n      const { id, name, real_name, profile, is_bot } = response.user;\n      userList.push({ id, name, real_name, profile, is_bot });\n    }\n  }\n}\n\nconsole.log(`There are ${userList.length} users in the channel conversation:\\n${userList.map(user => `${(user.is_bot ? \'\' : \'\')} ${user.name}`).join(\'\\n\')}`);\n\n
Run Code Online (Sandbox Code Playgroud)\n