awaitlink / vk-chat-bot

:package: node package for building chat bots for VK communities (uses Callback API)
https://u32i64.github.io/vk-chat-bot/
MIT License
22 stars 4 forks source link

Can't reply to 'message_typing_state' event #3

Closed Trother555 closed 6 years ago

Trother555 commented 6 years ago

I don't know if it is a bug or it's just not meant to be used that way.

Anyway, this:

bot.on('message_typing_state', $ => {
  $.text('What are you typing there?')
})

is not working like I'm expecting. It says that peer id is undefined. A possible workaround:

bot.on('message_typing_state', $ => {
  $.setPid($.obj.from_id)
  $.text('What are you typing there?')
})

By the way, I can't understand why other handlers work: just can't find where pid is set for them.

Trother555 commented 6 years ago

Now I got it. It happens in APIBuffer's constructor when calling clear(). this.pid = this.obj.peer_id But when typing event object looks like: {"state":"typing","from_id":162112527,"to_id":-162112527} So may be you can add an additional if to check for it

clear () {
    this.replyText = ''
    this.attachment = []
    if (this.eventType === 'message_allow') {
      this.pid = this.obj.user_id
    } else if (this.eventType === 'message_typing_state'){
      this.pid = this.obj.from_id
    } else {
      this.pid = this.obj.peer_id
    }
  }
awaitlink commented 6 years ago

Thanks for reporting this! This is a bug indeed, the problem is that API docs don't explain anything about this event at this moment. I published v6.0.5 with the fix you suggested.

Just run:

npm up vk-chat-bot

And you should be on the latest version ;)