Bug on message.mention() method when messages sent by PC/Mac wechat
Created by: cameron93lin
Provide Your Network Information
Out China DigitalOcean
npm run doctor
or wechaty run doctor
(for docker user), paste output here
Run Wechaty Doctor
- Wechaty version: #git[1af7793]
- Linux x64 version 4.4.0-127-generic memory 200/992 MB
- Docker: false
- Node version: v10.6.0
- Tcp IPC TEST: PASS
Expected behavior
Get mention list
Actual behavior
If the user mention someone via IOS wechat or Android wechat, the bot can get mention list by message.mention(). However, if the user mention someone via Windows wechat or Mac wechat, the bot can not get mention list by message.mention().
Steps to reproduce the behavior (and fixes, if any)
Tried to log the JSON.stringify() for the message. Here is the output
19:27:28 INFO Wechaty <Puppet#0<PuppetPadchat>()/PuppetPadchat#0> start() v#git[1af7793] is starting...
| __ __ _ _
| \ \ / /__ ___| |__ __ _| |_ _ _
| \ \ /\ / / _ \/ __| '_ \ / _` | __| | | |
| \ V V / __/ (__| | | | (_| | |_| |_| |
| \_/\_/ \___|\___|_| |_|\__,_|\__|\__, |
| |___/
=============== Powered by Wechaty ===============
-------- https://github.com/chatie/wechaty --------
Version: 0.19.113
I'm a bot, my superpower is talk in Wechat.
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me to more superpowers!
Please wait... I'm trying to login in...
UNLGuide login
Message#Text(👥Room<testroom>🗣Contact<林昊坤>👤Contact<UNLGuide>)<啊>
{"domain":null,"_events":{},"_eventsCount":0,"id":"2325293998016036117","payload":{"id":"2325293998016036117","timestamp":1532805263,"type":6,"fromId":"mike93star","roomId":"5983158076@chatroom","text":"啊","toId":"wxid_qppaw9v0jz412"}}
Message discarded because its TOO OLD(than 1 minute)
Message#Text(👥Room<testroom>🗣Contact<林昊坤>👤Contact<UNLGuide>)<test>
{"domain":null,"_events":{},"_eventsCount":0,"id":"1607858285795942644","payload":{"id":"1607858285795942644","timestamp":1532806024,"type":6,"fromId":"mike93star","roomId":"5983158076@chatroom","text":"test","toId":"wxid_qppaw9v0jz412"}}
Message#Text(👥Room<testroom>🗣Contact<林昊坤>👤Contact<UNLGuide>)<test>
{"domain":null,"_events":{},"_eventsCount":0,"id":"1248288888237367453","payload":{"id":"1248288888237367453","timestamp":1532806066,"type":6,"fromId":"mike93star","roomId":"5983158076@chatroom","text":"test","toId":"wxid_qppaw9v0jz412"}}
[]
[]
Message#Text(👥Room<testroom>🗣Contact<林昊坤>👤Contact<UNLGuide>)<@UNLGuide This message is sent by Windows wechat>
{"domain":null,"_events":{},"_eventsCount":0,"id":"9188518001739378141","payload":{"id":"9188518001739378141","timestamp":1532806090,"type":6,"fromId":"mike93star","roomId":"5983158076@chatroom","text":"@UNLGuide This message is sent by Windows wechat","toId":"wxid_qppaw9v0jz412"}}
[]
Message#Text(👥Room<testroom>🗣Contact<林昊坤>👤Contact<UNLGuide>)<@UNLGuide This is sent by IOS wechat>
{"domain":null,"_events":{},"_eventsCount":0,"id":"8323233247060153478","payload":{"id":"8323233247060153478","timestamp":1532806119,"type":6,"fromId":"mike93star","roomId":"5983158076@chatroom","text":"@UNLGuide This is sent by IOS wechat","toId":"wxid_qppaw9v0jz412"}}
[ Contact {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
id: 'wxid_qppaw9v0jz412',
payload:
{ alias: '',
avatar:
'http://wx.qlogo.cn/mmhead/icTdbqWNOwNS6ibQ7CxgibzdWe5q0QiaIHYcul3vewia8libpVFYYzZmASSg/0',
city: '',
gender: 0,
id: 'wxid_qppaw9v0jz412',
name: 'UNLGuide',
province: '',
signature: '',
type: 1,
friend: false },
[Symbol(name)]: 'Contact<undefined>',
[Symbol(counter)]: 8 } ]
Message#Unknown(👥Room<testroom>🗣Contact<UNLGuide>)<<msg>
<op id='2'>
<username>5983158076@chatroom</username>
</op>
</msg>
{"domain":null,"_events":{},"_eventsCount":0,"id":"9061310802386479943","payload":{"id":"9061310802386479943","timestamp":1532806138,"type":0,"fromId":"wxid_qppaw9v0jz412","roomId":"5983158076@chatroom","text":"<msg>\n<op id='2'>\n<username>5983158076@chatroom</username>\n</op>\n</msg>"}}
[]
Message#Text(👥Room<testroom>🗣Contact<UNLGuide>)<@林昊坤 This is sent by Android wechat>
{"domain":null,"_events":{},"_eventsCount":0,"id":"2071233528889721529","payload":{"id":"2071233528889721529","timestamp":1532806158,"type":6,"fromId":"wxid_qppaw9v0jz412","roomId":"5983158076@chatroom","text":"@林昊坤 This is sent by Android wechat"}}
[ Contact {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
id: 'mike93star',
payload:
{ alias: '',
avatar:
'http://wx.qlogo.cn/mmhead/Q79zmeHemBkYeEOoNCjus4CXblUpxib9kdCYrficUz31Y/0',
city: 'Guangzhou',
gender: 1,
id: 'mike93star',
name: '林昊坤',
province: 'Guangdong',
signature: '哟哟切克闹,牛肉拉肠来一套!',
type: 1,
friend: true },
[Symbol(name)]: 'Contact<undefined>',
[Symbol(counter)]: 5 } ]
Message#Text(👥Room<testroom>🗣Contact<Kiwi_>👤Contact<UNLGuide>)<@UNLGuide This is sent by Mac wechat>
{"domain":null,"_events":{},"_eventsCount":0,"id":"3896229268494902507","payload":{"id":"3896229268494902507","timestamp":1532806455,"type":6,"fromId":"yuanqm814","roomId":"5983158076@chatroom","text":"@UNLGuide This is sent by Mac wechat","toId":"wxid_qppaw9v0jz412"}}
[]
Please see below for the console output. The symbol after @ is different between Windows or Mac wechat and all other wechat
Code
async function onMessage (msg: Message) {
console.log(msg.toString())
console.log(JSON.stringify(msg))
if (msg.age() > 60) {
console.log('Message discarded because its TOO OLD(than 1 minute)')
return
}
const contactList = await msg.mention()
if(contactList){
console.log(contactList)
}
}