Opening Problem Statement
Meet Sarah, a project manager working with multiple development teams. Every time she needs to get detailed GitHub user information—like their real email, company affiliation, or location—she wastes at least 15 minutes per query. Sarah’s routine involves opening GitHub, searching for the user, manually examining pull requests to find contact emails, and then copying the avatar and other details all by hand. Over a month, this stacks up to multiple hours wasted, delays in contacting contributors, and occasional errors due to missing or outdated data. Clearly, Sarah needs a faster, more reliable way to fetch GitHub user info right inside the tools she already uses daily, like Slack.
What This Automation Does
When this n8n workflow runs triggered by a Slack command, it automates the retrieval and sharing of comprehensive GitHub user details directly in Slack channels. Here’s exactly what it does:
- Fetches GitHub user profile data such as name, company, location, avatar URL, and public email via GitHub’s GraphQL API.
- Extracts verified email addresses from the user’s recent 25 pull requests’ commits, ensuring accurate contact info beyond the public profile.
- Filters out GitHub-generated no-reply emails to provide only usable emails.
- Posts a well-formatted Slack message in the originating channel, displaying the user’s name, emails, company, location, and avatar in an attachment.
- Eliminates manual searching steps, reducing time per lookup from 15 minutes to just a few seconds.
- Improves team communication by having GitHub user info instantly accessible where conversations happen.
Prerequisites ⚙️
- n8n automation platform (account with access to create workflows) 🔌
- Slack workspace with OAuth2 credentials configured for n8n Slack node 💬🔑
- GitHub personal access token with permissions to query user data via GraphQL graph endpoint 🔐
- Basic understanding of Slack slash commands or how to trigger webhooks 📧
Step-by-Step Guide
Step 1: Create a Webhook in n8n for Slack to trigger 🔌
Navigate to n8n Editor, click + New Workflow. Add the Webhook node. Set the:
- HTTP Method to
POST - Path to something unique, e.g.,
dacd64a7-a83e-4492-b8fe-363453906d0d
Save the node and copy the webhook URL. You should see a URL like https://your-n8n-domain/webhook/dacd64a7-a83e-4492-b8fe-363453906d0d. This is where Slack will send the data when a command is executed.
Common mistake: Forgetting to select POST method, which is required for Slack commands.
Step 2: Configure Slack to trigger the webhook 📧
In your Slack workspace, create a new slash command or app that sends a POST request to the webhook URL. For example, create a slash command /githubuser that posts the username typed by a team member in Slack’s message payload as text.
Test sending a command like /githubuser octocat in Slack. Your webhook should receive a payload with text = “octocat”.
Common mistake: Not parsing the text field correctly in the next node.
Step 3: Add the GraphQL node to query GitHub user info 🎯
Add the GraphQL node connected to the Webhook node. Configure:
- Endpoint:
https://api.github.com/graphql - Query: Use the provided query that dynamically inserts the username from the webhook payload
{{$node["Webhook"].json["body"]["text"]}} - Headers: Add
User-Agentasn8nandAuthorizationasbearer.
This query fetches the user’s name, company, location, avatarUrl, public email, and the last 25 pull requests with commit author emails.
Expected outcome: JSON response with nested user data for processing.
Step 4: Use a Function node to extract and clean emails 🧹
Add the Function node after GraphQL. Copy-paste this JavaScript code:
let emails = [];
let tempEmails = [];
const name = $node["GraphQL"].json["data"]["data"]["user"]["name"];
const publicEmail = $node["GraphQL"].json["data"]["data"]["user"]["email"];
const username = $node["Webhook"].json["body"]["text"];
const nameRegex = new RegExp(name,"g")
if(publicEmail){
tempEmails.push(publicEmail);
}
for(const edge of items[0].json.data.data.user.pullRequests.edges){
for(node of edge.node.commits.nodes){
if(nameRegex.test(node.commit.author.name) || node.commit.author.name == username) {
tempEmails.push(node.commit.author.email);
}
}
}
emails = [...new Set(tempEmails)];
let re = /^w+(.)*@users.noreply.github.com/;
emails = emails.filter(email => !re.test(email));
return [{json:{emails}}];
Explanation: This code collects the public email plus emails from commits where author name matches the GitHub user, removes duplicates, and filters out GitHub no-reply emails.
Common mistake: Incorrect RegEx causing valid emails to be filtered out.
Step 5: Send formatted results back to Slack using the Slack node 💬
Add the Slack node after the Function node. Configure:
- Channel: dynamically set using
{{$node["Webhook"].json["body"]["channel_id"]}} - Attachments: craft a message showing Name, Emails, Company, Location, and Avatar URL from previous nodes using expressions.
- Authentication: use your Slack OAuth2 credentials.
This posts a neat message in the Slack channel with GitHub user information instantly accessible.
Common mistake: Forgetting to link OAuth2 credentials correctly, resulting in errors.
Customizations ✏️
- Change the number of pull requests analyzed: In the GraphQL node’s query, adjust the
last: 25value to a higher or lower number to scan more or fewer commits. - Include additional GitHub fields: Modify the GraphQL query to fetch user bio, Twitter handle, or repository count, and update the Slack message template accordingly.
- Notify a specific Slack user: In the Slack node, add a
mentionin the message text to ping a team lead whenever a GitHub user info is retrieved.
Troubleshooting 🔧
- Problem: “Authorization error from GitHub API”
Cause: Invalid or expired GitHub token.
Solution: Generate a new personal access token with required scopes and update the GraphQL node’s headers. - Problem: “Slack node authentication failed”
Cause: Incorrect Slack OAuth2 credentials.
Solution: Reauthenticate Slack credentials in n8n and reconnect the Slack node. - Problem: No emails showing up in the Slack message.
Cause: The Function node filtering is too strict or no commits match the author name.
Solution: Check the commit author names in GitHub, adjust the RegEx pattern, or reduce filtering to include more results.
Pre-Production Checklist ✅
- Test Slack slash command triggers webhook and passes username correctly.
- Validate GitHub token has correct GraphQL API scopes and the query returns data.
- Run workflow manually with sample data to verify email extraction logic.
- Confirm Slack node posts message correctly with avatar and user info.
- Backup workflow JSON and credentials before deploying.
Deployment Guide
Once all tests pass, activate the workflow in n8n by toggling the Active switch. Make sure the webhook URL remains publicly accessible for Slack to send POST requests. Monitor the Slack channel for confirmation messages when users run the command. For scaling, consider rate limits of GitHub’s GraphQL API and Slack message posting limits. If self-hosting n8n, ensure uptime and network accessibility for uninterrupted calls.
FAQs
- Can I use this with other chat platforms? Potentially yes, but you’d need to replace the Slack node with your platform’s messaging node and adjust webhook triggers accordingly.
- Does this consume GitHub API credits? Yes, GraphQL queries count towards your GitHub API rate limit so monitor usage to avoid interruptions.
- Is my extracted email data secure? The workflow only fetches public and commit-based emails. Keep tokens safe and run n8n on a secure server.
- Can this workflow handle multiple queries concurrently? Yes, but monitor API limits and consider adding rate-limiting or queue nodes if usage is heavy.
Conclusion
By building this workflow, you just automated the tedious process Sarah faced—retrieving comprehensive GitHub user information directly within Slack. This automation cuts lookup times from 15 minutes to seconds, boosts communication efficiency, and reduces human error in copying contact details. Next, you might explore automating GitHub issue tracking, Slack notifications for PR merges, or enriching Slack profiles with GitHub data for your team. Keep experimenting and enjoy the smoother collaboration!