С aiogram у меня так и не сраслось, но получилось с telethon
import redis
import asyncio
from telethon import TelegramClient, events
import config as cfg
bot = TelegramClient('xxx', cfg.api_id, cfg.api_hash)
@bot.on(events.NewMessage())
async def echo(event):
await bot.send_message(event.chat.id, event.text)
async def botrun():
await bot.start(bot_token=cfg.bot_token)
await bot.run_until_disconnected()
async def redisrun():
r = redis.Redis(host=cfg.REDIS_HOST, port=6379, db=0)
p = r.pubsub()
p.subscribe('test')
while True:
mes = p.get_message()
if mes:
print(str(mes['data']))
await asyncio.sleep(1)
async def main():
f1 = loop.create_task(redisrun())
f2 = loop.create_task(botrun())
await asyncio.wait([f1, f2])
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())