Slack Integration with C#

By Kamlesh Bhor · 📅 02 Jul 2025 · 👁️ 33

Follow:

Automate notifications, track projects, and impress your team - no prior experience needed!

This step-by-step tutorial is perfect for students and junior developers. By the end, you'll build a C# app that sends custom Slack messages using real-time webhooks. Let's turn you into a workflow automation hero! 🦸‍♂️


Why This Rocks for Learners

  • ✅ Zero Slack/C# experience required

  • ✅ Complete in under 20 minutes

  • ✅ Add a portfolio-worthy skill

  • ✅ Practical use cases (project alerts, exam reminders, team updates)


🚀 Step 0: What You'll Create

A C# console app that sends messages to Slack:

"But I'm a beginner!" → Don't worry! We'll walk through every mouse click and code line together.


📦 Step 1: Setup Your Tools

What You Need:

  1. Slack Account (free): signup.slack.com

  2. Visual Studio (free): visualstudio.microsoft.com

    • Select ".NET desktop development" during install

  3. .NET 6+ SDK (auto-installed with VS)

💡 Already set up? Skip to Step 2!


🔑 Step 2: Get Your Slack "Magic URL" (Webhook)

  1. Go to Slack API Portal → Create New App

  2. Name: My First C# Bot → Workspace: Pick yours

  3. Click Incoming Webhooks → Toggle On

  4. Add New Webhook → Choose #general → Copy Webhook URL

🔒 Security Tip: Treat this URL like a password! Never share or commit to GitHub.

 

🧩 Step 3: Create Your C# Project

  1. Open Visual Studio → Create new project

  2. Search: Console App → Select Console App (.NET Core)

  3. Name: SlackBot → Create

  4. Install required package:

    • Right-click Dependencies → Manage NuGet Packages

    • Search: Newtonsoft.Json → Install

💻 Step 4: Code - The Simple Version

Replace all code in Program.cs with:

using System.Text;
using System.Net.Http;
using Newtonsoft.Json;

// STEP 1: PASTE YOUR WEBHOOK HERE
const string WEBHOOK_URL = "https://hooks.slack.com/services/..."; 

// Simple message structure
public class SlackMessage
{
    public string? text { get; set; }
}

static async Task Main()
{
    // Create message
    var message = new SlackMessage 
    { 
        text = "Hello classmates! :wave: This is my first Slack bot from C#!" 
    };

    // Convert to JSON
    string json = JsonConvert.SerializeObject(message);
    
    // Send to Slack
    using (HttpClient client = new HttpClient())
    {
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await client.PostAsync(WEBHOOK_URL, content);
        
        // Check result
        Console.WriteLine(response.IsSuccessStatusCode 
            ? "✅ Message sent to Slack!" 
            : "❌ Failed: " + response.StatusCode);
    }
}

🎨 Step 5: Level Up - Send a Fancy Message

Replace the message code with this Block Kit example:

var message = new 
{
    blocks = new[] 
    {
        // Header
        new { 
            type = "header",
            text = new { 
                type = "plain_text", 
                text = ":tada: C# PROJECT UPDATE :tada:" 
            }
        },
        
        // Divider line
        new { type = "divider" },
        
        // Content section
        new { 
            type = "section",
            text = new {
                type = "mrkdwn",
                text = $"*Project Name:*\n`Slack Integration Tutorial`\n*Status:*\nCompleted! :white_check_mark:"
            },
            accessory = new {
                type = "image",
                image_url = "https://i.imgur.com/L7GddrP.png",
                alt_text = "C# logo"
            }
        },
        
        // Button
        new {
            type = "actions",
            elements = new[] {
                new {
                    type = "button",
                    text = new {
                        type = "plain_text",
                        text = "View Code :github:"
                    },
                    url = "https://github.com/your-repo"
                }
            }
        }
    }
};

🚦 Step 6: Run & Test

  1. Press F5 in Visual Studio

  2. See "✅ Message sent to Slack!" in console

  3. Check your #general Slack channel:

 

Troubleshooting:

  • 400 Error: Check your JSON syntax

  • 404 Error: Re-copy webhook URL

  • No message: Try re-running the app


🌐 Real-World Uses for Students

  1. Project Alerts

    if (projectCompleted) SendSlackMessage("Project submitted! 🎉");  
  2. Exam Reminders

    SendSlackMessage($"⏰ {courseName} exam in 24 hours!");  
  3. Team Coordination

    SendSlackMessage($"@here {task} needs review");  
 

📚 Next Steps to Level Up

  1. Store webhook securely
    Use appsettings.json instead of hardcoding

  2. Add message formatting
    Try emojis, @mentions, and attachments

  3. Explore events
    Make your bot respond to Slack messages

  4. Deploy
    Run your bot 24/7 on Azure Free Tier

 

💬 "Will This Work for My Class Project?"

Absolutely! This integration is perfect for:

  • Notifying teams when assignments are uploaded

  • Alerting study groups about schedule changes

  • Sharing real-time data from science experiments

  • Building a portfolio piece that stands out

 

You did it! ✨
Now you can automate Slack with C# - go impress your classmates, professor, or future internship manager! Got questions? Drop them in Slack (your bot can reply too 😉)



Kamlesh Bhor
Article by Kamlesh Bhor

Feel free to comment below about this article.

💬 Discuss about this post