How to use the wechaty.Friendship.Type function in wechaty

To help you get started, we’ve selected a few wechaty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wechaty / wechaty-getting-started / examples / advanced / friend-bot.js View on Github external
// if want to send msg , you need to delay sometimes
          await new Promise(r => setTimeout(r, 1000))
          await friendship.contact().say('hello from Wechaty')
          console.log('after accept')

        } else {
          logMsg = 'not auto accepted, because verify message is: ' + friendship.hello()
        }
        break

        /**
         *
         * 2. Friend Ship Confirmed
         *
         */
      case Friendship.Type.Confirm:
        logMsg = 'friend ship confirmed with ' + friendship.contact().name()
        break
    }
  } catch (e) {
    logMsg = e.message
  }

  console.log(logMsg)
  await fileHelper.say(logMsg)

})
github wechaty / wechaty-getting-started / examples / advanced / gist-bot / on-friend.js View on Github external
async function onFriendship (
  request,
) {
  try {
    const contact = request.contact()

    if (request.type() === Friendship.Type.Confirm) {
      console.info('New friend ' + contact.name() + ' relationship confirmed!')
      return
    }

    /********************************************
     *
     * 从这里开始修改 vvvvvvvvvvvv
     *
     */
    await request.accept()

    setTimeout(
      async _ => {
        await contact.say('thank you for adding me')
      },
      3000,
github gengchen528 / wechat-assistant / wechaty / listeners / on-friend.js View on Github external
async function onFriend(friendship) {
  let logMsg,hello;
  try {
    name = friendship.contact().name()
    hello = friendship.hello()
    logMsg = name + ',发送了好友请求';
    console.log(logMsg);
    switch (friendship.type()) {
      case Friendship.Type.Receive:
        if (config.ACCEPTFRIEND.length == 0) {
          console.log('无认证关键词,30秒后将会自动通过好友请求')
          await lib.delay(30000);
          await friendship.accept();
        } else if (config.ACCEPTFRIEND.length>0&&config.ACCEPTFRIEND.includes(hello)) {
          console.log(`触发关键词${hello},30秒后自动通过好友请求`)
          await lib.delay(3000); 
          await friendship.accept();
        }
        break;
      case Friendship.Type.Confirm:
        logMsg = '已确认添加好友:' + name;
        console.log(logMsg)
        break;
    }
  } catch (e) {