예제 #1
0
def forward(update, context):
message = update.effective_message  # type: Optional[Message]
    from_chat_id = update.effective_chat.id
    from_chat_name = update.effective_chat.title or update.effective_chat.first_name

    for chat in TO_CHATS:
     to_chat_name = context.bot.get_chat(chat).title or context.bot.get_chat(chat).first_name
        try:
         context.bot.forward_message(chat_id=chat, from_chat_id=from_chat_id, message_id=message.message_id)
               
               except:
            LOGGER.exception("Error while forwarding message from chat \"{}\" to chat \"{}\".".\
                             format(from_chat_name, to_chat_name))
예제 #2
0
def forward(update: Update, context: CallbackContext):
    message = update.effective_message
    chat = update.effective_chat
    if not message or not chat:
        return
    from_chat_name = chat.title or chat.first_name

    for chat in TO_CHATS:
        to_chat_name = (context.bot.get_chat(chat).title
                        or context.bot.get_chat(chat).first_name)
        try:
            send_message(message, chat)
        except ChatMigrated as err:
            send_message(message, err.new_chat_id)
            LOGGER.warning(
                f"Chat {chat} has been migrated to {err.new_chat_id}!! Edit the config file!!"
            )
        except:
            LOGGER.exception(
                'Error while forwarding message from chat "{}" to chat "{}".'.
                format(from_chat_name, to_chat_name))