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: localization failing due to localized versions of setMyCommandsParams command property being an empty string #13

Closed
carafelix opened this issue May 2, 2024 · 0 comments · Fixed by #14

Comments

@carafelix
Copy link
Member

carafelix commented May 2, 2024

With a sample bot using something in the lines:

const userCommands = new Commands<MyContext>();
bot.use(commands());

userCommands.command("start", "init bot", (c) => {
  c.reply("started");
}).localize("es", "iniciar", "Inicializa el bot")
  .addToScope(
    { type: "all_private_chats" },
    (ctx) => ctx.reply(`iniciado`),
  );

userCommands.command("end", "end", (c) => {
  c.reply("end");
}).localize("es", "fin", "finaliza")
  .addToScope(
    { type: "all_private_chats" },
    (ctx) => ctx.reply(`finalizado`),
  );

throws:

[
  {
    scope: { type: "chat", chat_id: <ID> },
    language_code: undefined,
    commands: [
      { command: "start", description: "init bot" },
      { command: "end", description: "end" }
    ]
  },
  {
    scope: { type: "chat", chat_id: <ID> },
    language_code: "es",
    commands: [
      { command: "", description: "Inicializa el bot" },
      { command: "", description: "finaliza" }
    ]
  }
]
Error in middleware while handling update 286148219 GrammyError: Call to 'setMyCommands' failed! (400: Bad Request: command must be non-empty)

Most likely due to probably this line inside the toObject utility:

command: localizedName instanceof RegExp ? "" : localizedName,

Is there any particular reason why we are converting to RegExp the languages keys inside the Command._languages map? Seems unnecessary, since the regExp characteristics are not being used anywhere. I looked up the matchOnlyAtStart option and the fuzzySearch method and they don't depend on regExp usage neither

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.

1 participant