Title: [FEATURE] tool for translating unicode offsets to utf-16 offsets of MessageEntity · Issue #4319 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: [FEATURE] tool for translating unicode offsets to utf-16 offsets of MessageEntity · Issue #4319 · python-telegram-bot/python-telegram-bot
X Title: [FEATURE] tool for translating unicode offsets to utf-16 offsets of MessageEntity · Issue #4319 · python-telegram-bot/python-telegram-bot
Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? I want to send a message with customized MessageEntity. At first I assumed ptb already handled the unicode -> utf-16 translation. It generally works for most...
Open Graph Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? I want to send a message with customized MessageEntity. At first I assumed ptb already handled the unicode -> utf-16 ...
X Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? I want to send a message with customized MessageEntity. At first I assumed ptb already handled the unicode -> utf-...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/4319
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE] tool for translating unicode offsets to utf-16 offsets of MessageEntity","articleBody":"### What kind of feature are you missing? Where do you notice a shortcoming of PTB?\r\n\r\nI want to send a message with customized `MessageEntity`. At first I assumed ptb already handled the unicode -\u003e utf-16 translation. It generally works for most texts, but turns out it will fail if there are some emojis in the message.\r\n\r\n### Describe the solution you'd like\r\n\r\nA new class `UnicodeMessageEntity` is needed. Currently I have a simple solution:\r\n```python\r\n def fix_entities_offset(self):\r\n for text, entities in zip(self.texts, self.entities):\r\n cur_index = 0\r\n accumulated_len = 0\r\n for i, entity in enumerate(entities):\r\n cur_text = text[cur_index:entity.offset]\r\n accumulated_len += len(cur_text.encode('utf-16-le'))\r\n cur_off = accumulated_len // 2\r\n cur_text = text[entity.offset:entity.offset+entity.length]\r\n accumulated_len += len(cur_text.encode('utf-16-le'))\r\n cur_len = accumulated_len // 2 - cur_off\r\n entities[i] = MessageEntity(offset=cur_off, length=cur_len, type=entity.type, language=entity.language)\r\n cur_index = entity.offset + entity.length\r\n```\r\nIt would be nice if this can be automatically applied when send messages, when entity object is an instance of `UnicodeMessageEntity`.\r\n\r\n### Describe alternatives you've considered\r\n\r\n_No response_\r\n\r\n### Additional context\r\n\r\n_No response_","author":{"url":"https://github.com/Antares0982","@type":"Person","name":"Antares0982"},"datePublished":"2024-06-22T18:21:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/4319/python-telegram-bot/issues/4319"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5e738682-66b8-1a0a-e043-06971aacfc8b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8384:1CCD95:126C6:16D4E:6A5B7894 |
| html-safe-nonce | a6000a40609632247a2c194d0e67f6006174f6722586387da51eb9264876dbba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mzg0OjFDQ0Q5NToxMjZDNjoxNkQ0RTo2QTVCNzg5NCIsInZpc2l0b3JfaWQiOiI4MzY3MzA4NTY3NDczNzgwODg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ebadac166e15e5ca547621e7637292512750a3642dcbc33a89080b42ab23b01d |
| hovercard-subject-tag | issue:2367948850 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/4319/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0eb4825ff7638da962a5d0d4163b80055f4ac72d1c3276a25e6e3eb7a31207bc/python-telegram-bot/python-telegram-bot/issues/4319 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0eb4825ff7638da962a5d0d4163b80055f4ac72d1c3276a25e6e3eb7a31207bc/python-telegram-bot/python-telegram-bot/issues/4319 |
| og:image:alt | What kind of feature are you missing? Where do you notice a shortcoming of PTB? I want to send a message with customized MessageEntity. At first I assumed ptb already handled the unicode -> utf-16 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Antares0982 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git |
| octolytics-dimension-user_id | 16178365 |
| octolytics-dimension-user_login | python-telegram-bot |
| octolytics-dimension-repository_id | 38696925 |
| octolytics-dimension-repository_nwo | python-telegram-bot/python-telegram-bot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38696925 |
| octolytics-dimension-repository_network_root_nwo | python-telegram-bot/python-telegram-bot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width