Module

x/grammy_conversations/mod.ts>ConversationForm

Conversational interfaces for grammY
Latest
class ConversationForm
import { ConversationForm } from "https://deno.land/x/grammy_conversations@v1.1.0/mod.ts";

Form building utilities that are exposed on conversation.form.

All methods of this class behave similarly. They all follow these steps:

  1. Wait for an update.
  2. Validate the contained data.
  3. Skip the update if validation fails.
  4. 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.

Constructors

new
ConversationForm(conversation: { wait: () => Promise<C>; skip: () => Promise<never>; })

This class is constructed internally by the plugin.

Methods

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 parseInt, 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 parseInt.

number(otherwise?: (ctx: C) => unknown | Promise<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 parseFloat, 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.

select<T extends string>(options: T[], otherwise?: (ctx: C) => Promise<unknown> | unknown)

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.

text(otherwise?: (ctx: C) => unknown | Promise<unknown>)

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.

url(otherwise?: (ctx: C) => unknown | Promise<unknown>)

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

import ConversationForm
import { ConversationForm } from "https://deno.land/x/grammy_conversations@v1.1.0/mod.ts";