/
index.d.ts
151 lines (139 loc) · 4.86 KB
/
index.d.ts
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
declare module 'free-cleverbot' {
export type Stimulus = string;
export type Context = string[];
export type Language =
| 'af' | 'id' | 'ms' | 'ca' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'eu'
| 'ti' | 'fr' | 'gl' | 'hr' | 'zu' | 'is' | 'it' | 'lt' | 'hu' | 'nl'
| 'no' | 'pl' | 'pt' | 'ro' | 'sl' | 'fi' | 'sv' | 'vi' | 'tr' | 'el'
| 'bg' | 'ru' | 'sr' | 'uk' | 'ko' | 'zh' | 'ja' | 'hi' | 'th';
export type Headers = {
'Accept': string;
'Accept-Encoding': string;
'Accept-Language': string;
'Cache-Control': string;
'Connection': string;
'Content-Type': string;
'Host': string;
'Pragma': string;
'Origin': string;
'Referer': string;
'Sec-Ch-Ua'?: string;
'Sec-Ch-Ua-Arch'?: string;
'Sec-Ch-Ua-Bitness'?: string;
'Sec-Ch-Ua-Full-Version'?: string;
'Sec-Ch-Ua-Full-Version-List'?: string;
'Sec-Ch-Ua-Mobile': string;
'Sec-Ch-Ua-Model': string;
'Sec-Ch-Ua-Platform'?: string;
'Sec-Ch-Ua-Platform-Version'?: string;
'Sec-Ch-Ua-Wow64': string;
'Sec-Fetch-Dest': string;
'Sec-Fetch-Mode': string;
'Sec-Fetch-Site': string;
'Sec-Gpc': string;
'User-Agent': string;
};
export interface Config {
debug?: boolean;
defaultLanguage?: Language;
maxRetryAttempts?: number;
retryBaseCooldown?: number;
cookieExpirationTime?: number;
}
export interface CookieData {
content: string[] | undefined;
lastUpdate: number;
}
export interface SessionData {
cbsId: string | undefined;
xai: string | undefined;
ns: number;
lastResponse: string | undefined;
}
export interface RequestData {
successfulRequestsCount: number;
failedRequestsCount: number;
headers: Headers;
}
export interface CleverBotData {
debug: boolean;
selectedLanguage: Language;
maxRetryAttempts: number;
retryBaseCooldown: number;
cookie: CookieData;
session: SessionData;
request: RequestData;
}
/**
* The main function of the module, communicating with the Cleverbot API.
* @param stimulus - The input text for Cleverbot.
* @param context - The required conversation context as an array of strings.
* @param language - Optional language code for the Cleverbot session.
* @returns The response from Cleverbot as a string.
* @example
* const CleverBot = require('free-cleverbot');
*
* CleverBot.config({ debug: false, defaultLanguage: 'en', maxRetryAttempts: 5, retryBaseCooldown: 4000, cookieExpirationTime: 15768000 });
*
* const context = [];
*
* (async () => {
* try {
* const res = await CleverBot.interact('Hello', context);
*
* context.push(msg);
* context.push(res);
*
* console.log(res);
* } catch (err) {
* console.error('Sorry, but something went wrong ):', err);
* }
* })();
* @throws {Error} If it fails to get a response after the maximum number of attempts.
*/
export function interact(stimulus: Stimulus, context: Context, language?: Language): Promise<string>;
/**
* Function responsible for configuring the module.
* Allows setting various configuration options for the Cleverbot module.
*
* @param config - The configuration object containing settings.
* @example
* CleverBot.config({
* debug: false,
* defaultLanguage: 'en',
* maxRetryAttempts: 5,
* retryBaseCooldown: 4000,
* cookieExpirationTime: 15768000,
* });
* @throws {Error} If the provided configuration object is invalid.
*/
export function config(config: Config): void;
/**
* Returns the current session data stored in RAM and other information.
*
* @example console.log(CleverBot.getData());
* @returns An object with Cleverbot data.
*/
export function getData(): CleverBotData;
/**
* Allows for the deletion of the current session and the initiation of a new one. The conversation context should also be removed.
*
* @example
* const CleverBot = require('free-cleverbot');
*
* const context = ['Hello', 'Hi', 'How are you?'];
*
* CleverBot.newSession();
* context = [];
*/
export function newSession(): void;
/**
* Represents the version number of the `free-cleverbot` module.
* This property contains a string that specifies the current version of the module,
* conforming to the Semantic Versioning (SemVer) standard.
*
* @example console.log(CleverBot.version); // Displays e.g. '2.0.0'
* @return The current version of the module.
*/
export const version: string;
}