ConversationForm
Form building utilities that are exposed on conversation
.
All methods of this class behave similarly. They all follow these steps:
- Wait for an update.
- Validate the contained data.
- Skip the update if validation fails.
- Extract the data if the validation succeeds, and return the data.
Moreover, you are able to pass a handler to each method that will be called if the user sends an update that fails validation.
Type Parameters
C
C extends Context
Constructors
This class is constructed internally by the plugin.
Methods
text
Waits until the user sends some text, and returns this text. If the user does something else, these updates will be skipped. You may specify the otherwise
handler that is called in such cases. Among other things, this allows you to tell the user that they need to send some text.
number
Waits until the user sends a number, and returns this number. If the user sends something that cannot be parsed to a number using parse
, these updates will be skipped. You may specify the otherwise
handler that is called in such cases. Among other things, this allows you to tell the user that they need to send some text.
int
int(options: number | ((ctx: C) => Promise<unknown> | unknown) | { radix?: number; otherwise?: (ctx: C) => Promise<unknown> | unknown });
Waits until the user sends a number, and returns this number. If the user sends something that cannot be parsed to a number using parse
, these updates will be skipped. You may specify the otherwise
handler that is called in such cases. Among other things, this allows you to tell the user that they need to send some text. You can also pass a radix that will be passed to parse
.
select
Waits until the user sends one of the given strings, and returns the selected string. This is escpecially useful if you previously sent a custom keyboard, and you expect the user to press one of the keyboard buttons. If the user does something else, these updates will be skipped. You may specify the otherwise
handler that is called in such cases. Among other things, this allows you to tell the user that they need to select one of the given options.
url
Waits until the user sends a URL, and returns this URL. If the user sends something that cannot be parsed to a URL by the global URL
constructor, these updates will be skipped. You may specify the otherwise
handler that is called in such cases. Among other things, this allows you to tell the user that they did not send a valid URL.
Note that the URL constructor requires