From db9dd130e0ff93979d2815f870f62bcabd0debb8 Mon Sep 17 00:00:00 2001 From: Yuan Gao Date: Wed, 19 Aug 2020 13:50:29 +0800 Subject: [PATCH] add phone method in contact class (#2039) * add phone method in contact class * 0.47.13 * 0.47.14 * update wechaty-puppet version * add jsdoc for contact.phone --- package.json | 6 +++--- src/user/contact.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1b7236fa..16c14a6b 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "wechaty", - "version": "0.47.13", + "version": "0.47.14", "description": "Wechaty is Conversational SDK Chatbot Makers, Powered by TypeScript, Docker, and 💖", "main": "dist/src/mod.js", "typings": "dist/src/mod.d.ts", "engines": { "node": ">= 12", - "wechaty-puppet": ">=0.30.3" + "wechaty-puppet": ">=0.31.1" }, "wechaty": { "DEFAULT_PORT": 8080, @@ -103,7 +103,7 @@ "typed-emitter": "^1.2.0", "watchdog": "^0.8.17", "wechaty-puppet-hostie": "^0.9.13", - "wechaty-puppet": "^0.30.3", + "wechaty-puppet": "^0.31.1", "ws": "^7.2.3" }, "devDependencies": { diff --git a/src/user/contact.ts b/src/user/contact.ts index d3cb7c63..594920d9 100644 --- a/src/user/contact.ts +++ b/src/user/contact.ts @@ -537,6 +537,51 @@ class Contact extends ContactEventEmitter implements Sayable { } } + /** + * GET / SET / DELETE the phone list for a contact + * + * @param {(none | string[])} phoneList + * @returns {(Promise)} + * @example GET the phone list for a contact, return {(Promise)} + * const phoneList = await contact.phone() + * if (phone.length === 0) { + * console.log('You have not yet set any phone number for contact ' + contact.name()) + * } else { + * console.log('You have already set phone numbers for contact ' + contact.name() + ':' + phoneList.join(',')) + * } + * + * @example SET the phoneList for a contact + * try { + * const phoneList = ['13999999999', '13888888888'] + * await contact.alias(phoneList) + * console.log(`change ${contact.name()}'s phone successfully!`) + * } catch (e) { + * console.log(`failed to change ${contact.name()} phone!`) + * } + */ + public async phone (): Promise + public async phone (phoneList: string[]): Promise + public async phone (phoneList?: string[]): Promise { + log.silly('Contact', 'phone(%s)', phoneList === undefined ? '' : JSON.stringify(phoneList)) + + if (!this.payload) { + throw new Error('no payload') + } + + if (typeof phoneList === 'undefined') { + return this.wechaty.puppet.contactPhone(this.id) + } + + try { + await this.wechaty.puppet.contactPhone(this.id, phoneList) + await this.wechaty.puppet.contactPayloadDirty(this.id) + this.payload = await this.wechaty.puppet.contactPayload(this.id) + } catch (e) { + log.error('Contact', 'phone(%s) rejected: %s', JSON.stringify(phoneList), e.message) + Raven.captureException(e) + } + } + /** * * @description -- GitLab