OpenAI's Codex gets a plugin marketplace for Slack, Notion, Figma, and more
Back to Tutorials
aiTutorialintermediate

OpenAI's Codex gets a plugin marketplace for Slack, Notion, Figma, and more

March 27, 20264 views5 min read

Learn to build a Slack plugin that integrates with OpenAI's Codex to automate tasks using natural language commands. This tutorial shows how to create a plugin that interprets user requests and executes actions within Slack.

Introduction

In this tutorial, we'll explore how to build a Slack plugin that integrates with OpenAI's Codex to automate tasks in your workspace. This tutorial demonstrates how developers can leverage Codex plugins to connect with popular productivity tools like Slack, Notion, and Figma. You'll learn to create a plugin that can interpret natural language commands and execute actions within Slack using Codex's powerful language understanding capabilities.

Prerequisites

  • Basic understanding of Python and web development
  • Slack workspace with admin privileges
  • OpenAI API key
  • Heroku account or similar hosting platform
  • Basic knowledge of Slack's Bot Framework

Step-by-step instructions

1. Setting Up Your Development Environment

1.1 Create a New Python Project

We'll start by creating a new Python project directory and installing the required dependencies. This foundational step ensures we have all necessary tools to build our plugin.

mkdir codex-slack-plugin
 cd codex-slack-plugin
 python -m venv venv
 source venv/bin/activate  # On Windows: venv\Scripts\activate
 pip install slack-bolt openai python-dotenv

1.2 Create Environment Configuration

Next, we'll set up environment variables to securely store our API keys and configuration settings. This approach protects sensitive information from being exposed in version control.

# .env file
SLACK_BOT_TOKEN=xoxb-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX
SLACK_SIGNING_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SLACK_APP_ID=XXXXXXXXXXXXX

2. Creating the Slack Bot

2.1 Initialize the Slack App

We'll create the core Slack application that will listen for messages and respond to user commands. This forms the foundation of our plugin architecture.

from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from dotenv import load_dotenv
import os

load_dotenv()

# Initialize the app with our bot token and signing secret
app = App(
    token=os.environ["SLACK_BOT_TOKEN"],
    signing_secret=os.environ["SLACK_SIGNING_SECRET"]
)

@app.message("hello")
def message_hello(message, say):
    say(f"Hello <@{message['user']}>!")

if __name__ == "__main__":
    handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
    handler.start()

2.2 Implement Natural Language Processing

Now we'll add Codex integration to interpret natural language commands. This is where our plugin's intelligence comes from - translating human language into actionable tasks.

import openai

# Configure OpenAI API
openai.api_key = os.environ["OPENAI_API_KEY"]

def interpret_command(user_input):
    prompt = f"""
    You are an AI assistant that translates natural language commands into structured actions.
    
    User command: {user_input}
    
    Please respond with JSON that contains:
    - action: What the command should do (e.g., 'create_task', 'search_docs')
    - parameters: A dictionary of parameters for the action
    
    Example response:
    {{
      "action": "create_task",
      "parameters": {{"task_name": "Design new dashboard", "assignee": "@john"}}
    }}
    """
    
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=200,
        temperature=0.3
    )
    
    return response.choices[0].text.strip()

3. Building Plugin Functionality

3.1 Create Task Management Plugin

We'll implement a plugin that can create and manage tasks within Slack using Codex's interpretation capabilities. This demonstrates how Codex plugins can work with real productivity tools.

@app.message("create task")
def handle_task_creation(message, say):
    # Get the user's full message
    full_message = message['text']
    
    # Use Codex to interpret the command
    interpreted = interpret_command(full_message)
    
    try:
        # Parse the JSON response
        import json
        action_data = json.loads(interpreted)
        
        if action_data['action'] == 'create_task':
            task_name = action_data['parameters']['task_name']
            assignee = action_data['parameters']['assignee']
            
            # Create the task in Slack
            say(f"Task created: {task_name} assigned to {assignee}")
            
    except json.JSONDecodeError:
        say("I couldn't understand that command. Please try again.")

3.2 Add Notion Integration

Let's extend our plugin to work with Notion, showing how Codex plugins can integrate with multiple tools simultaneously.

import requests

# Notion integration
NOTION_API_KEY = os.environ["NOTION_API_KEY"]
NOTION_DATABASE_ID = os.environ["NOTION_DATABASE_ID"]

def create_notion_page(title, content):
    url = "https://api.notion.com/v1/pages"
    headers = {
        "Authorization": f"Bearer {NOTION_API_KEY}",
        "Content-Type": "application/json",
        "Notion-Version": "2022-06-28"
    }
    
    payload = {
        "parent": {"database_id": NOTION_DATABASE_ID},
        "properties": {
            "Name": {"title": [{"text": {"content": title}}]}
        },
        "children": [
            {
                "paragraph": {
                    "text": [{"text": {"content": content}}]
                }
            }
        ]
    }
    
    response = requests.post(url, headers=headers, json=payload)
    return response.json()

4. Deploying the Plugin

4.1 Prepare for Deployment

Before deploying, we need to create a requirements file and update our main application to handle production environments.

# requirements.txt
slack-bolt==1.18.0
openai==0.27.8
python-dotenv==1.0.0
requests==2.31.0

4.2 Create a Production-ready Main File

Our final application file should be production-ready and handle errors gracefully, which is crucial for real-world plugin deployments.

from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from dotenv import load_dotenv
import os
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

load_dotenv()

app = App(
    token=os.environ["SLACK_BOT_TOKEN"],
    signing_secret=os.environ["SLACK_SIGNING_SECRET"]
)

@app.error
def global_error_handler(error, body, logger):
    logger.error(f"Error: {error}")
    logger.error(f"Request body: {body}")

if __name__ == "__main__":
    try:
        handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
        logger.info("Starting the Slack app...")
        handler.start()
    except Exception as e:
        logger.error(f"Failed to start app: {e}")

4.3 Deploy to Heroku

Finally, we'll deploy our plugin to Heroku, ensuring it's always running and ready to process user commands.

# Procfile
web: python app.py

Then deploy using Heroku CLI:

heroku create codex-slack-plugin
heroku config:set SLACK_BOT_TOKEN=xoxb-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX-XXXXXXXXXXXX
heroku config:set SLACK_SIGNING_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
heroku config:set OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
heroku config:set SLACK_APP_TOKEN=xapp-XXXXXXXXXXXXX

git add .
git commit -m "Add plugin implementation"
git push heroku main

Summary

In this tutorial, we've built a Slack plugin that leverages OpenAI's Codex to interpret natural language commands and execute actions within Slack. We've demonstrated how Codex plugins can integrate with productivity tools like Notion, creating a seamless workflow automation experience. The plugin interprets user commands, translates them into structured actions, and executes them within the Slack environment. This architecture can be extended to integrate with other tools like Figma, Gmail, and Google Drive, showcasing the power of Codex plugins in modern workplace automation.

Key concepts covered include: Slack bot development, natural language processing with Codex, API integration patterns, and production deployment strategies. This foundation can be expanded to create more sophisticated plugins that work across multiple platforms, demonstrating the real-world potential of AI-powered plugin ecosystems.

Source: The Decoder

Related Articles