未验证 提交 fb47be47 编写于 作者: S SuperChang 提交者: GitHub

Support delay to accept room invitation (#1910)

* 0.29.3

* feat: support delay accept room invitation

* 0.31.4

* modify: bump wechaty-puppet version up

* modify: add examples for the new methods.

* modify: refactor

* modify: bump wechaty-puppet version
上级 4868ee17
......@@ -97,7 +97,7 @@
"read-pkg-up": "^7.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.19.1",
"wechaty-puppet": "^0.19.5",
"ws": "^7.0.0"
},
"devDependencies": {
......
......@@ -37,6 +37,7 @@ import {
import {
Contact,
} from './contact'
import { RoomInvitationPayload } from 'wechaty-puppet'
/**
*
......@@ -267,4 +268,51 @@ export class RoomInvitation extends Accessory implements Acceptable {
return ageSeconds
}
/**
* Load the room invitation info from disk
*
* @returns {RoomInvitation}
* @example
* const bot = new Wechaty()
* const dataFromDisk // get the room invitation info data from disk
* const roomInvitation = await bot.RoomInvitation.fromJSON(dataFromDisk)
* await roomInvitation.accept()
*/
public static async fromJSON (
payload: string | RoomInvitationPayload,
): Promise<RoomInvitation> {
log.verbose('RoomInvitation', 'fromJSON(%s)',
typeof payload === 'string'
? payload
: JSON.stringify(payload),
)
if (typeof payload === 'string') {
payload = JSON.parse(payload) as RoomInvitationPayload
}
await this.puppet.roomInvitationPayload(payload.id, payload)
return this.wechaty.RoomInvitation.load(payload.id)
}
/**
* Get the room invitation info when listened on room-invite event
*
* @returns {string}
* @example
* const bot = new Wechaty()
* bot.on('room-invite', async roomInvitation => {
* const roomInvitation = bot.RoomInvitation.load(roomInvitation.id)
* const jsonData = await roomInvitation.toJSON(roomInvitation.id)
* // save the json data to disk, and we can use it by RoomInvitation.fromJSON()
* }
* .start()
*/
public async toJSON (): Promise<string> {
log.verbose('RoomInvitation', `toJSON()`)
const payload = await this.puppet.roomInvitationPayload(this.id)
return JSON.stringify(payload)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册