import type { StateData, Context } from './state'; import type { ButtonsList, RawButton } from './buttons'; import type { Options } from './config'; import { type QuestionText } from './questions/text'; import { type QuestionConfirm } from './questions/confirm'; import { type QuestionSelect } from './questions/select'; import { type QuestionPinpad } from './questions/pinpad'; import { type QuestionPicker } from './questions/picker'; import { type QuestionDatepicker } from './questions/datepicker'; export declare type Question = QuestionText | QuestionConfirm | QuestionSelect | QuestionPinpad | QuestionPicker | QuestionDatepicker; /** * Function which returns option value based on current context values * @param context Current context values */ export declare type ContextFn = (context: Context) => T | Promise; export interface QuestionCommon { /** Type of question */ type: string; /** Name for result in context */ name: string; /** Question message */ message: string | ContextFn; /** Skip this question? */ skip?: boolean | ContextFn; /** Overwrite global options */ options?: Options; /** Format user's answer * @param answer User's answer for the question * @param context Object with collected data on previous steps */ format?: (answer: T, context?: Context) => unknown; /** Validate answer * @param answer Handeled user's answer for the question * @param context Object with collected data on previous steps * @returns true - to pass answer * @returns false - default error message and repeat question * @returns string - custom error message and repeat question */ validate?: (answer: T, context?: Context) => boolean | string; } interface Message { message: string; buttons?: ButtonsList; } interface CallbackResponce { value?: string; answer?: string; message?: string; alert?: string; } /** Methods to prepare message for user and handle the answer */ export interface QuestionHandler { /** Prepared question message * @param data Current state data */ message(data: StateData): Promise; /** Handle callback_data from user * @param rawMessage callback_data from user * @param data Current state data */ callback?(button: RawButton, data: StateData): Promise; /** Validate raw user's answer * @param rawMessage raw answer(message or keyboard button value) from user * @param data Current state data */ validate?(rawMessage: string, data: StateData): Promise; /** Format raw user's answer to value, whichh will be stored in result * @param rawMessage raw answer(message or button value) from user * @param data Current state data */ format(rawMessage: string, data: StateData): Promise; } export declare function getQuestionHandler(data: StateData): QuestionHandler | QuestionHandler | QuestionHandler | QuestionHandler | undefined; export {};