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.
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.
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.WebMessageInfomessages and export theparseProtoMessagefunction, then we could drastically simplify the whole system.