{"id":15714359,"url":"https://github.com/conjikidow/slack-notifier","last_synced_at":"2025-03-30T19:46:52.654Z","repository":{"id":245635502,"uuid":"818804867","full_name":"conjikidow/slack-notifier","owner":"conjikidow","description":"A simple Python package for sending Slack notifications","archived":false,"fork":false,"pushed_at":"2025-03-29T04:24:10.000Z","size":356,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T05:22:25.082Z","etag":null,"topics":["notifications","slack"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/conjikidow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-22T23:21:38.000Z","updated_at":"2025-03-29T04:24:13.000Z","dependencies_parsed_at":"2024-06-23T05:05:45.231Z","dependency_job_id":"b774e08f-f8e7-4282-a56e-081b583b783a","html_url":"https://github.com/conjikidow/slack-notifier","commit_stats":null,"previous_names":["conjikidow/slack-notifier"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conjikidow%2Fslack-notifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conjikidow%2Fslack-notifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conjikidow%2Fslack-notifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conjikidow%2Fslack-notifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conjikidow","download_url":"https://codeload.github.com/conjikidow/slack-notifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246372502,"owners_count":20766625,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["notifications","slack"],"created_at":"2024-10-03T21:36:19.505Z","updated_at":"2025-03-30T19:46:52.647Z","avatar_url":"https://github.com/conjikidow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slack Notifier Package\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![CI](https://github.com/conjikidow/slack-notifier/actions/workflows/ci.yaml/badge.svg)](https://github.com/conjikidow/slack-notifier/actions/workflows/ci.yaml)\n\nThis package provides a simple interface to send notifications to Slack using the Slack SDK for Python.\n\n## Installation\n\nInstall the package using [uv](https://github.com/astral-sh/uv) is recommended.\nRun the following command to add the package to your project:\n\n```console\nuv add git+https://github.com/conjikidow/slack-notifier\n```\n\nThen you can import the package in your Python code:\n\n```python\nfrom slack_notifier import SlackNotifier\n```\n\n## Usage\n\n### Example Usage\n\nHere is an example of how to use the `SlackNotifier` class to send a message to Slack:\n\n```python\nimport logging\nfrom pathlib import Path\n\nfrom slack_notifier import SlackNotifier\n\n\ndef main() -\u003e None:\n    channel = \"#slack-channel\"  # Specify the Slack channel name (with #) or ID\n    username = \"slack-username\"  # Optional: Provide the username for sending the message\n    token_env_var = \"SLACK_API_TOKEN\"  # Optional: Defaults to \"SLACK_TOKEN\", or specify your own environment variable name\n\n    # Initialize SlackNotifier with the channel, optional username, and optional token environment variable name\n    notifier = SlackNotifier(channel, username=username, token_env_var=token_env_var)\n\n    message = \"Hello from your Slack notifier!\"  # The message to send\n    notifier.send_message(message)  # Send the message to Slack\n\n    attachments = [\n        Path(\"tests/data/test_file.txt\"),\n        Path(\"tests/data/test_file.png\"),\n    ]\n    message = \"Hello from your Slack notifier with file attachments!\"\n    notifier.send_message(message, attachments=attachments)  # Send the message with file attachments\n\n\nif __name__ == \"__main__\":\n    logging.basicConfig(level=logging.INFO)\n\n    main()\n```\n\n### Explanation\n\n- Replace `\"#slack-channel\"` and `\"slack-username\"` with your actual Slack channel (name or ID) and username (if applicable).\n- The `SlackNotifier` class will automatically try to load the Slack API token from the environment variable:\n  - By default, it looks for the `SLACK_TOKEN` environment variable.\n  - You can specify a different environment variable name using the `token_env_var` parameter.\n  - If the token is not found in the environment variable, the class will attempt to load it from the `.env` file (if present).\n  - If no token is found in either the environment variable or `.env` file, an error will be raised.\n- The `SlackNotifier` class initializes a Slack client with the loaded token and sends a message to the specified channel using the `send_message` method.\n- If the username is provided, it will be used as the sender of the message; otherwise, the default sender will be used.\n- If file paths are provided in the `attachments` parameter, the files will be uploaded as attachments to the message.\n\n### Obtaining Your Slack API Token\n\nTo use the Slack API, you need to create a Slack App and generate a bot token. Follow these steps:\n\n1. **Create a Slack App**:\n   - Go to [Slack API: Your Apps](https://api.slack.com/apps).\n   - Click on the **Create New App** button.\n   - Select either **From scratch** or **Using an app manifest** to create your app. Provide the necessary details, such as the name of your app and the workspace where you want it installed.\n\n2. **Set Up Permissions**:\n   - Once your app is created, navigate to the **OAuth \u0026 Permissions** section under the **Features** tab.\n   - Here, you will define the **Bot Token Scopes** that your app requires. For sending messages, you need at least the following permissions:\n     - `chat:write` - Send messages to channels.\n     - `chat:write.customize` - Send messages with a custom username and avatar (optional, but required when specifying a custom username).\n     - `files:write` - Upload files (optional, but required for sending file attachments).\n\n     ![Image](https://github.com/user-attachments/assets/b80548d0-392d-4524-906c-d870bb53e02c)\n\n3. **Install the App**:\n   - Go to the **Install App** section in the left sidebar of your app's settings.\n   - Click **Install to Workspace** to install the app to your Slack workspace.\n   - You’ll be prompted to authorize the app. Once authorized, you’ll be given an **OAuth Access Token** (starts with `xoxb-`), which is the token you will use for API requests.\n\n4. **Set the Token as an Environment Variable**:\n   - You can set the obtained OAuth token as an environment variable called `SLACK_TOKEN`. Alternatively, you can specify a different environment variable name by passing it to the `SlackNotifier` class.\n\nFor more details, visit the [Slack API Authentication Documentation](https://api.slack.com/authentication).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconjikidow%2Fslack-notifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconjikidow%2Fslack-notifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconjikidow%2Fslack-notifier/lists"}