|
| 1 | +export namespace constants { |
| 2 | + const SESSION_VERSION: number; |
| 3 | +} |
| 4 | + |
| 5 | +export namespace errors { |
| 6 | + class BaseError {} |
| 7 | + |
| 8 | + const BusyErrorCode: string; |
| 9 | + class BusyError {} |
| 10 | + |
| 11 | + const FormNotFoundErrorCode: string; |
| 12 | + class FormNotFoundError {} |
| 13 | + |
| 14 | + const I18nErrorCode: string; |
| 15 | + class I18nError {} |
| 16 | + |
| 17 | + const QueryNotFoundErrorCode: string; |
| 18 | + class QueryNotFoundError {} |
| 19 | + |
| 20 | + const SessionErrorCode: string; |
| 21 | + class SessionError {} |
| 22 | +} |
| 23 | + |
| 24 | +interface AddFormOptions<Answers, Ref> { |
| 25 | + cb?: ( |
| 26 | + answers: Answers, |
| 27 | + ref: Ref, |
| 28 | + ) => Promise<any>; |
| 29 | + i18n?: ( |
| 30 | + text: string, |
| 31 | + answers: Partial<Answers>, |
| 32 | + ref: Ref, |
| 33 | + ) => Promise<any>; |
| 34 | +} |
| 35 | + |
| 36 | +type ChatId = number | string; |
| 37 | + |
| 38 | +export interface Form<Answers, Ref> { |
| 39 | + name: string; |
| 40 | + queries: Query<Answers, Ref>[]; |
| 41 | + options: AddFormOptions<Answers, Ref>; |
| 42 | +} |
| 43 | + |
| 44 | +export class FormSet<Answers, Ref> { |
| 45 | + addForm( |
| 46 | + formName: string, |
| 47 | + queries: Query<Answers, Ref>[], |
| 48 | + options?: AddFormOptions<Answers, Ref>, |
| 49 | + ): Form<Answers, Ref>; |
| 50 | + |
| 51 | + cancel(chatId: ChatId): Promise<boolean>; |
| 52 | + |
| 53 | + getForms(): Form<Answers, Ref>[]; |
| 54 | + |
| 55 | + on( |
| 56 | + event: "query", |
| 57 | + cb: ( |
| 58 | + question: { |
| 59 | + choices: Array<{ text: string }>; |
| 60 | + text: string; |
| 61 | + }, |
| 62 | + ref: Ref, |
| 63 | + ) => void, |
| 64 | + ): void; |
| 65 | + |
| 66 | + process( |
| 67 | + chatId: ChatId, |
| 68 | + text: string, |
| 69 | + ref: Ref, |
| 70 | + ): Promise<void>; |
| 71 | + |
| 72 | + processForm( |
| 73 | + formName: string, |
| 74 | + chatId: ChatId, |
| 75 | + ref: Ref, |
| 76 | + options?: { |
| 77 | + answers?: Answers; |
| 78 | + }, |
| 79 | + ): Promise<void>; |
| 80 | +} |
| 81 | + |
| 82 | +export interface Query<Answers, Ref> { |
| 83 | + name?: keyof Answers; |
| 84 | + |
| 85 | + post?( |
| 86 | + this: QueryController<Answers, Ref>, |
| 87 | + answer: string, |
| 88 | + ): Promise<any>; |
| 89 | + |
| 90 | + pre?(this: QueryController<Answers, Ref>): Promise<any>; |
| 91 | + |
| 92 | + question?: { |
| 93 | + choices?: (string | { id: number | string; text: string })[]; |
| 94 | + strict?: boolean; |
| 95 | + retryText?: string; |
| 96 | + text?: string; |
| 97 | + }; |
| 98 | + |
| 99 | + text?: string; |
| 100 | +} |
| 101 | + |
| 102 | +export interface QueryController<Answers, Ref> { |
| 103 | + form: Form<Answers, Ref>; |
| 104 | + formset: FormSet<Answers, Ref>; |
| 105 | + ref: Ref; |
| 106 | + |
| 107 | + do<Key extends keyof Answers>(name: Key): Promise<never>; |
| 108 | + |
| 109 | + getAnswer<Key extends keyof Answers>(): Answers[Key]; |
| 110 | + getAnswer<Key extends keyof Answers>(name: Key, defaultValue?: any): Answers[Key]; |
| 111 | + |
| 112 | + getAnswers(): Partial<Answers>; |
| 113 | + |
| 114 | + goto<Key extends keyof Answers>(name: Key): Promise<never>; |
| 115 | + |
| 116 | + post(): Promise<never>; |
| 117 | + |
| 118 | + retry(text?: string): Promise<never>; |
| 119 | + |
| 120 | + send(text: string): Promise<void>; |
| 121 | + |
| 122 | + setAnswer<Key extends keyof Answers>(key: Key, value: Answers[Key]): void; |
| 123 | + setAnswer<Key extends keyof Answers>(value: Answers[Key]): void; |
| 124 | + |
| 125 | + setText(text: string): void; |
| 126 | + |
| 127 | + skip(): Promise<never>; |
| 128 | + |
| 129 | + stop(): Promise<never>; |
| 130 | + |
| 131 | + text(text: string, ctx?: Partial<Answers>): Promise<string>; |
| 132 | + |
| 133 | + unsetAnswer(): void; |
| 134 | + unsetAnswer<Key extends keyof Answers>(name: Key): void; |
| 135 | +} |
0 commit comments