Go-whatsapp: Easy way to get chat history as TextMessage/ImageMessage/…

Created on 22 Sep 2018  Â·  9Comments  Â·  Source: Rhymen/go-whatsapp

I want to create a tool to export a chat. Getting the chat history with LoadMessages works fine. The problem is, that it returns *proto.WebMessageInfo (in Node.Content) that has to be parsed with parseProtoMessage which isn’t exported. It is possible to parse it manually, but it is too complex considering that such a function already exists.

Am I missing an easy way to get TextMessages, ImageMessages, etc… via LoadMessages?

Do you think exporting parseProtoMessage is an option? I implemented this as a workaround and it seems to work well.

enhancement

Most helpful comment

I needed it also and did exactly the same thing as you did. Basically I see no problem to export the function. We are thinking about to redesign the handler system. If we dispatch *proto.WebMessageInfo messages and export the parseProtoMessage function, then we could drastically simplify the whole system.

All 9 comments

I needed it also and did exactly the same thing as you did. Basically I see no problem to export the function. We are thinking about to redesign the handler system. If we dispatch *proto.WebMessageInfo messages and export the parseProtoMessage function, then we could drastically simplify the whole system.

You don't need to export parseProtoMessage, imo. Just pass a message handler(s) to ChatHistory func and let dispatcher handle raw messages for you, e.g. my attempt at it

@kaxap I like your approach. It also gives the opportunity to implement different handlers for old Messages. I already considered to dispatch the messages the normal way, but I didn´t like that. This is a nice alternative, because it uses the default handlers only if you haven´t passed any spefic ones.

@SchulteMK Would you like me to create a pull request based on this attempt?

@kaxap That would be nice :) I think it could be very helpful for many people.

@kaxap I looked at your implementation, what could be the best way to find all the jids ? Can you supply an example that could help in understanding how load chat history function works?

@adarshsrivastava11 do you need all user jids who posted a message in a given group?

@kaxap No not in a group but in my inbox. jids of all the people who's text in there in my inbox. Is it possible?

The only "trick" I was able to think of is to collect all the jids in a raw message handler, e.g.

HandleRawMessage(message *proto.WebMessageInfo) {
    jid := *message.Key.RemoteJid
       ....
}

The idea is to store all jids from incoming raw messages to a Set, since Whatsapp would (re)send last messages from chats/groups when a new connection is established.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Valdenirmezadri picture Valdenirmezadri  Â·  7Comments

xnodcorp picture xnodcorp  Â·  3Comments

it-sumanp picture it-sumanp  Â·  8Comments

highness28 picture highness28  Â·  5Comments

elpulga picture elpulga  Â·  4Comments