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

Feat: add Message.find to search in cache. #1534

Closed
huan opened this issue Aug 8, 2018 · 13 comments
Closed

Feat: add Message.find to search in cache. #1534

huan opened this issue Aug 8, 2018 · 13 comments

Comments

@huan
Copy link
Member

huan commented Aug 8, 2018

For some scenarios like find the recent messages by text.

This might be a workaround for #1531

huan added a commit to wechaty/puppet that referenced this issue Aug 11, 2018
huan added a commit that referenced this issue Aug 11, 2018
huan added a commit that referenced this issue Aug 11, 2018
@huan
Copy link
Member Author

huan commented Aug 11, 2018

@kis87988 Would you like to try this new method to see if it could help you to find someone who had said something in a room before?

It had been published on Wechaty v0.19.145 or later versions.

@huan huan closed this as completed Aug 11, 2018
@kis87988
Copy link
Contributor

Sure, I will try and test it out.

@kis87988
Copy link
Contributor

kis87988 commented Aug 11, 2018

@zixia
Did I use it right?

        const room = bot.Room.load("chatroom@123456")
        room.say("match[2]")
        await delay(10000) //delay 10s
        const match=["這是一個測試的文字1","這是一個測試的文字2","這是一個測試的文字3"]
        const find_content = match[2]
        console.log("find_content:", find_content)
        const found_msg = await bot.Message.find({text:new RegExp(find_content,"igm"),
                                                  roomId:room.id, 
                                                  type: Message.Type.Text})
        if(found_msg)
        {
          console.log(found_msg)
          console.log(found_msg.text())
          console.log(found_msg.from())
        }
        else
        {
          console.log(`not found message${find_content}`)
        }
find_content: 這是一個測試的文字3
16:49:23 VERB Message findAll([object Object])
16:49:23 SILL Accessory #1333<Message> constructor()
16:49:23 VERB Message constructor([object Object]) for class Message
16:49:23 SILL Accessory #1334<Message> constructor()
16:49:23 VERB Message constructor([object Object]) for class Message
Message {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: { MsgId: 'id1' },
  [Symbol(name)]: 'Message',
  [Symbol(counter)]: 1333 }
16:49:23 ERR Config ###########################
16:49:23 ERR Config unhandledRejection: Error: no payload [object Promise]
16:49:23 ERR Config ###########################
16:49:23 ERR Config process.on(unhandledRejection) promise.catch(no payload)
Config Error: no payload
    at AnotherOriginalClass.text (/bot/node_modules/wechaty/src/user/message.ts:321:13)
    at Object.<anonymous> (/bot/WilliamDABot.ts:324:33)
    at Generator.next (<anonymous>)
    at fulfilled (/bot/WilliamDABot.ts:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:25) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 3)
16:49:43 SILL PadchatRpc initHeartbeat() debounceQueue.subscribe(ws.on(message))

@huan huan reopened this Aug 12, 2018
@huan
Copy link
Member Author

huan commented Aug 12, 2018

Why there's a data like id: { MsgId: 'id1' }?

I do not think the id1 is the real id from padchat, can you explain it?

@kis87988
Copy link
Contributor

um..
Does that mean the message not found?
or my code is wrong:(

@huan
Copy link
Member Author

huan commented Aug 12, 2018

I have no idea about this problem, I will do a test by myself later.

@huan
Copy link
Member Author

huan commented Aug 13, 2018

I had just tested with the following code, it works without any problem with Wechaty v0.19.149

  if (msg.text() === 'find') {
    console.log('find start')
    const messageList = await this.Message.findAll({ text: /test/i })
    console.log('length:', messageList.length)
    for (const m of messageList) {
      console.log(m.from() + '')
      console.log(m.to() + '')
      console.log(m.room() + '')
      console.log(m.text() + '')
    }
    console.log('find done')
  }

@kis87988
Copy link
Contributor

Yes, it is working now. thanks!

@huan
Copy link
Member Author

huan commented Aug 15, 2018

Did you found the reason of why it didn't work before?

And please close this issue if you have no more questions. Thanks

@kis87988
Copy link
Contributor

@zixia
No, I put exactly same code. I guess it may be some version, connection, or cache issue.
And I can not close this one because ...I am not the issuer 😄

@huan
Copy link
Member Author

huan commented Aug 15, 2018

Ok, let me do this. :P

@huan huan closed this as completed Aug 15, 2018
@xmsz
Copy link

xmsz commented Nov 24, 2018

您好,在onMessage中如何筛选聊天记录
使用Message.find({ text: "2" });会出现

WARN Message findAll() rejected: filterValue not found for filterKey: fromId
Error: filterValue not found for filterKey: fromId

@huan
Copy link
Member Author

huan commented Nov 24, 2018

@xmsz Please file a new issue and follow the template.

This issue had already been closed.

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

No branches or pull requests

3 participants