-
Notifications
You must be signed in to change notification settings - Fork 17
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
[enhancement] add callback to conversation forms #117
Comments
Wouldn't it be better to just provide a callback so people can do this? const value = await conversation.form.text({ action: ctx => ctx.deleteMessage(), otherwise: () => {...} }) Then it isn't limited to deletions only, but messages can also be copied elsewhere or reacted to or whatever. |
sounds and looks a lot better! if you don't resist, i will replace my idea with this one in the starting message |
Please go ahead! |
Naturally, it would make sense to implement all form utilities around a new generic form building helper function. const text: string = await conversation.form.build({
select: ctx => ctx.has(":text") ? { ok: true, value: ctx.msg.text } : { ok: false },
action: ctx => ctx.deleteMessage(),
otherwise: ctx => ctx.reply("no text"),
}) All current form implementations of the plugin can then be based on this abstraction. In addition, it permits people to build their own forms utilities on top of it. Having such a base makes it trivial to add the requested |
that's an interesting idea, but forms get rid of their simplicity. const getText: (options: FormOptions) => Promise<string> = conversation.form.build({
select: ctx => ctx.has(":text") && ctx.msg.text,
action: ctx => ctx.deleteMessage(),
otherwise: ctx => ctx.reply("no text"),
})
const text1 = await getText();
const text2 = await getText({ action: ctx => {} }); also we still need prebuilt functions as text, photo, etc... |
No. They will not be changed. This is purely additive. If the API is not good enough to be exposed, then the method can be made
This can already be done today. We do not need to modify the plugin for that.
That is because forms perform both validation and selection. The result value has to encode failure and success, and upon success, a value. These types do that. |
for example:
it's useful because form functions don't return anything except values.
thanks @KnorpelSenf for the idea
i'd like it a lot more than
The text was updated successfully, but these errors were encountered: