Coder Social home page Coder Social logo

Comments (3)

dosubot avatar dosubot commented on June 10, 2024 2

🤖

嘿,@shangsheng,我们又见面了!希望你一切都好 😜

在Wechaty中,您可以使用'friendship'事件来监听好友请求。以下是一个示例,展示了如何处理通过手机号搜索返回空的微信ID的情况,以及如何区分微信提示'由于当前账号打招呼频率过高,此次打招呼消息未能发送。请注意规范使用账号。'。

import { Wechaty, log } from 'wechaty'

const bot = new Wechaty()

bot.on('friendship', async (friendship) => {
  log.info(`Received friendship: ${friendship.toString()}`)

  // 处理通过手机号搜索返回空的微信ID的情况
  const contact = await bot.Friendship.search({ phone: '1234567890' }) // 请替换为实际的手机号
  if (!contact) {
    log.info('This phone number does not have a WeChat ID.')
    return
  }

  // 处理微信提示
  if (friendship.hello() === '由于当前账号打招呼频率过高,此次打招呼消息未能发送。请注意规范使用账号。') {
    log.info('Received high frequency prompt from WeChat.')
    return
  }

  // 如果好友请求类型为接收,则接受好友请求
  if (friendship.type() === bot.Friendship.Type.Receive) {
    await friendship.accept()
  }
})

bot.start()

在这个示例中,我们首先通过手机号搜索联系人。如果没有找到联系人,我们记录一条消息并返回。然后,我们检查好友请求的问候消息。如果它匹配微信的高频提示,我们记录一条消息并返回。最后,如果好友请求类型为接收,我们接受好友请求。

请将'1234567890'替换为您要搜索的实际手机号。

参考资料:

'friendship'事件在Wechaty中是当有人发送好友请求或确认好友关系时触发的。'friendship'事件的事件监听器在提供的代码中定义为WechatyEventListenerFriendship

'friendship'事件接受一个参数,这是一个FriendshipInterface类型的对象。这个对象代表了好友请求或确认。

以下是如何使用'friendship'事件的示例:

bot.on('friendship', async (friendship) => {
  if(friendship.type() === Friendship.Type.Receive){ // 1. receive new friendship request from new contact
    const contact = friendship.contact()
    let result = await friendship.accept()
    if(result){
      console.log(`Request from ${contact.name()} is accept successfully!`)
    } else{
      console.log(`Request from ${contact.name()} failed to accept!`)
    }
  } else if (friendship.type() === Friendship.Type.Confirm) { // 2. confirm friendship
    console.log(`new friendship confirmed with ${contact.name()}`)
  }
})

在这个示例中,监听了'friendship'事件。当收到新的好友请求(Friendship.Type.Receive)时,机器人接受请求并记录接受是否成功。当确认好友关系(Friendship.Type.Confirm)时,机器人记录确认信息。

参考资料:

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

from wechaty.

dosubot avatar dosubot commented on June 10, 2024 2

🤖

Based on the information available in the Wechaty repository, there is a specific command for generating and discovering a token. This command is defined in the token.ts file and is part of the subcommands function call, which is part of the cmd-ts library. The command is named 'Token' and its description is 'Generate & Discover TOKEN for Wechaty'. The actual implementation of the commands is imported from 'wechaty-token' as cmds.

Here is the relevant code:

const token = subcommands({
  name: 'Token',
  description: 'Generate & Discover TOKEN for Wechaty',
  version: VERSION,
  cmds,
})

export { token }

This code defines a token command that can be used to generate and discover a token for Wechaty. The actual commands (cmds) are defined in the 'wechaty-token' module. However, the specific details about the 'wechaty-token' module and the commands it provides for generating and discovering a token are not available in the Wechaty repository.

You may need to look into the 'wechaty-token' module or its documentation for more details on how to use these commands to apply for a token. If you have access to the 'wechaty-token' module, you can check the exported functions or classes to see how the token generation and discovery is implemented.

If you need further assistance, please provide more details or context. Dosu is here to help!

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

from wechaty.

shangsheng avatar shangsheng commented on June 10, 2024

@dosu-bot 怎么申请token

from wechaty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.