/
BorisPlus
/
Telegram-Bot-Discussion-Examples
Обзор
Документация
Войти
/
BorisPlus
/
Telegram-Bot-Discussion-Examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
examples/hello_world_bot/main.py
51 строка
1 KB
b
2025_10_13_initial
13 окт 2025, 00:05
13 окт 2025, 00:05
0fc4405
Код
Авторство
О чём код?
from optparse import OptionParser from telegram import Update from telegram.ext import CallbackContext from telegram_bot_discussion import Discussion, Contextual from telegram_bot_discussion.config import Config from telegram_bot_discussion.ext.logger import LogLevel, Printer from telegram_bot_discussion.handlers import ReplicasHandler from telegram_bot_discussion.functions import get_chat_id class HelloWorldBotReplicasHandler(ReplicasHandler): async def when_there_are_no_any_dialog( self, update: Update, context: CallbackContext, ): discussion: Discussion = Contextual[Discussion](context)() await discussion.bot().send_message( get_chat_id(update), "Hello world, I am Telegram Bot Discussion!", ) def main(): usage = "usage: %prog -t/--token <token>" parser = OptionParser(usage=usage) parser.add_option( "-t", "--token", help="Telegram bot-API token", ) (options, _) = parser.parse_args() Discussion( logger=Printer( name="hello_world_bot", level=LogLevel.DEBUG, ), config=Config(token=options.token), ).set_replicas_handler(HelloWorldBotReplicasHandler()).start() # cd examples # python3 ./hello_world_bot/main.py -t <token> if __name__ == "__main__": main()