Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function message.to(): Contact|Room bug #88

Closed
lijiarui opened this issue Nov 12, 2016 · 2 comments
Closed

Function message.to(): Contact|Room bug #88

lijiarui opened this issue Nov 12, 2016 · 2 comments
Labels

Comments

@lijiarui
Copy link
Member

lijiarui commented Nov 12, 2016

Run npm run doctor or wechaty run doctor(for docker user), paste output here

wechaty@0.5.9 doctor /wechaty
ts-node bin/doctor

Wechaty Doctor

  1. Wechaty version: 0.5.9
  2. Linux x64 version 3.16.0-4-amd64 memory 283/1000 MB
  3. Docker: true
  4. Node version: v7.1.0

Code

I' trying use message.to() method, the full code as follows

import { Wechaty} from 'wechaty'

const bot = Wechaty.instance()
bot
.on('scan' ,(url,code)=>{console.log(url)})

.on('login',username=>{console.log(username.name())})

.on('message', m=> {
  const content = m.content()
  const to = m.to()
  const from = m.from()
  const room = m.room()
  if(room)
    console.log(`MessageReciver:${to}  content:${content} form:${from} in room: ${room}`) 
    else
    console.log(`MessageReciver:${to} ; content:${content};form:${from}`)
})
.init()

Expected behavior

When someone(not the bot itself) says "hello" in the room, m.to() should return room, but now, m.room() return contact

Steps to reproduce the behavior (and fixes, if any)

I login in with username '李佳芮' , then create a room called 'testmsg'.

When the bot itself speaking in the room 'testmsg', m.to() return the room 'testmsg' as expected.
Log as follows:(console.log(MessageReciver:${to} content:${content} form:${from} in room: ${room}) )

SILL Message constructor() SN:4
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Room ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Room ready()
MessageReciver:@@f02e19fceda71e02614ffe7820e6599d656cf4cb24695364a88d16d943666a1b content:test1 form:李佳芮 in room: @@f02e19fceda71e02614ffe7820e6599d656cf4cb24695364a88d16d943666a1b

When other people speaking in room 'testmsg' ,m.to() return to the contact which username is '李佳芮'.(I think it should return room)
Log as follows:(console.log(MessageReciver:${to} content:${content} form:${from} in room: ${room}) )

SILL Message constructor() SN:5
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Room ready()
SILL Message ready()
SILL Contact ready()
SILL Contact ready()
SILL Room ready()
MessageReciver:李佳芮 content:test2 form:邀群助手 in room: @@f02e19fceda71e02614ffe7820e6599d656cf4cb24695364a88d16d943666a1b

While, I think this message 's receiver is the room 'testmsg', so it should return room 'testmsg' , not the bot.

I wonder know is it a bug or you intented this return value? Thanks.

@huan
Copy link
Member

huan commented Nov 12, 2016

Thanks for the report. The behavior you reported is confirmed. And I agree that room() should has the same behavior in all conditions.

However, your issue lead me to re-think about the Wechaty Message design: is there any reason for to() to return a Room instance?

Currently to() will return Room is because of the Wechaty Message Object design of WebwxApp(wx.qq.com). It store room id in UserName, treat Contact & Room same. The only difference between Contact and Room is the id: room id starts with @@, no other difference else.

However, Wechaty treats Contact and Room as two totally different things. This design is because I believe it should: Contact is a person, Room is a group of persons.

At last, I believe that it is really confusing that Message.to() will return a Room, because we already have a Message.room() method to get the room. We should get rid of Message.to(): Room method, and it seems will be ok, not found any side effects(yet).

After that, the Message.to() will return null if a message is in a room, and no receiver is specified. Message.room() will return the room(if the message is in a room), or return null(if the message is between individuals).

Will commit the code later.

@huan huan added the bug label Nov 12, 2016
@huan huan changed the title Function message.to() return bug Function message.to(): Contact|Room bug Nov 12, 2016
@lijiarui
Copy link
Member Author

Thanks,

About your question, maybe there is no reason for to() to return a Room instance, if function message.room(room:Room) can set the destination for message. But it seems cannot work well as shown in #89

@huan huan closed this as completed Nov 12, 2016
huan added a commit that referenced this issue Nov 12, 2016
huan added a commit that referenced this issue Nov 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants