Comments (3)
🤖
嘿,@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.
🤖
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.
@dosu-bot 怎么申请token
from wechaty.
Related Issues (20)
- 企业微信遇到的问题 HOT 4
- 重新扫码padlocal两三天了还没有人修复嘛,wechat bad request error: 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至最新版下载页面,登录不了咯, HOT 7
- 我想监听群聊中其他人进入群聊的事件,是否有提供呢 HOT 5
- 为什么使用bot.Contact.findAll()方法查找到的联系人名称都是空呢 HOT 8
- 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至 最新版下载页面,依赖都是最新版的这个怎么解决呢 HOT 2
- 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至 最新版下载页面,依赖都是最新版的这个怎么解决呢? HOT 2
- 告诉我现在个人微信可以支持发送语音的所有puppet HOT 2
- Workpro 企业微信小程序消息发送失败
- 如何识别 引用 类型的消息,目前用text获取不到 HOT 1
- 【wechaty问题交流微信群】一起讨论,吐槽,解决wechaty中遇到的坑 HOT 1
- contact.friend() HOT 1
- 什么时候可以支持消息的引用啊
- updating README
- PadLocal是不是带着小姨子跑路了 HOT 1
- 短时间多次调用room.say发送图片,发送间隔很长 HOT 5
- 你的应用版本过低,请升级击“确定”后将跳转至最新版下载页面。 HOT 1
- wechaty版本1.18+怎么获取用户唯一标识? HOT 1
- 如何强制刷新群聊列表? HOT 3
- 消息发送完成后,没有实际展示,也没有报错
- 经常中断 uncaughtException GError [AxiosError]: timeout of 60000ms exceeded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechaty.