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

Friend search (#1895)

* 0.29.3

* modify: recorrect the mini-program payload type according to puppet mini-program.

* temp

* feat: support search new friend

* modify: change parameter for search()

* modify: optimize code, bump version

* modify: bump wechaty and wechaty-puppet version

* better search function

* 0.29.23

* 0.29.24

* 0.29.25

* 0.29.26

* 0.29.27

* 0.29.28

* 0.29.29

* 0.29.30

* 0.29.31
Co-authored-by: Huan (李卓桓)'s avatarHuan (李卓桓) <zixia@zixia.net>
上级 d2ef571c
{
"name": "wechaty",
"version": "0.29.35",
"version": "0.29.40",
"description": "Wechaty is a Bot SDK for Wechat Personal Account",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
......@@ -100,7 +100,7 @@
"read-pkg-up": "^7.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.17.5",
"wechaty-puppet": "^0.17.10",
"ws": "^7.0.0"
},
"devDependencies": {
......
......@@ -35,7 +35,8 @@ import {
import {
FriendshipPayload,
FriendshipType,
} from 'wechaty-puppet'
FriendshipSearchQueryFilter,
} from 'wechaty-puppet'
import {
Acceptable,
......@@ -70,6 +71,40 @@ export class Friendship extends Accessory implements Acceptable {
return newFriendship
}
/**
* Search a Friend by phone or weixin.
*
* The best practice is to search friend request once per minute.
* Remeber not to do this too frequently, or your account may be blocked.
*
* @param {FriendshipSearchCondition} condition - Search friend by phone or weixin.
* @returns {Promise<Contact>}
*
* @example
* const friend_phone = await bot.Friendship.search({phone: '13112341234'})
* const friend_weixin = await bot.Friendship.search({weixin: 'weixin_account'})
*
* console.log(`This is the new friend info searched by phone : ${friend_phone}`)
* await bot.Friendship.add(friend_phone, 'hello')
*
*/
public static async search (
queryFiter : FriendshipSearchQueryFilter,
): Promise<null | Contact> {
log.verbose('Friendship', 'static search("%s")',
JSON.stringify(queryFiter),
)
const contactId = await this.puppet.friendshipSearch(queryFiter)
if (!contactId) {
return null
}
const contact = this.wechaty.Contact.load(contactId)
await contact.ready()
return contact
}
/**
* @description
* use {@link Friendship#add} instead
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册