Send, receive friend request, and friend confirmation events.
- send request
- receive request(in friend event)
- confirmation friendship(friend event)
Kind: global class
- Friendship
- instance
- .accept()
Promise.<void>
- .hello()
string
- .contact()
Contact
- .type()
FriendshipType
- .accept()
- static
.send()- .add(contact, hello)
Promise.<void>
- instance
Return the type of: Promise.<void>
Accept Friend Request
Kind: instance method of Friendship
Example
const bot = new Wechaty()
bot.on('friendship', async friendship => {
try {
console.log(`received friend event.`)
switch (friendship.type()) {
// 1. New Friend Request
case Friendship.Type.Receive:
await friendship.accept()
break
// 2. Friend Ship Confirmed
case Friendship.Type.Confirm:
console.log(`friend ship confirmed`)
break
}
} catch (e) {
console.error(e)
}
}
.start()
Return the type of: string
Get verify message from
Kind: instance method of Friendship
Example (If request content is `ding`, then accept the friendship)
const bot = new Wechaty()
bot.on('friendship', async friendship => {
try {
console.log(`received friend event from ${friendship.contact().name()}`)
if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
await friendship.accept()
}
} catch (e) {
console.error(e)
}
}
.start()
Return the type of: Contact
Get the contact from friendship
Kind: instance method of Friendship
Example
const bot = new Wechaty()
bot.on('friendship', async friendship => {
const contact = friendship.contact()
const name = contact.name()
console.log(`received friend event from ${name}`)
}
.start()
Return the type of: FriendshipType
Return the Friendship Type
Tips: FriendshipType is enum here.
- FriendshipType.Unknown
- FriendshipType.Confirm
- FriendshipType.Receive
- FriendshipType.Verify
Kind: instance method of Friendship
Example (If request content is `ding`, then accept the friendship)
const bot = new Wechaty()
bot.on('friendship', async friendship => {
try {
if (friendship.type() === Friendship.Type.Receive && friendship.hello() === 'ding') {
await friendship.accept()
}
} catch (e) {
console.error(e)
}
}
.start()
Deprecated
use Friendship#add instead
Kind: static method of Friendship
Return the type of: Promise.<void>
Send a Friend Request to a contact
with message hello
.
The best practice is to send friend request once per minute. Remeber not to do this too frequently, or your account may be blocked.
Kind: static method of Friendship
Param | Type | Description |
---|---|---|
contact | Contact |
Send friend request to contact |
hello | string |
The friend request content |
Example
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!')
}