How to launch and proper operation of Pyrogram and Aiogram

104 views Asked by At

The problem is that the bot doesn't work as it should.

I want to make a bot parser that will copy all new and incoming messages on the account and send them to the chat bot with the signature “From”

It basically doesn’t work for me, I don’t really understand asynchrony yet, but I was suggested to run the main() function this way

If you put pyrogram first to run, then only it works and vice versa

import asyncio

from data import API_ID, API_HASH, TOKEN

from pyrogram import Client, filters
from pyrogram.types import Message
from aiogram import Bot, Dispatcher, types, filters

app = Client(api_hash=API_HASH, api_id=API_ID)
bot = Bot(TOKEN)
dp = Dispatcher()

@dp.message(filters.CommandStart)
async def start(message: types.Message):
    await message.answer(text="Welcom to Parser Bot")

async def parse(parse_message, username):
    await bot.send_message(chat_id=types.Message.chat.id, text=f"from {username}\n\n{parse_message}")

@app.on_message()
async def get_message(client: Client, message: Message):
    parse_message = message.text
    parse_username = message.from_user.username

    asyncio.run(parse(parse_message, parse_username))

async def main():
    await asyncio.gather(
        app.run(),
        dp.start_polling(bot)
    )

if __name__ == "__main__":
    asyncio.run(main())

I tried to find similar examples, but all of them only parse the entire history of chat or subscriptions on a Telegram channel or chat

Perhaps you can make both a chat bot and a parser bot only through Pyrogram?

Also, if you can help, please show me the example code.

0

There are 0 answers