I have two scripts, which are written on telethon and aiogram. My telethon scripts resend massages from the groups and aiogram process them (will be completed later). Unfortunately, when both of scripts are executing simultaneously, that cause issues: aiogram responds to the resented message twice. I TRIED to make docker-containers and even run both of script on separate machines, but issue still persist. When only aiogram is running without telethon - everything is okey.
aiogram script:
import aiogram
import aiomysql
import asyncio
from aiogram import types, Bot, Dispatcher, executor
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.middlewares import BaseMiddleware
from aiogram.dispatcher.handler import CancelHandler
from aiogram.types import Update
from aiogram.types.chat_member import ChatMemberMember, ChatMemberOwner, ChatMemberAdministrator
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup
from aiogram.types import CallbackQuery
from aiogram.contrib.fsm_storage.memory import MemoryStorage
#from keyboard import get_inline_keyboard
TOKEN_API = "token)"
processed_messages = {}
storage = MemoryStorage()
bot = aiogram.Bot(TOKEN_API)
dp = aiogram.Dispatcher(bot, storage=storage)
@dp.message_handler()
async def process_forwarded_message(message: types.Message):
if message.message_id in processed_messages:
return
processed_messages[message.message_id] = True
buttons = [
aiogram.types.InlineKeyboardButton("Edit", callback_data=f"edit:{message.message_id}"),
aiogram.types.InlineKeyboardButton("Delete", callback_data=f"delete:{message.message_id}"),
aiogram.types.InlineKeyboardButton("Forward", callback_data=f"forward:{message.message_id}")
]
keyboard = aiogram.types.InlineKeyboardMarkup().row(*buttons)
await bot.send_message(chat_id=message.from_user.id,
text=message.text,
reply_markup=keyboard)
if __name__ == '__main__':
executor.start_polling(dp,
skip_updates=True)
telethon script
from telethon import TelegramClient, events
import asyncio
import aiogram
import aiomysql
Id_bot =
Id_Group2 =
Id_Group3 =
Id_Group4 =
Id_Group5 =
Id_Group6 =
api_id = ''
api_hash = ''
chats_to_listen_to = [Id_Group2, Id_Group3, Id_Group4, Id_Group5, Id_Group6]
client = TelegramClient('none', api_id, api_hash)
@client.on(events.NewMessage(chats=chats_to_listen_to))
async def new_message_handler(event):
if event.grouped_id:
return # ignore messages that are gallery here
await client.send_message(Id_bot, event.message)
@client.on(events.Album(chats=chats_to_listen_to))
async def album_handler(event):
await event.forward_to(entity=Id_bot, message=event.message)
client.start()
client.run_until_disconnected()