Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

support-lib

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.

Installation

Install directly from GitHub:

pip install git+https://github.com/dkustikx/support-lib.git

Or install a specific version/tag:

pip install git+https://github.com/dkustikx/support-lib.git@v0.1.0

Or install from a local clone:

git clone https://github.com/dkustikx/support-lib.git
cd support-lib
pip install .

Usage

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()

API Reference

question(update, group_id: int, token: str) -> Optional[Tuple[int, int]]

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

answer(update, token: str) -> bool

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

Requirements

  • Python 3.8+
  • python-telegram-bot >= 20.0

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages