Code Monkey home page Code Monkey logo

mm-blast's Introduction

Mattermost Direct Message Blaster

Send direct messages to a list of user IDs in Mattermost as a bot. This tool can be run as a standalone script or as an API server that listens for slash commands from Mattermost.

Prerequisites

  • Python 3.9+
  • Docker (optional, but recommended for deployment)
  • A Mattermost server with administrative access (for setting up the slash command)

Setup

  1. Clone this repository:

    git clone https://github.com/maxwellpower/mm-blast.git
    cd mm-blast
  2. Install the required Python packages:

    pip install fastapi uvicorn requests termcolor
  3. Set up the necessary environment variables. You can either export them directly or use an .env file. The required variables are:

    • MATTERMOST_URL: The URL of your Mattermost server.
    • BOT_API_KEY: The API key for your bot.
    • USER_IDS_OR_CSV_PATH: Either a comma-separated list of user IDs or a path to a CSV file containing user IDs.
    • MESSAGE or MESSAGE_FILE_PATH: The message to send. Can be provided directly as a string or as a path to a file containing the message.
    • RUN_MODE: Either "script" (default) for standalone mode or "api" for API server mode.
    • SHARED_SECRET: A secret key used to authenticate incoming API requests (only required for API mode).
    • VERIFY_SSL: Verify the SSL certificate. Default = true.

Usage

Standalone Script Mode

In this mode, the script will send messages to users based on the provided user IDs and message.

python main.py

API Server Mode with Mattermost Slash Command

  1. Start the API server:

    export RUN_MODE=api
    python main.py
  2. In Mattermost, go to Main Menu > Integrations > Slash Commands.

  3. Click Add Slash Command.

  4. Fill in the details:

    • Title: DM Blaster
    • Description: Send direct messages to a list of users.
    • Command Trigger Word: blast (or any other trigger word you prefer)
    • Request URL: http://<YOUR_SERVER_IP>:8000/send_message
    • Request Method: POST
    • Response Username: (Optional) The bot's username.
    • Autocomplete: Enable this and provide a hint like send to guide users.
  5. Click Save.

Now, in any Mattermost channel, you can use the slash command /blast send to trigger the message sending.

Using the Slash Command in Mattermost

Once you've set up the slash command in Mattermost (as described in the previous section), you can use it to send direct messages to multiple users. Here's how:

  1. Syntax:

    /blast send --users=<USER_IDS> --message=<MESSAGE>
    
    • <USER_IDS>: A comma-separated list of user IDs or hashes to whom you want to send the message.
    • <MESSAGE>: The message you want to send. You can format it using Mattermost's markdown syntax for richer content.
  2. Example:

    /blast send --users=user1ID,user2ID,user3ID --message=Hello! This is a *test* message.
    

    This will send the message "Hello! This is a test message." to the users with IDs user1ID, user2ID, and user3ID.

  3. Notes:

    • Ensure that you've set permissions in Mattermost to restrict the usage of the slash command to trusted roles.
    • The slash command will provide feedback in the channel or as a direct message to the admin, indicating the success or failure of the message sending process.

Docker Deployment

Run the Docker container:

docker run --env-file .env ghcr.io/maxwellpower/mm-blast

Running the Docker Container with Mounted Volumes

  1. Add your files to a local folder like "resources" and expose that folder to the app directory in the container.
docker run --env-file .env -v resources:/app ghcr.io/maxwellpower/mm-blast

Running the container in API/Slash Command mode

** Note: If you're running in API mode, make sure to expose port 8000 **

docker run --env-file .env -p 8000:8000 ghcr.io/maxwellpower/mm-blast
    requests.exceptions.SSLError: HTTPSConnectionPool(host='servicenow---sandbox.cloud.mattermost.com', port=443): Max retries exceeded with url: /api/v4/channels/direct (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

mm-blast's People

Contributors

maxwellpower avatar

Watchers

Stuart Doherty avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.