import type TypedEventEmitter from 'typed-emitter'; import type { GError } from 'gerror'; import * as PUPPET from '@juzi/wechaty-puppet'; import type { FriendshipInterface, ContactSelfInterface, RoomInterface, RoomInvitationInterface, ContactInterface, MessageInterface, PostInterface, TagInterface, TagGroupInterface } from '../user-modules/mod.js'; declare const WECHATY_EVENT_DICT: { readonly dong: "Should be emitted after we call `Wechaty.ding()`"; readonly error: "Will be emitted when there's an Error occurred."; readonly heartbeat: "Will be emitted periodically after the Wechaty started. If not, means that the Wechaty had died."; readonly puppet: "Will be emitted when the puppet has been set."; readonly ready: "All underlined data source are ready for use."; readonly start: "Will be emitted after the Wechaty had been started."; readonly stop: "Will be emitted after the Wechaty had been stopped."; readonly 'contact-tag-add': "Will be emitted when contact has new tags."; readonly 'contact-tag-remove': "Will be emitted when contact has some tags removed."; readonly 'contact-name': "Will be emitted when contact name has been changed."; readonly 'contact-alias': "Will be emitted when contact alias has been changed."; readonly 'contact-phone': "Will be emitted when contact phone has been changed."; readonly 'contact-description': "Will be emitted when contact description has been changed."; readonly 'contact-corporation': "Will be emitted when contact corporation has been changed."; readonly 'room-owner': "Will be emitted when room owner has been changed."; readonly friendship: string; readonly login: string; readonly logout: string; readonly message: string; readonly post: string; readonly 'room-invite': string; readonly 'room-join': string; readonly 'room-leave': string; readonly 'room-topic': string; readonly 'room-announce': string; readonly scan: string; readonly tag: string; readonly 'tag-group': string; readonly 'post-comment': string; readonly 'post-tap': string; readonly 'verify-code': string; readonly dirty: string; readonly 'login-url': string; }; declare type WechatyEventName = keyof typeof WECHATY_EVENT_DICT; /** * Wechaty Event Listener Interfaces */ declare type WechatyEventListenerDong = (data?: string) => void | Promise; declare type WechatyEventListenerError = (error: GError) => void | Promise; declare type WechatyEventListenerFriendship = (friendship: FriendshipInterface) => void | Promise; declare type WechatyEventListenerHeartbeat = (data: any) => void | Promise; declare type WechatyEventListenerLogin = (user: ContactSelfInterface) => void | Promise; declare type WechatyEventListenerLogout = (user: ContactSelfInterface, reason?: string) => void | Promise; declare type WechatyEventListenerMessage = (message: MessageInterface) => void | Promise; declare type WechatyEventListenerPost = (post: PostInterface) => void | Promise; declare type WechatyEventListenerPuppet = (puppet: PUPPET.impls.PuppetInterface) => void | Promise; declare type WechatyEventListenerReady = () => void | Promise; declare type WechatyEventListenerRoomInvite = (roomInvitation: RoomInvitationInterface) => void | Promise; declare type WechatyEventListenerRoomJoin = (room: RoomInterface, inviteeList: ContactInterface[], inviter: ContactInterface, date?: Date) => void | Promise; declare type WechatyEventListenerRoomLeave = (room: RoomInterface, leaverList: ContactInterface[], remover?: ContactInterface, date?: Date) => void | Promise; declare type WechatyEventListenerRoomTopic = (room: RoomInterface, newTopic: string, oldTopic: string, changer: ContactInterface, date?: Date) => void | Promise; declare type WechatyEventListenerRoomAnnounce = (room: RoomInterface, newAnnounce: string, changer?: ContactInterface, oldAnnounce?: string, date?: Date) => void | Promise; declare type WechatyEventListenerRoomOwner = (room: RoomInterface, newOwner: ContactInterface, oldOwner: ContactInterface) => void | Promise; declare type WechatyEventListenerScan = (qrcode: string, status: PUPPET.types.ScanStatus, data: string, type: PUPPET.types.ScanType, createDate: Date, expireDate?: Date) => void | Promise; declare type WechatyEventListenerStartStop = () => void | Promise; declare type WechatyEventListenerContactTagAdd = (contact: ContactInterface, tagList: TagInterface[]) => void | Promise; declare type WechatyEventListenerContactTagRemove = (contact: ContactInterface, tagList: TagInterface[]) => void | Promise; declare type WechatyEventListenerContactName = (contact: ContactInterface, newName: string, oldName: string) => void | Promise; declare type WechatyEventListenerContactPhone = (contact: ContactInterface, newPhoneList: string[], oldPhoneList: []) => void | Promise; declare type WechatyEventListenerContactAlias = (contact: ContactInterface, newAlias: string, oldAlias: string) => void | Promise; declare type WechatyEventListenerContactDescription = (contact: ContactInterface, newDescription: string, oldDescription: string) => void | Promise; declare type WechatyEventListenerContactCorporation = (contact: ContactInterface, newCorporation: string, oldCorporation: string) => void | Promise; declare type WechatyEventListenerTag = (type: PUPPET.types.TagEvent, list: TagInterface[], date?: Date) => void | Promise; declare type WechatyEventListenerTagGroup = (type: PUPPET.types.TagGroupEvent, list: TagGroupInterface[], date?: Date) => void | Promise; declare type WechatyEventListenerPostComment = (comment: PostInterface, post: PostInterface) => void | Promise; declare type WechatyEventListenerPostTap = (post: PostInterface, contact: ContactInterface, type: PUPPET.types.Tap, tap: boolean, date?: Date) => void | Promise; declare type WechatyEventListenerVerifyCode = (id: string, message: string, scene: PUPPET.types.VerifyCodeScene, status: PUPPET.types.VerifyCodeStatus) => void | Promise; declare type WechatyEventListenerDirty = (id: string, type: PUPPET.types.Dirty) => void | Promise; declare type WechatyEventListenerLoginUrl = (url: string) => void | Promise; /** * @desc Wechaty Class Event Type * @typedef WechatyEventName * @property {string} error - When the bot get error, there will be a Wechaty error event fired. * @property {string} login - After the bot login full successful, the event login will be emitted, with a Contact of current logged in user. * @property {string} logout - Logout will be emitted when bot detected log out, with a Contact of the current login user. * @property {string} heartbeat - Get heartbeat of the bot. * @property {string} friendship - When someone sends you a friend request, there will be a Wechaty friendship event fired. * @property {string} message - Emit when there's a new message. * @property {string} ready - Emit when all data has load completed, in wechaty-puppet-padchat, it means it has sync Contact and Room completed * @property {string} room-join - Emit when anyone join any room. * @property {string} room-topic - Get topic event, emitted when someone change room topic. * @property {string} room-leave - Emit when anyone leave the room.
* - If someone leaves the room by themselves, WeChat will not notice other people in the room, so the bot will never get the "leave" event. * @property {string} room-invite - Emit when there is a room invitation, see more in {@link RoomInvitation} * @property {string} scan - A scan event will be emitted when the bot needs to show you a QR Code for scanning.
* It is recommend to install qrcode-terminal(run `npm install qrcode-terminal`) in order to show qrcode in the terminal. */ /** * @desc Wechaty Class Event Function * @typedef WechatyEventFunction * @property {Function} error -(this: Wechaty, error: Error) => void | Promise callback function * @property {Function} login -(this: Wechaty, user: ContactSelf)=> void * @property {Function} logout -(this: Wechaty, user: ContactSelf) => void | Promise * @property {Function} scan -(this: Wechaty, url: string, code: number) => void | Promise
*
    *
  1. URL: {String} the QR code image URL
  2. *
  3. code: {Number} the scan status code. some known status of the code list here is:
  4. *
*
    *
  • 0 initial_
  • *
  • 200 login confirmed
  • *
  • 201 scanned, wait for confirm
  • *
  • 408 waits for scan
  • *
* @property {Function} heartbeat -(this: Wechaty, data: any) => void | Promise * @property {Function} friendship -(this: Wechaty, friendship: Friendship) => void | Promise * @property {Function} message -(this: Wechaty, message: Message) => void | Promise * @property {Function} ready -(this: Wechaty) => void | Promise * @property {Function} room-join -(this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void | Promise * @property {Function} room-topic -(this: Wechaty, room: Room, newTopic: string, oldTopic: string, changer: Contact) => void | Promise * @property {Function} room-leave -(this: Wechaty, room: Room, leaverList: Contact[]) => void | Promise * @property {Function} room-invite -(this: Wechaty, room: Room, roomInvitation: RoomInvitation) => void | Promise
* see more in {@link RoomInvitation} */ /** * @listens Wechaty * @param {WechatyEventName} event - Emit WechatyEvent * @param {WechatyEventFunction} listener - Depends on the WechatyEvent * * @return {Wechaty} - this for chaining, * see advanced {@link https://github.com/wechaty/getting-started/wiki/FAQ#36-why-wechatyonevent-listener-return-wechaty|chaining usage} * * @desc * When the bot get message, it will emit the following Event. * * You can do anything you want when in these events functions. * The main Event name as follows: * - **scan**: Emit when the bot needs to show you a QR Code for scanning. After scan the qrcode, you can login * - **login**: Emit when bot login full successful. * - **logout**: Emit when bot detected log out. * - **message**: Emit when there's a new message. * * see more in {@link WechatyEventName} * * @example Event:scan * // Scan Event will emit when the bot needs to show you a QR Code for scanning * * bot.on('scan', (url, status) => { * console.log(`[${status}] Scan ${url} to login.` ) * }) * * @example Event:login * // Login Event will emit when bot login full successful. * * bot.on('login', (user) => { * console.log(`user ${user} login`) * }) * * @example Event:logout * // Logout Event will emit when bot detected log out. * * bot.on('logout', (user) => { * console.log(`user ${user} logout`) * }) * * @example Event:message * // Message Event will emit when there's a new message. * * wechaty.on('message', (message) => { * console.log(`message ${message} received`) * }) * * @example Event:friendship * // Friendship Event will emit when got a new friend request, or friendship is confirmed. * * bot.on('friendship', (friendship) => { * if(friendship.type() === Friendship.Type.Receive){ // 1. receive new friendship request from new contact * const contact = friendship.contact() * let result = await friendship.accept() * if(result){ * console.log(`Request from ${contact.name()} is accept successfully!`) * } else{ * console.log(`Request from ${contact.name()} failed to accept!`) * } * } else if (friendship.type() === Friendship.Type.Confirm) { // 2. confirm friendship * console.log(`new friendship confirmed with ${contact.name()}`) * } * }) * * @example Event:room-join * // room-join Event will emit when someone join the room. * * bot.on('room-join', (room, inviteeList, inviter) => { * const nameList = inviteeList.map(c => c.name()).join(',') * console.log(`Room ${room.topic()} got new member ${nameList}, invited by ${inviter}`) * }) * * @example Event:room-leave * // room-leave Event will emit when someone leave the room. * * bot.on('room-leave', (room, leaverList) => { * const nameList = leaverList.map(c => c.name()).join(',') * console.log(`Room ${room.topic()} lost member ${nameList}`) * }) * * @example Event:room-topic * // room-topic Event will emit when someone change the room's topic. * * bot.on('room-topic', (room, topic, oldTopic, changer) => { * console.log(`Room ${room.topic()} topic changed from ${oldTopic} to ${topic} by ${changer.name()}`) * }) * * @example Event:room-invite, RoomInvitation has been encapsulated as a RoomInvitation Class. * // room-invite Event will emit when there's an room invitation. * * bot.on('room-invite', async roomInvitation => { * try { * console.log(`received room-invite event.`) * await roomInvitation.accept() * } catch (e) { * console.error(e) * } * }) * * @example Event:error * // error Event will emit when there's an error occurred. * * bot.on('error', (error) => { * console.error(error) * }) */ interface WechatyEventListeners { 'room-invite': WechatyEventListenerRoomInvite; 'room-join': WechatyEventListenerRoomJoin; 'room-leave': WechatyEventListenerRoomLeave; 'room-topic': WechatyEventListenerRoomTopic; 'room-announce': WechatyEventListenerRoomAnnounce; dong: WechatyEventListenerDong; error: WechatyEventListenerError; friendship: WechatyEventListenerFriendship; heartbeat: WechatyEventListenerHeartbeat; login: WechatyEventListenerLogin; logout: WechatyEventListenerLogout; message: WechatyEventListenerMessage; post: WechatyEventListenerPost; puppet: WechatyEventListenerPuppet; ready: WechatyEventListenerReady; scan: WechatyEventListenerScan; start: WechatyEventListenerStartStop; stop: WechatyEventListenerStartStop; 'contact-tag-add': WechatyEventListenerContactTagAdd; 'contact-tag-remove': WechatyEventListenerContactTagRemove; 'contact-name': WechatyEventListenerContactName; 'contact-alias': WechatyEventListenerContactAlias; 'contact-phone': WechatyEventListenerContactPhone; 'contact-description': WechatyEventListenerContactDescription; 'contact-corporation': WechatyEventListenerContactCorporation; 'room-owner': WechatyEventListenerRoomOwner; 'tag': WechatyEventListenerTag; 'tag-group': WechatyEventListenerTagGroup; 'post-comment': WechatyEventListenerPostComment; 'post-tap': WechatyEventListenerPostTap; 'verify-code': WechatyEventListenerVerifyCode; 'dirty': WechatyEventListenerDirty; 'login-url': WechatyEventListenerLoginUrl; } declare const WechatyEventEmitter: new () => TypedEventEmitter; export type { WechatyEventName, WechatyEventListeners, WechatyEventListenerDong, WechatyEventListenerError, WechatyEventListenerFriendship, WechatyEventListenerHeartbeat, WechatyEventListenerLogin, WechatyEventListenerLogout, WechatyEventListenerMessage, WechatyEventListenerPost, WechatyEventListenerPuppet, WechatyEventListenerReady, WechatyEventListenerRoomInvite, WechatyEventListenerRoomJoin, WechatyEventListenerRoomLeave, WechatyEventListenerRoomTopic, WechatyEventListenerRoomOwner, WechatyEventListenerRoomAnnounce, WechatyEventListenerScan, WechatyEventListenerStartStop, WechatyEventListenerContactTagAdd, WechatyEventListenerContactTagRemove, WechatyEventListenerContactName, WechatyEventListenerContactAlias, WechatyEventListenerContactPhone, WechatyEventListenerContactDescription, WechatyEventListenerContactCorporation, WechatyEventListenerTag, WechatyEventListenerTagGroup, WechatyEventListenerPostComment, WechatyEventListenerPostTap, WechatyEventListenerVerifyCode, WechatyEventListenerDirty, WechatyEventListenerLoginUrl, }; export { WechatyEventEmitter, }; //# sourceMappingURL=wechaty-events.d.ts.map