This topic was automatically generated from Slack. You can find the original thread here.
how do I use Slack API to get all the users “Full Name” and “Emails” from reactions in a message?
This topic was automatically generated from Slack. You can find the original thread here.
how do I use Slack API to get all the users “Full Name” and “Emails” from reactions in a message?
To get all the users’ “Full Name” and “Emails” from reactions in a message using the Slack API, you can follow these steps: 1. Use the Slack API to get reactions on a message: You can use the reactions.get
method to fetch reactions on a specific message. 2. Fetch user profiles: For each user who reacted, use the users.profile.get
method to fetch their full name and email. Here’s a Pipedream component that demonstrates how to achieve this: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { slack: { type: “app”, app: “slack”, }, channel: { type: “string”, label: “Channel ID”, }, timestamp: { type: “string”, label: “Message Timestamp”, }, }, async run({ steps, $ }) { // Fetch reactions from the message const reactionsResponse = await axios($, { url: https://slack.com/api/reactions.get
, headers: { Authorization: Bearer ${this.slack.$auth.oauth_access_token}
, }, params: { channel: this.channel, timestamp: this.timestamp, }, }); if (!reactionsResponse.ok) { throw new Error(Error fetching reactions: ${reactionsResponse.error}
); } const users = new Set(); reactionsResponse.message.reactions.forEach(reaction => { reaction.users.forEach(user => users.add(user)); }); const userProfiles = ; for (const user of users) { const userProfileResponse = await axios($, { url: https://slack.com/api/users.profile.get
, headers: { Authorization: Bearer ${this.slack.$auth.oauth_access_token}
, }, params: { user, }, }); if (!userProfileResponse.ok) { throw new Error(Error fetching user profile: ${userProfileResponse.error}
); } userProfiles.push({ fullName: userProfileResponse.profile.real_name, email: userProfileResponse.profile.email, }); } return userProfiles; }, });
how to get the channel ID and message timestamp from my Slack client?
To get the channel ID and message timestamp from your Slack client, you can use the Slack API. Below is a Pipedream component example that retrieves the channel ID and message timestamp for a specific message in a Slack channel. First, you need to have the message’s permalink. You can get this by right-clicking on the message in Slack and selecting “Copy link”. The permalink will look something like this: https://<workspace>.[slack.com/archives/<channel_id>/p<timestamp](http://slack.com/archives/<channel_id>/p<timestamp)>
. Here’s the Pipedream component code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { slack: { type: "app", app: "slack", }, permalink: { type: "string", label: "Message Permalink", description: "The permalink of the Slack message", }, }, async run({ steps, $ }) { const match = this.permalink.match(/archives\/([^\/]+)\/p(\d+)/); if (!match) { throw new Error("Invalid permalink format"); } const channel_id = match[1]; const timestamp = match[2].slice(0, 10) + "." + match[2].slice(10); return { channel_id, timestamp, }; }, });
### Steps to use this component: 1. Search for the Slack app from the step menu. 2. Select the custom component. 3. Connect your Slack account. 4. Enter the message permalink. 5. Test the step to retrieve the channel ID and message timestamp. This component extracts the channel ID and timestamp from the message permalink. The channel_id
and timestamp
will be returned as the output of the step. If you have any further questions or need additional help, feel free to ask!
can I handle Slack users from other Organizations? And also get the Full Name and email for them?
To handle Slack users from other organizations and retrieve their full name and email, you need to consider the following: 1. Slack API Limitations: Slack’s API generally restricts access to user information to the organization that owns the workspace. This means you cannot directly access user information from other organizations unless you have the appropriate permissions and the users are part of a shared channel. 2. Shared Channels: If the users from other organizations are part of a shared channel, you might be able to retrieve some information about them. However, the extent of the information you can access depends on the permissions and scopes granted to your Slack app. 3. OAuth Scopes: To retrieve user information, you need to ensure that your Slack app has the necessary OAuth scopes. For example, the users:read
and users:read.email
scopes are required to read user profiles and email addresses. Here’s an example Pipedream component to get the full name and email of a user in your Slack workspace: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { slack: { type: “app”, app: “slack”, }, userId: { type: “string”, label: “User ID”, description: “The ID of the user to retrieve information for”, }, }, async run({ steps, $ }) { const userProfile = await axios($, { url: https://slack.com/api/users.profile.get
, headers: { Authorization: Bearer ${this.slack.$auth.oauth_access_token}
, }, params: { user: this.userId, }, }); const userEmail = await axios($, { url: https://slack.com/api/users.info
, headers: { Authorization: Bearer ${this.slack.$auth.oauth_access_token}
, }, params: { user: this.userId, }, }); return { fullName: userProfile.profile.real_name, email: userEmail.user.profile.email, }; }, });