Skip to content

Commit 58e88f8

Browse files
committed
add: add typings file
1 parent 50198f1 commit 58e88f8

File tree

2 files changed

+301
-1
lines changed

2 files changed

+301
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"homepage": "https://botui.org",
55
"version": "0.3.3",
66
"main": "build/botui.min.js",
7+
"typings": "typings/index.d.ts",
78
"author": {
89
"name": "Moin Uddin",
910
"url": "https://moin.im"
@@ -41,4 +42,4 @@
4142
"watch": "gulp watch"
4243
},
4344
"license": "MIT"
44-
}
45+
}

typings/index.d.ts

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
/**
2+
* BotUI options
3+
*
4+
* @interface BotUIOptions
5+
*/
6+
interface BotUIOptions {
7+
/**
8+
* set this to true if you want to debug the underlaying Vue instance
9+
*
10+
* @type {boolean}
11+
* @memberof BotUIOptions
12+
*/
13+
debug?: boolean = false;
14+
/**
15+
* set this to false if you already have FontAwesome in your project and don't want it to be loaded again by BotUI.
16+
*
17+
* @type {boolean}
18+
* @memberof BotUIOptions
19+
*/
20+
fontawesome?: boolean = true;
21+
}
22+
23+
/**
24+
* Message method options
25+
*
26+
* @interface MessageOption
27+
*/
28+
interface MessageOption {
29+
/**
30+
* set to true if you want to show a loading state '3 animated dots'. available in version >= 0.3.1
31+
*
32+
* @type {boolean}
33+
* @memberof MessageOption
34+
*/
35+
loading?: boolean = false;
36+
/**
37+
* wait before showing the message. in milliseconds.
38+
*
39+
* @type {number}
40+
* @memberof MessageOption
41+
*/
42+
delay?: number = 0;
43+
/**
44+
* either 'text' or 'embed'
45+
*
46+
* @type {('text' | 'embed')}
47+
* @memberof MessageOption
48+
*/
49+
type: 'text' | 'embed' = 'text';
50+
/**
51+
* Should be a URL if type is 'embed', text otherwise.
52+
*
53+
* @type {string}
54+
* @memberof MessageOption
55+
*/
56+
content: string = '';
57+
/**
58+
* should be shown aligned to right side?
59+
*
60+
* @type {false}
61+
* @memberof MessageOption
62+
*/
63+
human?: false;
64+
/**
65+
* a string or array of custom CSS classes you want to be added.
66+
*
67+
* @type {string|string[]}
68+
* @memberof MessageOption
69+
*/
70+
cssClass?: string | string[] = '';
71+
}
72+
73+
/**
74+
* Actions method option
75+
*
76+
* @interface ActionsOption
77+
*/
78+
interface ActionsOption {
79+
/**
80+
* either 'text' or 'button',
81+
*
82+
* @type {('text' | 'button')}
83+
* @memberof ActionsOption
84+
*/
85+
type: 'text' | 'button' = 'text';
86+
/**
87+
* array of 'button' objects if type is 'button'. object of 'text' otherwise.
88+
*
89+
* @type {ButtonObject[]|TextObject[]}
90+
* @memberof ActionsOption
91+
*/
92+
action: ButtonObject[] | TextObject[];
93+
/**
94+
* a string or array of custom CSS classes you want to be added.
95+
*
96+
* @type {string|string[]}
97+
* @memberof ActionsOption
98+
*/
99+
cssClass?: string | string[] = '';
100+
/**
101+
* should the actions sections be hidden when submitted.
102+
*
103+
* @type {boolean}
104+
* @memberof ActionsOption
105+
*/
106+
autoHide?: boolean = true;
107+
/**
108+
* text from action is added as a message in UI from human side.
109+
*
110+
* @type {boolean}
111+
* @memberof ActionsOption
112+
*/
113+
autoMessage?: boolean = true;
114+
}
115+
116+
/**
117+
* Button object
118+
*
119+
* @interface ButtonObject
120+
*/
121+
interface ButtonObject {
122+
/**
123+
* icon to show in button.
124+
*
125+
* @type {string}
126+
* @memberof ButtonObject
127+
*/
128+
icon?: string = '';
129+
/**
130+
* Text to show in the button. be creative!
131+
*
132+
* @type {string}
133+
* @memberof ButtonObject
134+
*/
135+
text: string = '';
136+
/**
137+
* this is how you will identify the button when result is returned.
138+
*
139+
* @type {string}
140+
* @memberof ButtonObject
141+
*/
142+
value: string = '';
143+
/**
144+
* a string or array of custom CSS classes you want to be added.
145+
*
146+
* @type {string|string[]}
147+
* @memberof ButtonObject
148+
*/
149+
cssClass?: string | string[] = '';
150+
}
151+
152+
/**
153+
* Text action option.
154+
*
155+
* @interface TextObject
156+
*/
157+
interface TextObject {
158+
/**
159+
* size of the input to show. Relies on HTML size attribute for input elements.
160+
*
161+
* @type {number}
162+
* @memberof TextObject
163+
*/
164+
size?: number = 30;
165+
/**
166+
* Could be any of the valid types for HTML input elements. e.g.: number, tel, time, date, email, etc.
167+
*
168+
* @type {string}
169+
* @memberof TextObject
170+
*/
171+
sub_type?: string = '';
172+
/**
173+
* pre-populates the text field. Only for 'text' type.
174+
*
175+
* @type {string}
176+
* @memberof TextObject
177+
*/
178+
value: string = '';
179+
/**
180+
* Sets the placeholder text for the input element.
181+
*
182+
* @type {string}
183+
* @memberof TextObject
184+
*/
185+
placeholder?: string = '';
186+
}
187+
188+
interface ResultObject {
189+
/**
190+
* 'Text' or 'Button' Type of the action it was returned from.
191+
*
192+
* @type {('Text' | 'Button')}
193+
* @memberof ResultObject
194+
*/
195+
type: 'Text' | 'Button';
196+
/**
197+
* Text in the input in case type is 'text'. If type is 'button' then its the same as 'value' in button object.
198+
*
199+
* @type {string}
200+
* @memberof ResultObject
201+
*/
202+
value: string = '';
203+
/**
204+
* Only present if type of message is 'button'. same as the 'text' in button object.
205+
*
206+
* @type {string}
207+
* @memberof ResultObject
208+
*/
209+
text: string = '';
210+
}
211+
212+
declare class BotUI {
213+
214+
215+
constructor(id: string, opts?: BotUIOptions) { }
216+
217+
message: {
218+
/**
219+
* Appends a message to UI.
220+
*
221+
* @param {(MessageOption | string)} message
222+
* @returns {Promise<number>}
223+
*/
224+
add(message: MessageOption | string): Promise<number>;
225+
/**
226+
* Appends a message to UI. Just a shorthand to `message.add`.
227+
*
228+
* @param {(MessageOption | string)} message
229+
* @returns {Promise<number>}
230+
*/
231+
bot(message: MessageOption | string): Promise<number>;
232+
/**
233+
* Appends a message to UI and sets the `human` to `true`.
234+
*
235+
* @param {(MessageOption | string)} message
236+
* @returns {Promise<number>}
237+
*/
238+
human(message: MessageOption | string): Promise<number>;
239+
/**
240+
* Accepts an index of message.
241+
*
242+
* @param {number} index
243+
* @returns {Promise<MessageOption>}
244+
*/
245+
get(index: number): Promise<MessageOption>;
246+
/**
247+
* Updates a message in UI.
248+
* "Only content and loading property of message can updated. type of a message cannot be changed."
249+
*
250+
* @param {number} index
251+
* @param {MessageOption} message
252+
* @returns {Promise<number>}
253+
*/
254+
update(index: number, message: MessageOption): Promise<string>;
255+
/**
256+
* Removes a message from UI.
257+
*
258+
* @param {number} index
259+
* @returns {Promise<void>}
260+
*/
261+
remove(index: number): Promise<void>;
262+
/**
263+
* Removes all the messages from UI.
264+
*
265+
* @param {number} index
266+
* @returns {Promise<void>}
267+
*/
268+
removeAll(index: number): Promise<void>;
269+
}
270+
271+
action: {
272+
/**
273+
* Shows the action section.
274+
*
275+
* @returns {Promise<void>}
276+
*/
277+
show(action: ActionsOption): Promise<void>;
278+
/**
279+
* Hides the action section.
280+
*
281+
* @returns {Promise<void>}
282+
*/
283+
hide(): Promise<void>;
284+
/**
285+
* Shows the action section and sets the action type to text. Its a shorthand to show.
286+
*
287+
* @param {ActionsOption} action
288+
* @returns {Promist<ResultObject>}
289+
*/
290+
text(action: ActionsOption): Promist<ResultObject>;
291+
/**
292+
* Shows the action section and sets the action type to button. Its a shorthand to show.
293+
*
294+
* @param {ActionsOption} action
295+
* @returns {Promist<ResultObject>}
296+
*/
297+
button(action: ActionsOption): Promist<ResultObject>;
298+
}
299+
}

0 commit comments

Comments
 (0)