Llamo a la API de Slack (conversations.history) para recibir mensajes del canal. Quiero recuperar el nombre del remitente en la respuesta del mensaje. ¿Cómo puedo obtenerlo?
a continuación está mi mensaje de respuesta:
{ "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:[]}Puede usar la identificación de usuario devuelta por la clave de user para realizar una llamada a users.info después de recibir esa carga útil.
La API de chats.history no devuelve la información del usuario (solo la identificación del usuario), es posible que debas obtener a cada usuario del historial del canal , mira un código de ejemplo:
| Obtener usuarios del historial de canales de Slack | Ejecutar en Fusebit |
|---|
const channelId = 'C02TSNCQ2Q2'; const channelHistory = await client.conversations.history({ channel: channelId, }); // Get the user ids from the history and populate an array with the user details const userList = []; for await (let message of channelHistory.messages) { const userAdded = userList.find(user => user.id === message.user); if (!userAdded) { const response = await slackClient.users.info({ user: message.user, }); if (response.ok) { const { id, name, real_name, profile, is_bot } = response.user; userList.push({ id, name, real_name, profile, is_bot }); } } } console.log(`There are ${userList.length} users in the channel conversation:\n${userList.map(user => `${(user.is_bot ? '🤖' : '👤')} ${user.name}`).join('\n')}`);