A Python library for handling support messages in Telegram bots. This library provides functions to forward user questions to a support group and send replies back to users.
Install directly from GitHub:
pip install git+https://github.com/dkustikx/support-lib.gitOr install a specific version/tag:
pip install git+https://github.com/dkustikx/support-lib.git@v0.1.0Or install from a local clone:
git clone https://github.com/dkustikx/support-lib.git
cd support-lib
pip install .from telegram.ext import Application, MessageHandler, filters
from support_lib import question, answer
import os
TOKEN = os.getenv("BOT_TOKEN")
GROUP_ID = int(os.getenv("SUPPORT_GROUP_ID"))
async def handle_user_message(update, context):
"""Handle messages from users"""
if update.message.chat.type == "private":
await question(update, GROUP_ID, TOKEN)
async def handle_group_reply(update, context):
"""Handle replies in support group"""
if update.message.chat.id == GROUP_ID and update.message.reply_to_message:
await answer(update, TOKEN)
def main():
app = Application.builder().token(TOKEN).build()
app.add_handler(MessageHandler(
filters.TEXT & filters.ChatType.PRIVATE,
handle_user_message
))
app.add_handler(MessageHandler(
filters.TEXT & filters.ChatType.GROUPS,
handle_group_reply
))
app.run_polling()
if __name__ == "__main__":
main()Forwards a user's message to the support group.
- update: Telegram Update object
- group_id: Support group chat ID
- token: Bot token
- Returns: Tuple of (user_chat_id, group_message_id) or None on error
Sends a support group reply back to the original user.
- update: Telegram Update object (reply in support group)
- token: Bot token
- Returns: True if successful, False on error
- Python 3.8+
- python-telegram-bot >= 20.0
MIT