This Slack Bot fetches publications for authors from Google Scholar and sends notifications to a specified Slack channel with details of the latest publications. Keep your team updated with the latest scholarly articles seamlessly!
- 🤖 Setting Up Your Slack Bot
- 📚 Installing Required Libraries
- 🔧 Setting Up The Repo
- 🚀 Usage
- 📂 Directory Structure
- 📝 Files Descriptions
- 📄 License
- Go to the Slack API's "Your Apps" page.
- Click the Create New App button.
- Name your app, select the development workspace you want to use (you can create a new workspace if needed), and then click Create App.
- In your app's settings, go to the Bot Users feature and click Add a Bot User.
- Name your bot and enable it to be always online.
Slack apps use scopes to request specific sets of permissions. To send messages to channels, the bot needs particular scopes.
- Navigate to the OAuth & Permissions page in your app settings.
- Under the Scopes section, add the following bot token scopes:
channels:read
- To view basic information about public channels in the workspace.chat:write
- To send messages to channels.
It's essential to only request the permissions necessary for your bot to function, following the principle of least privilege.
- Still on the OAuth & Permissions page.
- Under the OAuth Tokens for Your Workspace section, you'll see a token that starts with
xoxb-
. This is your bot's API token. - Save this token securely. You'll need it for your
slack.config
file. Remember, never commit this token to public repositories for security reasons.
- Go to your Slack workspace.
- Navigate to the channel you want the bot to post messages in.
- Click on the channel name at the top, and select Add people & bots.
- Search for your bot's name and invite it.
Before you can run the project, you need to install some necessary libraries. To install the necessary libraries using pip
, you can run the following commands:
pip install scholarly tqdm requests configparser
Clone this repository:
git clone costantinoai/scholar-slack-bot
cd scholar-slack-bot
Ensure you have all required dependencies installed:
pip install -r requirements.txt
Now, populate slack.config
file with your bot's API token, channel name, and channel ID. The structure should look like:
[slack]
api_token = xoxb-YOUR-API-TOKEN
channel_name = YOUR-CHANNEL-NAME
Add author details in src/authors.json
or src/authors_short.json
.
With everything set up, you can now run the code. The bot will send messages to the Slack channel based on the fetched publications.
The script accepts several command-line arguments (flags) to customize its behavior:
-
--authors_path
: Specifies the path to theauthors.json
file.- Default:
./src/authors.json
- Example:
python main.py --authors_path="./path/to/your/authors.json"
- Default:
-
--slack_config_path
: Sets the path to theslack.config
file which contains Slack API token and channel information.- Default:
./src/slack.config
- Example:
python main.py --slack_config_path="./path/to/your/slack.config"
- Default:
-
--verbose
: (Optional) Provides verbose output for detailed logging and debugging.- Example:
python main.py --verbose
- Example:
-
--test_fetching
: (Optional) Test fetching functions. Do not send message (unless --test_message) or save cache. Mutually exclusive with--add_scholar_id
and--update_cache
.-
Example (fetch only): Fetch last year's data for two authors in
./src/authors.json
. Do not send messages or update cache.python main.py --test_fetching
-
Example (fetch and send message) Fetch last year's data for two authors in
./src/authors.json
. Send messages with fetched papers, but do not update cache.python main.py --test_fetching --test_message
-
-
--test_message
: (Optional) Send test message. Do not fetch, send message (unless --test_fetching) or save cache. Mutually exclusive with--add_scholar_id
and--update_cache
.- Example:
python main.py --test_message
- Example:
-
--add_scholar_id
: (Optional) Add a new scholar by Google Scholar ID to the file specified in--authors_path
, fetch publications and save them to cache (do not send message). Mutually exclusive with--test_message
,--test_fetching
and--update_cache
.- Example:
python main.py --add_scholar_id="YourGoogleScholarID"
- Example:
-
--update_cache
: (Optional) Re-fetch and save publications for all authors (do not send message). It overwrites the old cache. Mutually exclusive with--test_message
,--test_fetching
and--add_scholar_id
.- Example:
python main.py --update_cache
- Example:
If you're running the script from an IDE, the default settings are taken from hardcoded configurations in the IDEargs
class in the main()
function of main.py
. If you need to adjust paths or enable the debug mode for IDE execution, modify the corresponding variables in the main()
function.
slack-bot
├── add_authors_batch.sh
├── fetch_and_send.sh
├── fetch_scholar.py
├── helper_funcs.py
├── log_config.py
├── main.py
├── README.md
├── slack_bot.py
├── streams_funcs.py
└── src
├── authors.json
├── googleapi_cache
└── slack.config
-
add_authors_batch.sh: Bash script to add authors in batch. You need to set the correct
ids
, conda environment and conda.sh path to use this script. -
fetch_and_send.sh: Bash script to run the main workflow with default flags. You need to set the correct conda environment and conda.sh path to use this script.
-
fetch_scholar.py: Functions to fetch comprehensive details for scholarly publications.
-
helper_funcs.py: Collection of helper functions.
-
log_config.py: Set logging levels for all the scripts.
-
main.py: The main script. Run this file from terminal or IDE to run the bot.
-
slack_bot.py: Functions to connect to format and send messages to a Slack channel.
-
streams_funcs.py: Functions for every branch/scenario in main.py (depending on the active flags).
-
authors.json: A file containing the list of authors' names and their corresponding Google Scholar IDs. Here's how you should structure the contents:
[ {"name": "Daniel Kaiser", "id": "v4CvWHgAAAAJ"}, {"name": "Stefania Bracci", "id": "ECBBsv8AAAAJ"} ]
-
authors.json: Similar to
authors.json
, but with less authors and few missing publications. For debug purpose only (see Usage -> Flags ->--debug
) -
googleapi_cache: A directory that caches publication data fetched from Google Scholar for each author. This helps in speeding up subsequent fetches and reduces unnecessary API calls.
-
slack.config: Configuration file that contains Slack-related settings such as the API token and channel details. Make sure to structure the contents as:
[slack] api_token = xxx-xxxxxxxxxx channel_name = your-channel-name channel_id = optional-ch-id
Always remember to keep your slack.config file secure and never commit sensitive data, like your API token, directly to public repositories.
Want to know more about each function? Check out their respective files for in-depth comments!
MIT © Andrea Ivan Costantino