Skip to main content

Making friends

Sending Request#

async function onReady () {
const weixin = 'FridayBOT' // weixin id
const contact = await bot.Friendship.search({ weixin })
if (contact) {
console.info('Sending friend request...')
await bot.Friendship.add(contact)
} else {
console.info('Friendship.search: not found')
}
}
bot.on('ready', onReady)

Receiving Request#

import { Friendship } from 'wechaty'
async function onFriendship (friendship: Friendship) {
if (friendship.type() === Friendship.Type.Receive) {
console.info('New requrest from', friendship.contact())
console.info('Hello message:', friendship.hello())
await friendship.accept()
} else if (friendship.type() === Friendship.Type.Confirm) {
console.info('New request confirmed with', friendship.contact().name())
}
}
bot.on('friendship', onFriendship)
Last updated on by Leo_chen