A Telegram bot for the Angel & Mortal game, where participants can communicate anonymously with their assigned "angel" or "mortal." The bot manages user interactions and tracks data using Google Sheets.
Developed using the latest v20 version of python telegram bot: https://github.com/python-telegram-bot/python-telegram-bot
- User registration and chat initiation
- Anonymous messaging between participants
- Game instructions and announcements
- Google Sheets integration for data storage and retrieval
Before you begin, ensure you have met the following requirements:
- Python 3.9 or later
- A Telegram Bot API token (from BotFather)
- Google Cloud account with access to Google Sheets API
- A service account with
creds.json
containing your Google Sheets credentials
To set up Google Cloud authentication for accessing the Google Sheets API, follow these steps:
-
Create a Google Cloud Project:
- Go to the Google Cloud Console.
- Click on "Select a Project" and then "New Project."
- Enter a project name and click "Create."
-
Enable the Google Sheets API:
- In the Google Cloud Console, navigate to the "APIs & Services" > "Library."
- Search for "Google Sheets API" and click on it.
- Click "Enable" to activate the API for your project.
-
Create a Service Account:
- Go to "APIs & Services" > "Credentials."
- Click on "Create Credentials" and select "Service Account."
- Fill in the service account name and description, then click "Create."
- On the next page, click "Done."
-
Create a JSON Key:
- Find your newly created service account in the list and click on it.
- Click on the "Keys" tab, then "Add Key" > "Create New Key."
- Choose "JSON" and click "Create." This will download a JSON file containing your service account credentials.
-
Share the Google Sheet:
- Open your Google Sheet (request [email protected] for a sample google sheet format).
- Click the "Share" button.
- Add the service account email (found in the downloaded JSON file) with at least "Viewer" permissions.
-
Set Up Environment Variable:
- Copy the contents of the JSON file and set it in your
.env
file as follows:
GOOGLE_KEY='{"type": "service_account", "project_id": "your-project-id", ...}'
- Copy the contents of the JSON file and set it in your
This document outlines the steps to create a Telegram bot using BotFather and obtain the necessary API token for your bot.
-
Open Telegram
Launch the Telegram app or visit the Telegram Web interface.
-
Find BotFather
- In the search bar, type
@BotFather
. - Click on the BotFather bot to open a chat.
- Start a New Bot
- Send the command
/newbot
to BotFather. - Follow the prompts:
- Choose a name for your bot (this can be anything you like).
- Choose a username for your bot (must end with
bot
, e.g.,example_bot
).
- Receive Your API Token
- After successfully creating the bot, BotFather will provide you with an API token.
- Keep this token safe, as it is required for your bot to authenticate with the Telegram API.
- Set Up Environment Variable
-
Store your API token in your project’s
.env
file (or any configuration method you prefer) as follows:API_KEY=your_telegram_bot_api_token
-
Clone the repository:
git clone https://github.com/yourusername/angel-mortal-bot.git cd angel-mortal-bot
-
Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Create Environment Variables Create a .env file in the project root:
API_KEY=your_telegram_bot_api_key GOOGLE_KEY='your_google_service_account_credentials_json_string' ANGEL_BOT_TOKEN=your_angel_bot_token
-
Set up Google Sheet
Create a Google Sheet for the game and share it with your service account email. Ensure your sheet has the necessary columns to store user data.
-
Run the Bot (locally)
python bot.py
-
Deploy Bot on Heroku / Google Cloud / AWS
- Start the bot on Telegram by sending the /start command.
- Use commands like /angel, /mortal, /help, and /checkinfo to interact with the bot.
- Participants will be paired with an angel and a mortal (as per the pairings on google sheet), allowing anonymous communication.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes.
- Commit your changes (git commit -m 'Add new feature').
- Push to the branch (git push origin feature-branch).
- Open a pull request.
- python-telegram-bot for the Telegram Bot API wrapper.
- gspread for interacting with Google Sheets.