hnishi / simple-ai-slack-bot

Simple Slack bot powered by OpenAI Chat API
1 stars 0 forks source link

simple-ai-slack-bot

Simple Slack bot powered by OpenAI Chat API.

You can talk to the chat bot using OpenAI Chat API via Slack.

Usage in Slack

Public and private channels in which the bot is added

You have to mention the bot to talk to it.

screenshot

Direct messages to the bot

You can talk to the bot without mentioning it.

screenshot

Slack App Configuration

  1. Create an Slack app

  2. Socket Mode

    • On
  3. Bot Token Scopes

    • app_mentions:read
    • chat:write
    • im:history
    • im:read
    • im:write
  4. App Token Scopes

    • connections:write
  5. Event Subscriptions (Subscribe to bot events)

    • app_mentions:read
    • message.im
  6. Messages Tab

    • App Home --> Show Tabs --> Messages Tab
    • Check Allow users to send Slash commands and messages from the messages tab

Prerequisites

  1. Poetry

    Poetry is used to manage the dependencies.

    See https://python-poetry.org/docs/#installation

  2. Install the required packages

    poetry install --no-root

App Configuration

  1. Create the .env file

    cp .env.sample .env
  2. Set the necessary environment variables in the .env file

    SLACK_BOT_TOKEN=xoxb-xxx
    SLACK_APP_TOKEN=xapp-xxx
    OPENAI_API_KEY=sk-xxx
    OPENAI_ORGANIZATION=org-xxx  # this parameter is optional
    MODEL_NAME=gpt-3.5-turbo

    For model name, see https://platform.openai.com/docs/models/overview

Running the application

  1. Run the application

    poetry run python app.py

Docker

Build

docker build -t simple-ai-slack-bot .

Run

docker run -it simple-ai-slack-bot

docker compose

docker-compose up

References