Giter Club home page Giter Club logo

Comments (24)

khoben avatar khoben commented on August 29, 2024

Please try now -1001#1 for the default topic

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

Hey, thank you for resolving this issue I wanted to ask u one more thing while forwarding messages from groups is it possible to forward the original message sender's username too?

from telemirror.

khoben avatar khoben commented on August 29, 2024

Hey, thank you for resolving this issue I wanted to ask u one more thing while forwarding messages from groups is it possible to forward the original message sender's username too?

There are two options here: don't copy, but forward (mode option), or use ForwardFormatFilter (set filter in yaml configuration).

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

i tried forward mode but the replies don't work in it, is it possible to get usernames in a specific channel using copy mode?

from telemirror.

khoben avatar khoben commented on August 29, 2024

i tried forward mode but the replies don't work in it, is it possible to get usernames in a specific channel using copy mode?

If you need to forward from a chat, you will need to create a filter like https://github.com/khoben/telemirror/blob/master/telemirror/messagefilters/messagefilters.py#L213, but instead of channel_name (https://github.com/khoben/telemirror/blob/master/telemirror/messagefilters/messagefilters.py#L253) get the user name from the message object.

Getting username from message:

message_sender = await message.get_sender()
message_sender_name = utils.get_display_name(message_sender) # or message_sender.username

from telemirror.

khoben avatar khoben commented on August 29, 2024

Check updates to ForwardFormatFilter

Sample configuration:

directions:
  - from: [-1001#3]
    to: [-1002#1]
    filters:
      - ForwardFormatFilter:
          format: "{sender_title} {sender_username} says:\n\n{message_text}"

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

working, thank you so much <3<3

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

Hey khoen, sorry to diusturb you again. I'm using this restricted channel filter

`class RestrictSavingContentBypassFilter(MessageFilter):
def init(self, send_restricted_content=True):
self.send_restricted_content = send_restricted_content

async def _process_message(
    self, message: EventMessage, event_type: Type[EventLike]
) -> Tuple[bool, EventMessage]:
    if message.chat.noforwards and message.media:
        # Handle images
        
        if isinstance(message.media, types.MessageMediaPhoto):
            client: TelegramClient = message.client
            photo: bytes = await client.download_media(message=message, file=bytes)
            cloned_photo: types.TypeInputFile = await client.upload_file(photo)
            message.media = cloned_photo
        # Others media types set to None (remove from original message)...
        else:
            message.media = None

    return True, message`
    
    to forward messages from restricted channels or groups but when someone in restricted group topics sends an image its sends this error
    
   `ERROR 2024-03-07 00:43:03,782 [mirroring.py:175]:telemirror: Error while sending message to chat#-1002068277802. ChatForwardsRestrictedError: You can't forward messages from a protected chat (caused by SendMediaRequest)`

texts are being forwarded but no the attachments in group topics

from telemirror.

khoben avatar khoben commented on August 29, 2024

Try logging the line where the media should be downloaded and replaced. More likely "if" gives False in your case.

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

still couldn't figure it out, could u help me with what I'm doing wrong?

from telemirror.

khoben avatar khoben commented on August 29, 2024

Can you show your config and the changes you made?

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

I added the restricted filter in messagefilter.py and

class MessageFilter(Protocol):
@Property
def restricted_content_allowed(self) -> bool:
"""Indicates that restricted content is allowed or not to process"""
return True
and changes this to true

from telemirror.

khoben avatar khoben commented on August 29, 2024

Just checked, everything works. To begin with, I want to say that forwarding from channels where this is prohibited violates the Telegram Terms of Service.
But for testing purposes you should change the _process_message method to sample implementation from docstring and then use the RestrictSavingContentBypassFilter filter in the config.
To make the filter importable, add to telemirror/messagefilters/__init__.py:

from .restrictsavingfilter import RestrictSavingContentBypassFilter  # noqa: F401

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

Thank you for the help it worked but, its sending images as file
image

from telemirror.

khoben avatar khoben commented on August 29, 2024

Thank you for the help it worked but, its sending images as file
image

You can try to wrap downloaded bytes with:

message.media = types.InputMediaUploadedPhoto(file=cloned_photo)

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

Now I'm getting this error: PhotoExtInvalidError: The extension of the photo is invalid (caused by SendMediaRequest)

from telemirror.

khoben avatar khoben commented on August 29, 2024

Haven't tested it, but maybe taking the file name from the source message could help:

cloned_photo: types.TypeInputFile = await client.upload_file(photo, file_name=message.file.name)
message.media = types.InputMediaUploadedPhoto(file=cloned_photo)

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

Still getting the same error

from telemirror.

khoben avatar khoben commented on August 29, 2024

In what environment is the program running? OS/docker, python version and through which telegram client are messages with images sent?

from telemirror.

khoben avatar khoben commented on August 29, 2024

It would also be great if you sent the images themselves as files here

from telemirror.

corpsepapi avatar corpsepapi commented on August 29, 2024

In what environment is the program running? OS/docker, python version and through which telegram client are messages with images sent?
Windows OS
Python Version: 3.12.2

from telemirror.

khoben avatar khoben commented on August 29, 2024

Really idk why images are sent like random files or with error. Couldn't get the same behavior. Try running via docker or check that all dependencies are updated: pip install -r requirements.txt

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on August 29, 2024

Hi did you fix that ?

from telemirror.

khoben avatar khoben commented on August 29, 2024

@corpsepapi You may try to specify the name for cloned_photo if it is still relevant for you #68 (comment)

from telemirror.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.