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