使用自动拉人入群功能
Created by: icepy
1. Expected behavior
Question: What behavior do you expect?
Answer: 给联系人发送一个入群邀请
2. Actual behavior
Question: What actual behavior did you experience?
Answer: 直接报错,日志如下
(node:9351) UnhandledPromiseRejectionWarning: Error: topicFilter not found
at Function.<anonymous> (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:125:23)
at Generator.next (<anonymous>)
at /Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:7:71
at new Promise (<anonymous>)
at __awaiter (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:3:12)
at Function.findAll (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:122:16)
at Function.<anonymous> (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:164:41)
at Generator.next (<anonymous>)
at /Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:7:71
at new Promise (<anonymous>)
at __awaiter (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:3:12)
at Function.find (/Users/xiangwenwen/entropage/wechaty-getting-started/node_modules/wechaty/dist/src/user/room.js:159:16)
at autoAddContact (/Users/xiangwenwen/entropage/wechaty-getting-started/examples/starter-bot.js:44:31)
at EventEmitter.eventEmitter.once (/Users/xiangwenwen/entropage/wechaty-getting-started/examples/starter-bot.js:56:3)
at Object.onceWrapper (events.js:273:13)
at EventEmitter.emit (events.js:182:13)
at EventEmitter.emit (domain.js:442:20)
at Wechaty.onMessage (/Users/xiangwenwen/entropage/wechaty-getting-started/examples/starter-bot.js:38:20)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:9351) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:9351) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
代码如下:
在message callback 里查询到群的topic,然后使用:
async function onMessage (msg) {
console.log(msg.toString())
const room = msg.room();
if (room) {
const topic = await room.topic();
if (topic === 'Flutter 学习小组') {
eventEmitter.emit('find-entropage', topic);
}
}
}
async function autoAddContact(topic){
const room = await bot.Room.find({name: topic});
const contact = await bot.Contact.find({name: '山野'});
if (room) {
try {
room.add(contact);
} catch(e) {
console.log(JSON.stringify(e));
}
}
}
eventEmitter.once('find-entropage', (topic) => {
autoAddContact(topic);
});
3. Steps to reproduce your problem (and fixes, if any)
This part is very important: if you can not provide any reproduce steps, then the problem will be very hard to be recognized.
Question: What're the reproducible steps for us to see your problem?
Answer: