提交 36675b88 编写于 作者: S SuperChang 提交者: Huan (李卓桓)

Implement toContact() method (#1868)

* feat: implement toContact() method

* modify: bump version
上级 550303f9
{
"name": "wechaty",
"version": "0.29.3",
"version": "0.29.4",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
......@@ -98,7 +98,7 @@
"semver": "^6.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.16.1",
"wechaty-puppet": "^0.17.1",
"ws": "^7.0.0"
},
"devDependencies": {
......
......@@ -900,14 +900,20 @@ export class Message extends Accessory implements Sayable {
* @returns {Promise<Contact>}
*/
public async toContact (): Promise<Contact> {
log.warn('Message', 'toContact() to be implemented')
log.verbose('Message', 'toContact()')
if (this.type() === Message.Type.Contact) {
if (this.type() !== Message.Type.Contact) {
throw new Error('message not a ShareCard')
}
// TODO: return the ShareCard Contact
const contact = this.wechaty.userSelf()
const contactId = await this.puppet.messageContact(this.id)
if (!contactId) {
throw new Error(`can not get Contact id by message: ${contactId}`)
}
const contact = this.wechaty.Contact.load(contactId)
await contact.ready()
return contact
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册