A simple Telegram bot that lets users send and respond to proposals via inline keyboard buttons. This bot is built using Python and the python-telegram-bot
library with SQLite as the database backend.
- User Registration:
- Registers users by saving their
chat_id
andusername
when they start the bot.
- Registers users by saving their
- Proposal System:
- Users can propose to others by their Telegram username.
- Sends proposals with inline keyboard buttons for "Yes" and "No" responses.
- Notifies proposers of the response.
- Database Integration:
- Stores user data (
chat_id
,username
) in an SQLite database.
- Stores user data (
- Async Operations:
- Fully asynchronous, leveraging
asyncio
for efficient handling of Telegram API requests.
- Fully asynchronous, leveraging
- Python 3.9 or higher
- Telegram bot token (create a bot via BotFather)
- Required Python libraries (install with the steps below)
-
Clone the repository:
git clone https://github.com/nightfullstar/willyoumarryme_bot_telegram.git cd willyoumarryme_bot_telegram
-
Install dependencies:
pip install -r requirements.txt
-
Replace
YOUR_BOT_TOKEN
in the code with your Telegram bot token. -
Run the bot:
python wymm_bot.py
If you are running the bot in a Jupyter Notebook or an environment with an existing event loop, nest_asyncio
is used to allow nested event loops.
- Registers the user in the database.
- Sends a welcome message.
- Sends a proposal to the specified username.
- The target user receives a message with "Yes" and "No" buttons.
- Notifies the proposer of the response.
- User Registration:
- When a user sends
/start
, theirchat_id
andusername
are stored in an SQLite database.
- When a user sends
- Sending Proposals:
- The
/propose <username>
command fetches the target user’schat_id
from the database and sends a proposal message. - Inline keyboard buttons allow the recipient to accept or decline the proposal.
- The
- Callback Responses:
- Handles button presses to notify the proposer of the recipient’s decision.
- Notifies the sender if the target user hasn’t registered with the bot.
- Handles exceptions during message sending or database operations.
The SQLite database (users.db
) contains a single table:
CREATE TABLE users (
chat_id INTEGER PRIMARY KEY,
username TEXT
);
Install the required libraries:
pip install python-telegram-bot nest-asyncio
bot.py
: Main script containing the bot logic.users.db
: SQLite database file for storing user data.requirements.txt
: Dependencies for the project.
Run the bot with:
python bot.py
- Start a conversation with the bot using
/start
. - Use
/propose <username>
to send a proposal to another registered user.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to open an issue or submit a pull request with improvements or bug fixes.
- Built with the python-telegram-bot library.
- Inspired by the need for fun and interactive Telegram experiences, used it on my wife(she said yes)