Skip to content

idmasse/flippy_slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slackbot Powered by OpenAI

This project is a lightweight Slack bot that posts an AI-generated message to a Slack channel every six hours using OpenAI’s API.

Goal

Find a way to ensure that a computer on a local network is powered on and its operations are functional.

Due to security concerns, our IT team wasn't comfortable forwarding a port on our local network to expose it to the internet, so I designed this bot to act as a de-facto ping. The idea was that if I don't get a slack notification from the bot every six hours, I'll know to check that the computer is still running.

Approach

To make this more interesting (as opposed to just posting the same message over and over), I decided to make the bot prompt the OpenAI api to post to the Slack channel.

The bot has gone through several iterations, including:

  • Dark-humored haikus
  • Jokes
  • Horoscopes
  • A “word of the day” (current implementation)

Early versions of the word-of-the-day prompt resulted in frequent repetition. To improve variety, the bot now:

  • Randomly selects a starting letter
  • Prompts OpenAI to return a word beginning with that letter

This ensures fresh output while keeping the prompt simple and deterministic.

Implementation

The bot is scheduled to run every 21600 seconds (six hours) via a plist.


How It Works

  1. A scheduled job runs every six hours.
  2. The script:
    • Generates a prompt for OpenAI
    • Requests a short response (e.g., a word of the day and definition)
  3. The generated content is posted to a designated Slack channel.
  4. Receipt of the message confirms:
    • The machine is powered on
    • Network access is functional
    • The runtime environment and credentials are valid

Project Structure

  • flippy_slack.py
    Main execution script. Handles prompt generation, OpenAI interaction, and Slack message posting.

  • config.py
    Centralized configuration and environment variable loading.

  • com.flippy_slack.plist
    macOS LaunchAgent configuration used to schedule execution every 21,600 seconds (six hours).

  • requirements.txt
    Python dependencies required to run the bot.

  • README.md
    Project documentation.


Setup

Prerequisites

  • Python 3.9+
  • macOS (for scheduled execution using launchd)
  • A Slack bot token with permission to post messages
  • An OpenAI API key

Installation

pip install -r requirements.txt

About

flippy_slack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages