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

feat: Static menus #2

Open
KnorpelSenf opened this issue Oct 10, 2021 · 1 comment
Open

feat: Static menus #2

KnorpelSenf opened this issue Oct 10, 2021 · 1 comment

Comments

@KnorpelSenf
Copy link
Member

KnorpelSenf commented Oct 10, 2021

Menus cannot be sent via bot.api because they require an installed API transformer. This transformer is only installed during bot.use(menu).

One way would be to directly provide the API transformer to be installed on bot.api, but this does not follow the intuitive pattern of the rest of the plugin.

Instead, it would be cool if we can have a statically rendered version of the menu (a menu range) that can be passed to the constructor of the menu. Whenever the menu is sent (the internal Proxy is accessed), this static menu is rendered and sent. It obviously may not depend on a context object, so we should throw an error if someone tries to use dynamic strings/dynamic ranges.

const menu = new Menu('id', {
  static: new Menu.Range().text('go', ctx => ctx.reply('whee'))
})
@KnorpelSenf KnorpelSenf changed the title Static menus feat: Static menus Dec 2, 2021
@sartoshi-foot-dao
Copy link

Depositing the phrases I queried the issues of this repo so that they may be indexed for others:

this.id
bot.use
bot.api

Context

Question

Good evening all, a question about Menus and ctx:

Suppose I wanted to use grammY bot in an ancillary webhook that does not receive updates from Telegram but payloads from another system e.g. a scheduled message.

This message will contain a Menu, which depends on ctx to work; directly using Menu with bot.api.sendMessage(1234567, "good evening", {reply_markup: Menu} throws error Cannot send menu '${this.id}'! Did you forget to use bot.use() for it?. Actually, bot.use(Menu) is called before any other middleware.

I am assuming that if I had access to a ctx, presumably via listener, Menu would work. If so, what listener could be triggered by a non-telegram-update payload?

Has anyone any experience with sending menus in such a manner?

Edit: Menu is an instance of the Menu class (from plugin)

Answer

@KnorpelSenf:
You are correct that menus are generated from context objects. There's an idea to create static menus (#2) but so far there's been very little demand for this. Until then, there's a less convenient solution:

What you should do instead is to use bot.api to send a message with reply markup, using the built-in keyboard plugin of grammY. As soon as a button is pressed, you can switch over to the menu plugin and let it handle the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: To do
Development

No branches or pull requests

2 participants