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: undefined and unspecified have different behavior #144

Closed
EdJoPaTo opened this issue Dec 28, 2021 · 2 comments · Fixed by #145
Closed

Bug: undefined and unspecified have different behavior #144

EdJoPaTo opened this issue Dec 28, 2021 · 2 comments · Fixed by #145

Comments

@EdJoPaTo
Copy link
Member

I migrated yet another bot to grammy and found out that there is something fishy here.
I do not use transformers or something, its so far a plain Telegraf → grammY migration.

Technically telegraf-inline-menugrammy-inline-menu is used which sets undefined to some properties instead of omitting them. I recreated the issue with plain grammY calls but haven't looked into it what exactly might cause this issue.

The goal is to send a photo without caption.

await context.replyWithPhoto(media, {caption: undefined});

Ends up creating a photo message with a caption which is literally saying "undefined".

await context.replyWithPhoto(media, {caption: undefined, parse_mode: undefined});

Fails with "Call to 'sendPhoto' failed! (400: Bad Request: unsupported parse_mode)"
Part of the error contains this, which indicated the error still thinks the undefined is undefined and not the string "undefined":

{
  method: 'sendPhoto',
  payload: {
    chat_id: 2956631,
    photo: 'attach:https://hyyujfn4azjcick6',
    caption: undefined,
    parse_mode: undefined
  },
  ok: false,
  error_code: 400,
  description: 'Bad Request: unsupported parse_mode',
  parameters: {}
}

I did not create a minimal bot to check these calls in a simple environment but as the bot is not that complex I dont think there are side effects to it currently. But I might be wrong here.

@KnorpelSenf
Copy link
Member

These values should already get stripped for JSON requests. Can you confirm that this bug only reproduces when uploading own files, and that it doesn't reproduce when sending an image by file identifier or URL?

@EdJoPaTo
Copy link
Member Author

Can confirm. Sending images via URL works fine, this only happens via InputFile.

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

Successfully merging a pull request may close this issue.

2 participants