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

Bug: caption_entities not working as expected in Telegram Bot API #1240

Open
LughWalle opened this issue Dec 1, 2024 · 2 comments
Open

Bug: caption_entities not working as expected in Telegram Bot API #1240

LughWalle opened this issue Dec 1, 2024 · 2 comments

Comments

@LughWalle
Copy link

Bug Report

I have read:

I am using the latest version of the library.


Expected Behavior

The caption_entities parameter should properly format the caption for media messages such as photos, videos, and documents. When using the following code snippet:

await bot.sendPhoto(targetChatId, fileId, {
  caption: "This is an example caption",
  caption_entities: [
    { offset: 0, length: 8, type: 'underline' },
    { offset: 9, length: 10, type: 'spoiler' },
    { offset: 19, length: 8, type: 'bold' }
  ],
});

The resulting caption should render with formatting applied:

This is ||an example|| caption


Actual Behavior

The message is sent, but the caption_entities parameter is ignored, and the caption appears as plain text:

This is an example caption

No formatting (e.g., underline, spoiler, bold) is applied.


Steps to reproduce the Behavior

  1. Use the sendPhoto method with the code snippet above.
  2. Observe that the caption is sent as plain text, ignoring the caption_entities.
  3. Compare this to the behavior of entities for text messages, which applies formatting correctly.

This seems like a bug where the caption_entities field is either not processed or incorrectly passed to the Telegram Bot API. If the implementation is correct, clarification in the documentation would also be helpful. Thank you for your attention to this matter!

@darkywa13
Copy link

This is a normal practice for this library :(
caption_entities: JSON.stringify(message.caption_entities) as any

@LughWalle
Copy link
Author

Thanks for your feedback, @darkywa13.

While I understand that some behaviors may seem expected based on previous experiences with the library, the caption_entities parameter should work the same way as the entities parameter for text messages, applying formatting to captions.

If this limitation is inherent to the library, it would be helpful to explicitly document it, as it affects the functionality of bots that rely on formatted captions. Clarifying whether this is a limitation of the library or an issue with how the parameter is being handled would help developers avoid confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants