Skip to content

chain4energy/lockup-slack-bot

Repository files navigation

Slack Contract Monitor Bot

A Slack bot that utilizes lockup smart contract queries to display information, monitor lockups and send periodic alerts.

Prerequisites

  1. Slack App Setup:

    • Create a new Slack app at https://api.slack.com/apps
    • Enable Socket Mode
    • Add Bot Token Scopes: chat:write, commands, app_mentions:read
    • Install the app to your workspace
    • Get your Bot Token and App Token
  2. Contract Information:

    • Contract address of your deployed lockup contract
    • RPC endpoint for the blockchain network

Installation

You can easily deploy the application by running:

./deploy.sh

Configuration

Environment Variables

Create a .env file with the following variables:

# Slack Configuration
SLACK_BOT_TOKEN=your-bot-token-here
SLACK_APP_TOKEN=your-app-token-here
SLACK_CHANNEL=#alerts

# Contract Configuration
CONTRACT_ADDRESS=your-contract-address-here
RPC_ENDPOINT=https://rpc.c4e.io
CHAIN_ID=perun-1

# Monitoring Configuration
CHECK_TIME=09:00  # Time for daily checks (24-hour format)

Slack App Configuration

  1. Create Slack App:

  2. Enable Socket Mode:

    • Go to "Socket Mode" in your app settings
    • Enable Socket Mode
    • Generate an App-Level Token with connections:write scope
    • This is your SLACK_APP_TOKEN
  3. Configure Bot:

    • Go to "OAuth & Permissions"
    • Add Bot Token Scopes:
      • chat:write - Send messages
      • commands - Use slash commands
      • app_mentions:read - Respond to mentions
      • files:write - Upload files (for lockups export)
    • Install app to workspace
    • Copy the "Bot User OAuth Token" as your SLACK_BOT_TOKEN
  4. Add Slash Commands (Optional):

    • Go to "Slash Commands"
    • Create command /check-contract
    • Description: "Check contract coin availability"
    • Create command /export-lockups
    • Description: "Export all lockups data as files"
  5. Enable Events:

    • Go to "Event Subscriptions"
    • Enable Events
    • Subscribe to app_mention bot event

Usage

Automatic Monitoring

The bot automatically runs daily checks at the configured time (CHECK_TIME). If coin availability is insufficient, it sends an alert like:

!! INSUFFICIENT COIN AVAILABILITY ALERT !!

Time: 2025-08-26 09:00:00
Contract: c4e.....
Status: Insufficient funds available for rewards

Available Rewards: 1000000 uc4e
Required Per Year: 2000000 uc4e
Active Lockups: 5
Total Principal: 10000000 uc4e

Action Required: Please deposit additional rewards.

Manual Checks

  1. Slash Command: Type /check-contract in any channel where the bot is present

  2. Mention: Mention the bot with "check" or "status":

    @Contract Monitor check status
    

Lockups Data Export

Export all lockups data from the contract as downloadable files:

  1. Slash Command: Type /export-lockups in any channel where the bot is present

  2. Mention: Mention the bot with "export" or "lockups":

    @Contract Monitor export lockups
    

The bot will upload two files to the channel:

  • JSON file: Raw lockups data in JSON format for programmatic use
  • CSV file: Spreadsheet-friendly format for analysis in Excel/Google Sheets

Example export message:

All Lockups Export
Time: 2025-08-26 14:30:00
Contract: c4e.....
Format: JSON/CSV

Daily Status Updates

The bot sends daily status updates showing:

  • Current coin availability status
  • Available reward funds
  • Required rewards per year
  • Number of active lockups
  • Total principal locked

Contract Queries Used

The bot uses these smart contract queries:

  1. CheckCoinAvailability: Main query to check if sufficient funds are available
  2. GetDepositedRewards: Get current available reward funds
  3. GetAllRewards: Get total required rewards per year
  4. GetSumLockupsAndDeposits: Get lockup statistics
  5. GetAllLockups: Retrieve all lockups data for export functionality

Logs

Logs are written to logs/slack_monitor_bot.log and include:

  • Daily check results
  • Error messages
  • Slack message sending status
  • Contract query responses

Debug Mode

To enable debug logging, modify the logging level in the script:

logging.basicConfig(level=logging.DEBUG, ...)

Customization

Export File Formats

The lockups export creates two file formats:

  1. JSON Format: Contains the raw contract response data, preserving all nested structures and data types.

  2. CSV Format: Flattened view of the data suitable for spreadsheet applications.

Changing Check Frequency

To check more frequently than daily, modify the schedule line:

# Check every hour
schedule.every().hour.do(daily_check)

# Check every 30 minutes
schedule.every(30).minutes.do(daily_check)

About

A Slack bot that utilizes lockup smart contract queries to display information, monitor lockups and send periodic alerts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors