- Notifications
You must be signed in to change notification settings - Fork5.7k
Description
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
I want to send a message with customizedMessageEntity
. At first I assumed ptb already handled the unicode -> utf-16 translation. It generally works for most texts, but turns out it will fail if there are some emojis in the message.
Describe the solution you'd like
A new classUnicodeMessageEntity
is needed. Currently I have a simple solution:
deffix_entities_offset(self):fortext,entitiesinzip(self.texts,self.entities):cur_index=0accumulated_len=0fori,entityinenumerate(entities):cur_text=text[cur_index:entity.offset]accumulated_len+=len(cur_text.encode('utf-16-le'))cur_off=accumulated_len//2cur_text=text[entity.offset:entity.offset+entity.length]accumulated_len+=len(cur_text.encode('utf-16-le'))cur_len=accumulated_len//2-cur_offentities[i]=MessageEntity(offset=cur_off,length=cur_len,type=entity.type,language=entity.language)cur_index=entity.offset+entity.length
It would be nice if this can be automatically applied when send messages, when entity object is an instance ofUnicodeMessageEntity
.
Describe alternatives you've considered
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels