Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use editMessageMedia to keep daily announcements updated #111

Open
nmlorg opened this issue Nov 13, 2024 · 2 comments
Open

Use editMessageMedia to keep daily announcements updated #111

nmlorg opened this issue Nov 13, 2024 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@nmlorg
Copy link
Owner

nmlorg commented Nov 13, 2024

https://core.telegram.org/bots/api#october-31-2024:

  • Introduced the ability to add media to existing text messages using the method editMessageMedia.
  • Can you remove media?
  • What happens if the length of the text is greater than the caption limit?
  • Can you still use editMessageText to change the text, or do you have to use editMessageCaption after adding an image?
  • If you sendMessage(text='a' * 2000), then editMessageMedia to add a picture, does it fail, does it change to a message with caption='a' * 2000, does it change to a message with caption='a' * 1024, or what?
  • If it changes to caption='a' * 2000, can you editMessageCaption(caption='b' * 2000)? Can you edit it at all, or is it stuck? Can you remove the image, edit the text, then readd the image?

Depending on how this turns out, I'd like to start sending all announcements as text messages, immediately editing them to add media (if appropriate), and also keeping media updated (including removing it) as event titles/etc. change.

@nmlorg nmlorg added bug Something isn't working enhancement New feature or request labels Nov 13, 2024
@nmlorg nmlorg self-assigned this Nov 13, 2024
@nmlorg
Copy link
Owner Author

nmlorg commented Nov 14, 2024

(After a power outage just for fun…)

Calling editMessageMedia on a sendMessaged message converts it to a media message altogether, and its existing text is simply discarded. If you want it to have text, you have to supply a caption= to editMessageMedia (as part of the media= argument).

  • Setting media.media=None, ='', or sending a media= without an internal media= all emit a 400 from TBA.
  • The initial text is discarded, so its length is irrelevant.
  • editMessageText on a converted message throws a 400 ("there is no text in the message to edit").
  • The initial text is discarded.
  • The caption appears to follow all existing rules.

So this would be a one-way process:  If the record for a message that didn't include any image when sent is changed so that the message would have included an image if it were sent now, we can go ahead and add the image. That's it 🙁.

@nmlorg
Copy link
Owner Author

nmlorg commented Nov 26, 2024

I think I need to record the current [source] image in records. (Even if you send a photo by URL, it is returned in the Message as an array of file_ids, so that's currently all that's recorded in records.)

I already kinda half-assed #97 (comment):

key = (botuser, groupid)
if key in records:
last = Announcement(*records[key])
else:
last = None

without getting the futureproofing I actually wanted:
for key, record in records.items():
botuser, unused_groupid = key
if botuser != 'alerts' and len(record) == 3:
records[key] += ('', '')

so I'd need to do something like:

            if botuser != 'alerts' and len(record) == 3:
                records[key] += ('', '')
            if botuser != 'alerts' and len(record) == 5:
                records[key] += ('',)

or:

            if botuser != 'alerts':
                while len(record) < 6:
                    records[key] += ('',)

 
So I think it's time to decide between committing to Announcement (storing a dict in config/daily.pickle) and migrating records to config/reminders.yaml.


Holy crap!

>>> class MyDict(dict):
...     pass
... 
>>> class Announcement:
...     a = 1
... 
>>> mydict = MyDict()
>>> mydict['a'] = 2
>>> ann = Announcement()
>>> ann.a
1
>>> ann.__dict__ = mydict
>>> ann.a
2
>>> type(ann.__dict__)
<class '__main__.MyDict'>
>>> ann.a = 3
>>> mydict
{'a': 3}

I thought surely, even if it let me assign ann.__dict__ = MyDict(), it would at most implicitly shallow copy to a new pure dict, but maybe I can end up using Announcement and moving the data into an ImplicitTrackingDict!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant