异步电报bot api
atbot的Python项目详细描述
异步电报bot
此项目允许您使用Python3创建异步电报机器人。
目前api比较稀疏,可以通过pull请求或提交问题添加更多方法。
开始
使用
获取源git
git clone https://github.com/naim94a/atbot.git
使用
安装pip
pip install atbot
示例
importosimportasynciofromatbotimportTelegramBot,TelegramMessage,ChatActionAPI_KEY=os.getenv('API_KEY')asyncdefhandle_message(bot,msg):ifmsg.text=='/start':awaitbot.send_chat_action(msg.chat.id,ChatAction.TYPING)awaitasyncio.sleep(0.2)awaitbot.send_message(msg.chat.id,'Hello, {0}!'.format(msg.sender.first_name))asyncdefmy_bot():bot=TelegramBot(API_KEY)whileTrue:updates=awaitbot.get_updates()forupdateinupdates:obj=update.get_obj()ifisinstance(obj,TelegramMessage):awaithandle_message(bot,obj)asyncio.run(my_bot())