This Python program automatically detects incoming emails, drafts AI-generated replies, and saves them as drafts for manual review and sending. It's designed to run continuously using GitHub Actions and can be customized for the Artificial Intelligence Society's needs.
- Automatic email checking using Gmail API
- AI-powered response generation using Google's Generative AI
- Customizable AI prompts with example replies
- Separate file for easily editable society information
- Creation of draft replies instead of automatic sending
- Configurable email checking frequency and processing limits
- Error handling and logging for improved reliability
- Continuous running capability using GitHub Actions
-
Clone this repository to your local machine or fork it to your GitHub account.
-
Set up a Google Cloud Project and enable the Gmail API:
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API for your project
- Create OAuth 2.0 credentials (Desktop app) and download the client configuration as
credentials.json
-
Install the required Python packages locally for testing:
pip install -r requirements.txt -
Configure the
config.yamlfile:- Update the
email_addressfield with your Gmail address - Customize the
ai_promptas needed - Adjust the
check_frequencyandmax_emails_per_cycleas desired
- Update the
-
Edit the
society_info.txtfile:- Add detailed information about your Artificial Intelligence Society
- Include goals, activities, membership benefits, and contact information
-
Set up GitHub Secrets:
- In your GitHub repository, go to Settings > Secrets and variables > Actions
- Add the following secrets:
EMAIL_ADDRESS: Your Gmail addressGOOGLE_API_KEY: Your Google API key for the Generative AI modelGOOGLE_CREDENTIALS: The contents of yourcredentials.jsonfile, base64 encoded
-
Push your changes to GitHub:
git add . git commit -m "Set up AI Email Reply Bot" git push
The bot is configured to run automatically every 15 minutes using GitHub Actions. You can also trigger it manually:
- Go to your GitHub repository
- Click on the "Actions" tab
- Select the "Run Email Replier" workflow
- Click "Run workflow"
To test the bot locally:
-
Ensure you have the
credentials.jsonfile in your project directory -
Run the script:
python email_replier.py -
The first time you run the script, it will prompt you to authorize access to your Gmail account. Follow the instructions in the console.
You can customize the AI's behavior by modifying the following files:
-
config.yaml:- Adjust the
ai_promptto change how the AI generates responses - Modify the example reply to match your preferred style
- Change
check_frequencyandmax_emails_per_cycleto control email processing
- Adjust the
-
society_info.txt:- Update this file with the latest information about your society
- The AI will use this information when generating replies
The program creates draft replies instead of sending them automatically. To review and send the drafts:
- Log into your Gmail account
- Go to the Drafts folder
- Review each draft, make any necessary edits
- Send the emails manually when you're satisfied with the content
The program logs its activities and any errors to email_replier.log. You can view these logs in the GitHub Actions run details.
Ensure that your config.yaml file and credentials.json are kept secure and not shared publicly, as they contain sensitive information. The GitHub Secrets feature is used to securely store and use these credentials in the GitHub Actions workflow.
This program interacts with email accounts and uses AI to generate responses. Please use it responsibly and in compliance with all relevant laws and regulations. Always review the AI-generated drafts before sending to ensure they meet your standards and accurately represent your society.