# Slack Integration

**In Slack’s OAuth Settings**

* Go to your app’s **OAuth & Permissions** page.
    
* Under **Redirect URLs**, add:
    
    ```bash
    https://redirectmeto.com/http://localhost:3000/slack/oauth_redirect
    ```
    
    * Click **Save URLs**.
        
* **In Your App Code**
    
    * Use that exact URL in both:
        
        * Your **authorize** link (when redirecting users to Slack)
            
        * Your **token exchange** request (`oauth.v2.access`)
            
* **Run Your Local Server**
    
    * Start your backend on `http://localhost:3000`, listening on the path `/slack/oauth_redirect`.
        
    * RedirectMeTo automatically forwards Slack’s HTTPS callback—including query parameters—down to your local endpoint.
        

## Steps to create a slack app

## 1\. Open Slack API Portal 🌐

* Go to the Slack API apps page at **api.slack.com/apps** and ensure you're logged in.
    
* If you're on multiple workspaces, select the one where you want to create your app .
    

---

## 2\. Click **Create an App**

Once on the "Your Apps" page, click **Create an App**.  
You'll be prompted with two options:

* **From scratch**: Manually configure your app.
    
* **From manifest** (beta): Use a YAML manifest to define your app’s settings
    

---

## 3\. Choose a Starting Method

### From Scratch

* Click **From scratch**, then:
    
    * **Name your app** (e.g., "MyBotify").
        
    * **Select the workspace** where it'll live.
        
    * (Optional) upload an icon and set a description [techwondoe.com](https://techwondoe.com/blog/a-comphrensive-guide-to-creating-your-own-slack-app/?utm_source=chatgpt.com).
        

### Using Manifest

* Choose **From manifest**, paste your YAML, and Slack creates the app based on your spec.
    

---

## 4\. Configure Your App

Once created, you're taken to the **App Configuration** page. Key sections:

* **Basic Information**: Review App ID, signing secret, and add your app icon.
    
* **OAuth & Permissions**:
    
    * Add permission scopes (e.g., `chat:write`, `channels:read`).
        
    * Set **Redirect URLs** for OAuth (e.g., [https://yourapp.com/slack/oauth\_redirect](https://yourapp.com/slack/oauth_redirect)). For dev, you can use ngrok to tunnel a local server .
        
* **Event Subscriptions**:
    
    * Enable, paste your Request URL, and select events (e.g., `message.channels`).
        
    * Slack will verify your endpoint by sending a challenge.
        
* **Slash Commands**:
    
    * Click **Create New Command**, define the slash trigger (e.g., `/echo`) and link its Request URL .
        
* **Interactivity & Shortcuts**:
    
    * Enable and specify where button clicks or modals should be sent.
        
* **Incoming Webhooks**:
    
    * Enable webhooks and select target channels to get a webhook URL for posting messages .
        

---

## 5\. Install App to Workspace

* Under **OAuth & Permissions**, click **Install to Workspace**, authorize the requested scopes.
    
* Upon installing, Slack issues OAuth tokens (Bot and optionally User Tokens). Save these securely.
    

---

## 6\. Develop & Run Your App

* **Choose your tech stack** (Node.js with Bolt, Python, Java, or Deno) .
    
* **Setup development environment**:
    
    * Install Slack SDK (`@slack/bolt`, `slack_sdk`, etc.).
        
    * Use tools like **ngrok** to expose local dev server for events/callbacks .
        
* **Write code** to:
    
    * Handle OAuth callback, exchange code for tokens.
        
    * Listen/respond to slash commands, events, or interactive payloads.
        
* **Run locally**, updating Request URLs to ngrok's domain.
    

---

## 7\. Deploy & Publish

* **Deploy** your app to a production environment with stable URLs.
    
* Update all URLs in **OAuth**, **commands**, **events**, and **interactivity** configurations.
    
* (Optional) follow Slack’s review process to publish publicly on the Slack App Directory.
    

### 🔷 What are Slash Commands in Slack?

**Slash Commands** in Slack are custom or built-in commands that start with a `/` and allow users to **interact with apps or perform actions** directly from the message input box in a Slack channel or DM.

---

### 🔹 Examples of Built-in Slash Commands:

| Slash Command | Function |
| --- | --- |
| `/giphy cats` | Shows a random cat GIF from Giphy |
| `/remind me to call mom at 6pm` | Sets a reminder |
| `/poll "What's your favorite color?" "Red" "Blue"` | Creates a poll (via a polling app) |

---

### 🔹 What Custom Slash Commands Do

Custom slash commands let your own Slack app respond to user commands.

When a user types `/yourcommand`, Slack sends an HTTP request (called a **payload**) to your app’s server, and your app responds with a message.

---

### 🔹 How Slash Commands Work (Step-by-Step):

1. **User types a slash command**, e.g., `/weather delhi`.
    
2. **Slack sends a POST request** to your backend URL with:
    
    * The command used
        
    * User and channel info
        
    * Parameters after the command
        
3. **Your app processes the request** and returns a message or action.
    
4. **Slack displays the response** in the user’s chat.
    

## Slack Web API

The **Slack Web API** is a collection of over 200 HTTP methods that allow your app to **programmatically read, write, and modify data** within a Slack workspace. Think of it as the primary channel through which your app communicates with Slack. Here's how it works:

---

### 🔧 Key Features

* **RPC-style endpoints**  
    Each method is accessed via a URL like `https://slack.com/api/chat.postMessage`. You make HTTPS (GET or POST) requests to interact with channels, users, messages, files, and more [npm+11Slack API+11Slack Developer Docs+11](https://api.slack.com/web?utm_source=chatgpt.com).
    
* **Flexible input formats**  
    Send parameters as URL‑encoded form data or JSON. For token-based authentication, include your token in the `Authorization: Bearer <token>` header [Wikipedia+10Slack API+10Postman API Platform+10](https://api.slack.com/web?utm_source=chatgpt.com).
    
* **Wide range of capabilities**  
    Includes methods like `chat.postMessage`, `conversations.list`, `files.upload`, `users.info`, and many admin or audit functions [Slack Developer Tools](https://tools.slack.dev/node-slack-sdk/web-api/?utm_source=chatgpt.com).
    

---

### 🛠 How to Use It

1. **Install a client library**, such as `@slack/web-api` for Node.js.
    
2. **Instantiate a WebClient** with your bot token:
    
    ```bash
    const { WebClient } = require('@slack/web-api');
    const web = new WebClient(process.env.SLACK_BOT_TOKEN);
    ```
    
    **Call methods** directly:
    
3. ```bash
    await web.chat.postMessage({
      channel: 'C0123456789',
      text: 'Hello, world!'
    });
    ```
    
    The client handles retries, pagination, and error parsing
