juzibot / wechaty-puppet-macpro

One puppet based on Mac WeChat for Wechaty.
Apache License 2.0
38 stars 10 forks source link

inconsistant wechat ID obtained from Contact object and message event #15

Closed iyjian closed 5 years ago

iyjian commented 5 years ago

puppet version:

"wechaty": "^0.27.60", "wechaty-puppet-macpro": "^0.1.16",

test script

const { Wechaty, Contact } = require('wechaty')
const { PuppetMacpro } = require('wechaty-puppet-macpro')
const conf = require('./../config/default')

const puppet = new PuppetMacpro({
  token: conf.vendor.padproToken // <-- place your token
})

bot = new Wechaty({
  puppet,
})

bot.on('scan', (qrcode, status) => {
  console.log(`https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qrcode)}`)
}).on('message', message => {
  const aFriend = '人在江湖漂'
  if (message.from().name() === aFriend && !message.room()) {
    const wechatId = message.from().id
    console.log(`${aFriend} is sending me a message, his wechat id is: **${wechatId}**,trying to search him in my contact list`)
    bot.Contact.findAll({name: aFriend}).then(friend => {
      if (friend.length > 0) {
        console.log(`his wechat id in my contact list is: **${friend[0]['id']}**`)
      } else {
        console.log(`something goes wrong.....`)
      }
    })
  }
})
.start()

console output

$ node tests/testGetContacts.js
11:10:28 INFO Wechaty <Puppet#0<PuppetMacpro>()>() start() v0.27.60 is starting...
人在江湖漂 is sending me a message, his wechat id is: **iyjian9934**,trying to search him in my contact list

his wechat id in my contact list is: **wxid_ffk05mmvo73s22**
iyjian commented 5 years ago

seems it related to this one #2

su-chang commented 5 years ago

Thx for issue. wxid is the unique ID in Wechaty for one contact, and it always as a key for something, for example: RoomMemberPayload, ContactPayload

iyjian commented 5 years ago

Thx for issue. wxid is the unique ID in Wechaty for one contact, and it always as a key for something, for example: RoomMemberPayload, ContactPayload

yes, but I think the ID got from contact and contact in message should be same one.

iyjian commented 5 years ago

fixed