提交 6ed83490 编写于 作者: Y Yuan Gao 提交者: Huan (李卓桓)

Add `Message.recalled()` (#1735)

* add impl for recalled on Message

* 0.25.3

* refactor test to make code climate happy

* Revert "refactor test to make code climate happy"

This reverts commit 1f95756a.

* revise code according to review and add example code for toRecalled()

* move code inside try block
上级 32ee9ea5
{
"name": "wechaty",
"version": "0.25.2",
"version": "0.25.3",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
......
此差异已折叠。
......@@ -387,6 +387,38 @@ export class Message extends Accessory implements Sayable {
return this.payload.text || ''
}
/**
* Get the recalled message
*
* @example
* const bot = new Wechaty()
* bot
* .on('message', async m => {
* if (m.type() === MessageType.Recalled) {
* const recalledMessage = await m.toRecalled()
* console.log(`Message: ${recalledMessage} has been recalled.`)
* }
* })
* .start()
*/
public async toRecalled (): Promise<Message | null> {
if (this.type() !== MessageType.Recalled) {
throw new Error('Can not call toRecalled() on message which is not recalled type.')
}
const originalMessageId = this.text()
if (!originalMessageId) {
throw new Error('Can not find recalled message')
}
try {
const message = this.wechaty.Message.load(originalMessageId)
await message.ready()
return message
} catch (e) {
log.verbose(`Can not retrieve the recalled message with id ${originalMessageId}.`)
return null
}
}
public async say (text: string, mention?: Contact | Contact[]) : Promise<void>
public async say (contact: Contact) : Promise<void>
public async say (file: FileBox) : Promise<void>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册