Building a GitHub-Slack Bot

This guide will show you how to set up a workflow that sends notifications from GitHub to Slack when a new issue is created.

Features Included in Template

FeatureWorkware GitHub Slack Bot Template
Real-time Slack notifications
Receive instant updates when new issues are created
Slack message templates
Select from a set of pre-defined message templates
Issue details in Slack
Slack message with relevant issue details from GitHub
Issue status updates
Original Slack message updated with issue status changes
Comment notifications
New comments are added to the message thread in Slack
GitHub to Slack username mapping
Map GitHub usernames to Slack usernames in the workflow
Customization
Customize any aspect of this workflow to fit your needs in n8n

Prerequisites

  • An n8n instance (cloud or self-hosted)
  • A GitHub repository
  • A Slack workspace
  • Basic understanding of GitHub, Slack, and n8n
Get Started with a free trial of n8n Cloud
Sign up for n8n Cloud to start building your automated workflows
Learn more

Step 1: Import Workflow in N8N

1.1 Download Workflow File

  1. Click the workflow below to visit the workflow details page
  2. Click the Download button to download the workflow JSON file
  3. Save the file to your local computer
GitHub Slack Bot Workflow
A workflow to notify Slack when a new issue is created in GitHub
Learn more

1.2 Import Workflow to N8N

  1. Open your n8n instance
  2. Create a new workflow
  3. Click the ... menu in the top right
  4. Select Import from File...
  5. Choose the downloaded workflow JSON file
N8N Import Workflow Screenshot
Select Import from file from the kebab menu in n8n

Step 2: Configure Webhook in GitHub

2.1 Create Webhook

  1. Go to your GitHub repository
  2. Click Settings > Webhooks > Add webhook
  3. For the Payload URL, enter your n8n webhook URL
  4. Set Content type to application/json
  5. Select Let me select individual events
  6. Check only Issues and Issue comments
  7. Click Add webhook

2.2 Test Webhook

  1. Create a new issue in your repository
  2. Check n8n to see if the webhook was triggered
  3. If successful, you'll see the webhook data in n8n

Step 3: Configure Slack Integration

3.1 Create Slack App

  1. Go to api.slack.com/apps
  2. Click Create New App
  3. Choose From scratch
  4. Name your app and select your workspace
  5. Click Create App

3.2 Add Bot Token Scopes

  1. Go to OAuth & Permissions
  2. Under Scopes, add these Bot Token Scopes:
    • chat:write
    • chat:write.public
    • chat:write.customize
  3. Click Install to Workspace
  4. Copy the Bot User OAuth Token

3.3 Configure n8n Slack Node

  1. In n8n, double click the Slack node
  2. Click Add Credentials
  3. Paste your Bot User OAuth Token
  4. Select the channel for notifications
  5. Save the workflow

Step 4: Activate and Test

4.1 Activate Workflow

  1. Click Active toggle in n8n
  2. Ensure all credentials are set

4.2 Test End-to-End

  1. Create a new issue in GitHub
  2. Check Slack for the notification
  3. Add a comment to the issue
  4. Verify the comment appears in the Slack thread

Customization Options

Message Templates

You can customize the Slack message format in the Function node:

// Customize message format
const message = {
  text: `New Issue: ${issue.title}`,
  blocks: [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: `*New Issue:* ${issue.title}\n${issue.body}`
      }
    }
  ]
};

Username Mapping

To map GitHub usernames to Slack usernames:

  1. Add a Function node before Slack
  2. Create a mapping object:
const userMap = {
  'github-username': '@slack-username'
};
  1. Replace GitHub usernames in the message

Additional Events

To add more GitHub events:

  1. Edit webhook in GitHub
  2. Select additional events
  3. Add corresponding logic in n8n

Troubleshooting

Common Issues

  1. Webhook not triggering

    • Check webhook URL
    • Verify events are selected
    • Check repository permissions
  2. Slack messages not sending

    • Verify bot token
    • Check channel permissions
    • Ensure workflow is active

Getting Help

Best Practices

  • Use a dedicated Slack channel for notifications
  • Limit webhook events to reduce noise
  • Regularly review and update workflow

Security Considerations

  • Use HTTPS for webhook URLs
  • Limit webhook access to trusted IP ranges
  • Rotate Slack bot tokens periodically

Next Steps

  • Add more detailed filtering
  • Create multi-channel notifications
  • Implement issue triage workflows
GuideGitHubSlackIntegration