1 | import { Brolog } from 'brolog';
|
2 | import { Puppet, MemoryCard, StateSwitch, PuppetOptions } from 'wechaty-puppet';
|
3 | import { FileBox } from './config';
|
4 | import { Sayable } from './types';
|
5 | import { PuppetModuleName } from './puppet-config';
|
6 | import { Contact, ContactSelf, Friendship, Image, Message, MiniProgram, Room, RoomInvitation, Tag, UrlLink } from './user/mod';
|
7 | import { WechatyEventEmitter, WechatyEventName } from './events/wechaty-events';
|
8 | import { WechatyPlugin } from './plugin';
|
9 | export interface WechatyOptions {
|
10 | memory?: MemoryCard;
|
11 | name?: string;
|
12 | puppet?: PuppetModuleName | Puppet;
|
13 | puppetOptions?: PuppetOptions;
|
14 | ioToken?: string;
|
15 | }
|
16 | /**
|
17 | * Main bot class.
|
18 | *
|
19 | * A `Bot` is a WeChat client depends on which puppet you use.
|
20 | * It may equals
|
21 | * - web-WeChat, when you use: [puppet-puppeteer](https://github.com/wechaty/wechaty-puppet-puppeteer)/[puppet-wechat4u](https://github.com/wechaty/wechaty-puppet-wechat4u)
|
22 | * - ipad-WeChat, when you use: [puppet-padchat](https://github.com/wechaty/wechaty-puppet-padchat)
|
23 | * - ios-WeChat, when you use: puppet-ioscat
|
24 | *
|
25 | * See more:
|
26 | * - [What is a Puppet in Wechaty](https://github.com/wechaty/wechaty-getting-started/wiki/FAQ-EN#31-what-is-a-puppet-in-wechaty)
|
27 | *
|
28 | * > If you want to know how to send message, see [Message](#Message) <br>
|
29 | * > If you want to know how to get contact, see [Contact](#Contact)
|
30 | *
|
31 | * @example <caption>The World's Shortest ChatBot Code: 6 lines of JavaScript</caption>
|
32 | * const { Wechaty } = require('wechaty')
|
33 | * const bot = new Wechaty()
|
34 | * bot.on('scan', (qrCode, status) => console.log('https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode)))
|
35 | * bot.on('login', user => console.log(`User ${user} logged in`))
|
36 | * bot.on('message', message => console.log(`Message: ${message}`))
|
37 | * bot.start()
|
38 | */
|
39 | declare class Wechaty extends WechatyEventEmitter implements Sayable {
|
40 | private options;
|
41 | static readonly VERSION: string;
|
42 | static readonly log: Brolog;
|
43 | readonly log: Brolog;
|
44 | readonly state: StateSwitch;
|
45 | private readonly readyState;
|
46 | readonly wechaty: Wechaty;
|
47 | /**
|
48 | * singleton globalInstance
|
49 | * @ignore
|
50 | */
|
51 | private static globalInstance;
|
52 | private static globalPluginList;
|
53 | private pluginUninstallerList;
|
54 | private memory?;
|
55 | private lifeTimer?;
|
56 | private io?;
|
57 | puppet: Puppet;
|
58 | /**
|
59 | * the cuid
|
60 | * @ignore
|
61 | */
|
62 | readonly id: string;
|
63 | protected wechatifiedContact?: typeof Contact;
|
64 | protected wechatifiedContactSelf?: typeof ContactSelf;
|
65 | protected wechatifiedFriendship?: typeof Friendship;
|
66 | protected wechatifiedImage?: typeof Image;
|
67 | protected wechatifiedMessage?: typeof Message;
|
68 | protected wechatifiedMiniProgram?: typeof MiniProgram;
|
69 | protected wechatifiedRoom?: typeof Room;
|
70 | protected wechatifiedRoomInvitation?: typeof RoomInvitation;
|
71 | protected wechatifiedTag?: typeof Tag;
|
72 | protected wechatifiedUrlLink?: typeof UrlLink;
|
73 | get Contact(): typeof Contact;
|
74 | get ContactSelf(): typeof ContactSelf;
|
75 | get Friendship(): typeof Friendship;
|
76 | get Image(): typeof Image;
|
77 | get Message(): typeof Message;
|
78 | get MiniProgram(): typeof MiniProgram;
|
79 | get Room(): typeof Room;
|
80 | get RoomInvitation(): typeof RoomInvitation;
|
81 | get Tag(): typeof Tag;
|
82 | get UrlLink(): typeof UrlLink;
|
83 | /**
|
84 | * Get the global instance of Wechaty
|
85 | *
|
86 | * @param {WechatyOptions} [options={}]
|
87 | *
|
88 | * @example <caption>The World's Shortest ChatBot Code: 6 lines of JavaScript</caption>
|
89 | * const { Wechaty } = require('wechaty')
|
90 | *
|
91 | * Wechaty.instance() // Global instance
|
92 | * .on('scan', (url, status) => console.log(`Scan QR Code to login: ${status}\n${url}`))
|
93 | * .on('login', user => console.log(`User ${user} logged in`))
|
94 | * .on('message', message => console.log(`Message: ${message}`))
|
95 | * .start()
|
96 | */
|
97 | static instance(options?: WechatyOptions): Wechaty;
|
98 | /**
|
99 | * @param {WechatyPlugin[]} plugins - The plugins you want to use
|
100 | *
|
101 | * @return {Wechaty} - this for chaining,
|
102 | *
|
103 | * @desc
|
104 | * For wechaty ecosystem, allow user to define a 3rd party plugin for the all wechaty instances
|
105 | *
|
106 | * @example
|
107 | * // Report all chat message to my server.
|
108 | *
|
109 | * function WechatyReportPlugin(options: { url: string }) {
|
110 | * return function (this: Wechaty) {
|
111 | * this.on('message', message => http.post(options.url, { data: message }))
|
112 | * }
|
113 | * }
|
114 | *
|
115 | * bot.use(WechatyReportPlugin({ url: 'http://somewhere.to.report.your.data.com' })
|
116 | */
|
117 | static use(...plugins: (WechatyPlugin | WechatyPlugin[])[]): void;
|
118 | /**
|
119 | * The term [Puppet](https://github.com/wechaty/wechaty/wiki/Puppet) in Wechaty is an Abstract Class for implementing protocol plugins.
|
120 | * The plugins are the component that helps Wechaty to control the WeChat(that's the reason we call it puppet).
|
121 | * The plugins are named XXXPuppet, for example:
|
122 | * - [PuppetPuppeteer](https://github.com/wechaty/wechaty-puppet-puppeteer):
|
123 | * - [PuppetPadchat](https://github.com/wechaty/wechaty-puppet-padchat)
|
124 | *
|
125 | * @typedef PuppetModuleName
|
126 | * @property {string} PUPPET_DEFAULT
|
127 | * The default puppet.
|
128 | * @property {string} wechaty-puppet-wechat4u
|
129 | * The default puppet, using the [wechat4u](https://github.com/nodeWechat/wechat4u) to control the [WeChat Web API](https://wx.qq.com/) via a chrome browser.
|
130 | * @property {string} wechaty-puppet-padchat
|
131 | * - Using the WebSocket protocol to connect with a Protocol Server for controlling the iPad WeChat program.
|
132 | * @property {string} wechaty-puppet-puppeteer
|
133 | * - Using the [google puppeteer](https://github.com/GoogleChrome/puppeteer) to control the [WeChat Web API](https://wx.qq.com/) via a chrome browser.
|
134 | * @property {string} wechaty-puppet-mock
|
135 | * - Using the mock data to mock wechat operation, just for test.
|
136 | */
|
137 | /**
|
138 | * The option parameter to create a wechaty instance
|
139 | *
|
140 | * @typedef WechatyOptions
|
141 | * @property {string} name -Wechaty Name. </br>
|
142 | * When you set this: </br>
|
143 | * `new Wechaty({name: 'wechaty-name'}) ` </br>
|
144 | * it will generate a file called `wechaty-name.memory-card.json`. </br>
|
145 | * This file stores the login information for bot. </br>
|
146 | * If the file is valid, the bot can auto login so you don't need to scan the qrCode to login again. </br>
|
147 | * Also, you can set the environment variable for `WECHATY_NAME` to set this value when you start. </br>
|
148 | * eg: `WECHATY_NAME="your-cute-bot-name" node bot.js`
|
149 | * @property {PuppetModuleName | Puppet} puppet -Puppet name or instance
|
150 | * @property {Partial<PuppetOptions>} puppetOptions -Puppet TOKEN
|
151 | * @property {string} ioToken -Io TOKEN
|
152 | */
|
153 | /**
|
154 | * Creates an instance of Wechaty.
|
155 | * @param {WechatyOptions} [options={}]
|
156 | *
|
157 | */
|
158 | constructor(options?: WechatyOptions);
|
159 | /**
|
160 | * @ignore
|
161 | */
|
162 | toString(): string;
|
163 | /**
|
164 | * Wechaty bot name set by `options.name`
|
165 | * default: `wechaty`
|
166 | */
|
167 | name(): string;
|
168 | on(event: WechatyEventName, listener: (...args: any[]) => any): this;
|
169 | /**
|
170 | * @param {WechatyPlugin[]} plugins - The plugins you want to use
|
171 | *
|
172 | * this for chaining,
{Wechaty} - |
173 | *
|
174 | *
|
175 | * For wechaty ecosystem, allow user to define a 3rd party plugin for the current wechaty instance.
|
176 | *
|
177 | *
|
178 | * // The same usage with Wechaty.use().
|
179 | *
|
180 | */
|
181 | use(...plugins: (WechatyPlugin | WechatyPlugin[])[]): this;
|
182 | private installGlobalPlugin;
|
183 | private initPuppet;
|
184 | protected initPuppetEventBridge(puppet: Puppet): void;
|
185 | protected wechatifyUserModules(puppet: Puppet): void;
|
186 | /**
|
187 | * Start the bot, return Promise.
|
188 | *
|
189 | * @returns {Promise<void>}
|
190 | * @description
|
191 | * When you start the bot, bot will begin to login, need you WeChat scan qrcode to login
|
192 | * > Tips: All the bot operation needs to be triggered after start() is done
|
193 | * @example
|
194 | * await bot.start()
|
195 | * // do other stuff with bot here
|
196 | */
|
197 | start(): Promise<void>;
|
198 | /**
|
199 | * Stop the bot
|
200 | *
|
201 | * @returns {Promise<void>}
|
202 | * @example
|
203 | * await bot.stop()
|
204 | */
|
205 | stop(): Promise<void>;
|
206 | ready(): Promise<void>;
|
207 | /**
|
208 | * Logout the bot
|
209 | *
|
210 | * @returns {Promise<void>}
|
211 | * @example
|
212 | * await bot.logout()
|
213 | */
|
214 | logout(): Promise<void>;
|
215 | /**
|
216 | * Get the logon / logoff state
|
217 | *
|
218 | * @returns {boolean}
|
219 | * @example
|
220 | * if (bot.logonoff()) {
|
221 | * console.log('Bot logged in')
|
222 | * } else {
|
223 | * console.log('Bot not logged in')
|
224 | * }
|
225 | */
|
226 | logonoff(): boolean;
|
227 | /**
|
228 | * Get current user
|
229 | *
|
230 | * @returns {ContactSelf}
|
231 | * @example
|
232 | * const contact = bot.userSelf()
|
233 | * console.log(`Bot is ${contact.name()}`)
|
234 | */
|
235 | userSelf(): ContactSelf;
|
236 | say(text: string): Promise<void>;
|
237 | say(contact: Contact): Promise<void>;
|
238 | say(file: FileBox): Promise<void>;
|
239 | say(mini: MiniProgram): Promise<void>;
|
240 | say(url: UrlLink): Promise<void>;
|
241 | say(...args: never[]): Promise<never>;
|
242 | /**
|
243 | * @ignore
|
244 | */
|
245 | static version(gitHash?: boolean): string;
|
246 | /**
|
247 | * @ignore
|
248 | * Return version of Wechaty
|
249 | *
|
250 | * @param {boolean} [forceNpm=false] - If set to true, will only return the version in package.json. </br>
|
251 | * Otherwise will return git commit hash if .git exists.
|
252 | * @returns {string} - the version number
|
253 | * @example
|
254 | * console.log(Wechaty.instance().version()) // return '#git[af39df]'
|
255 | * console.log(Wechaty.instance().version(true)) // return '0.7.9'
|
256 | */
|
257 | version(forceNpm?: boolean): string;
|
258 | /**
|
259 | * @ignore
|
260 | */
|
261 | static sleep(millisecond: number): Promise<void>;
|
262 | /**
|
263 | * @ignore
|
264 | */
|
265 | sleep(millisecond: number): Promise<void>;
|
266 | /**
|
267 | * @private
|
268 | */
|
269 | ding(data?: string): void;
|
270 | /**
|
271 | * @ignore
|
272 | */
|
273 | private memoryCheck;
|
274 | /**
|
275 | * @ignore
|
276 | */
|
277 | reset(reason?: string): Promise<void>;
|
278 | unref(): void;
|
279 | }
|
280 | export { Wechaty, };
|
281 | //# sourceMappingURL=wechaty.d.ts.map |
\ | No newline at end of file |