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

[Feature request] @mention support? #153

Closed
dcsan opened this Issue Dec 21, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@dcsan

dcsan commented Dec 21, 2016

In a group it is so convenient to message the bot using @botName

I was looking at the message API and trying to see how @mentions work

but looking at output from console.log(inspect(m)) . I don't see any special data that refers to the mentioned users.
Their names are included in the text of the message. If you change your name, then the mention will use the updated name (not the wechat ID)

So I guess the only way is to use message and match against the Room.memberList()
It just seems surprising this is left encoded in the message text and not as a userId in the data somewhere...

I guess that the memberList requires room.ready() and maybe not available all the time?
So we could provide this as an async API helper on the message object?

@zixia zixia added the enhancement label Dec 22, 2016

@zixia

This comment has been minimized.

Show comment
Hide comment
@zixia

zixia Dec 22, 2016

Member

Thanks for the great feature suggestion!

I agree that if we have a room-mention / mention event for the room when we got mentioned will be very convenience.

How about let's design it like this:

// Global Event
Wechaty.instance()
.on('room-mention', (room, message) => {
  // here we got message mentioned us
})

// or a specific Room Event

Room.find({ name: 'test' })
.then(room => {
  room.on('mention', message => {
    // here we got message mentioned us
  })
})

Before we implement that, I suggest you can have a try with Room.member(name) to get the Contact by name in a Room. And I think you should not worry about room.ready() because the room will always be called ready() by Wechaty Framework before you received the event. (If it's not updated with the latest data, call room.refresh() instead)

Member

zixia commented Dec 22, 2016

Thanks for the great feature suggestion!

I agree that if we have a room-mention / mention event for the room when we got mentioned will be very convenience.

How about let's design it like this:

// Global Event
Wechaty.instance()
.on('room-mention', (room, message) => {
  // here we got message mentioned us
})

// or a specific Room Event

Room.find({ name: 'test' })
.then(room => {
  room.on('mention', message => {
    // here we got message mentioned us
  })
})

Before we implement that, I suggest you can have a try with Room.member(name) to get the Contact by name in a Room. And I think you should not worry about room.ready() because the room will always be called ready() by Wechaty Framework before you received the event. (If it's not updated with the latest data, call room.refresh() instead)

@lijiarui

This comment has been minimized.

Show comment
Hide comment
@lijiarui

lijiarui May 2, 2017

Member

It may fix as it can on #362

Member

lijiarui commented May 2, 2017

It may fix as it can on #362

@zixia

This comment has been minimized.

Show comment
Hide comment
@zixia

zixia May 3, 2017

Member

I'll close this issue because we have message.mentioned() now.

Member

zixia commented May 3, 2017

I'll close this issue because we have message.mentioned() now.

@zixia zixia closed this May 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment