diff --git a/docusaurus/docs/api/friendship.md b/docusaurus/docs/api/friendship.md index e030ceed695..b377db96fca 100644 --- a/docusaurus/docs/api/friendship.md +++ b/docusaurus/docs/api/friendship.md @@ -125,20 +125,63 @@ bot.on('friendship', async friendship => { .start() ``` -### Friendship.add\(contact, hello\) ⇒ `Promise ` +### Friendship.search\(phone\) ⇒ `Promise ` + +The method search contact by phone number and get a `contact`. The best practice is to send friend request once per minute. Remember not to do this too frequently, or your account may be blocked. + +| Param | Type | Description | +| :--- | :--- | :--- | +| phone | `number` | search phone number | + +#### Example + +```javascript +const phone = '131xxx1234' +const searchContact = await bot.Friendship.search({ + phone, +}) +``` + +### Friendship.add\(contact, options\) ⇒ `Promise ` The method sends a Friend Request to a `contact` with message `hello`.The best practice is to send friend request once per minute. Remember not to do this too frequently, or your account may be blocked. | Param | Type | Description | | :--- | :--- | :--- | | contact | `Contact` | Send friend request to contact | -| hello | `string` | The friend request content | +| options | `FriendshipAddOptions` | The friend request option | -#### Example +#### Example \(add searched contact\) + +```javascript +await bot.Friendship.add(searchContact, { hello: 'Nice to meet you! I am wechaty bot!' }) +``` + +#### Example \(add room member\) ```javascript const memberList = await room.memberList() for (let i = 0; i < memberList.length; i++) { - await bot.Friendship.add(member, 'Nice to meet you! I am wechaty bot!') + await bot.Friendship.add(member, { + room: message.room(), + hello: 'Nice to meet you! I am wechaty bot!', + }) +} + +``` + +#### Example \(add contact card\) + +```javascript +if (message.type() === bot.Message.Type.Contact) { + const contact = await message.toContact() + const options = { + contact: message.talker(), + hello: 'Nice to meet you! I am wechaty bot!', + } + if (message.room()) { + options.room = message.room() + } + await bot.Friendship.add(contact, options) } ```