easaiIT / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
0 stars 0 forks source link

Sweep: Export chat history #1

Open easaiIT opened 11 months ago

easaiIT commented 11 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

No response

Describe the solution you'd like.

First I would like to thank you for this amazing project.

I searched briefly and didn't find anything related to the functionality of exporting conversations to a file. I looked through whatsapp web and did not find the option and I believe this is a problem.

The functionality would allow you to download the history of the selected conversation.

Describe an alternate solution.

No response

Additional context

Sometimes we need to look at a user's conversation history to get some context on the current conversation.

I don't know if the archive would be ideal, but anything that brings back old conversations would be really helpful.

sweep-ai[bot] commented 11 months ago

Here's the PR! https://github.com/easaiIT/whatsapp-web.js/pull/3.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 5 GPT-4 tickets left. For more GPT-4 tickets, visit our payment portal.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/easaiIT/whatsapp-web.js/blob/8fc6e6098c88e7280074e4a9bdaabedc0646589e/index.d.ts#L771-L969 https://github.com/easaiIT/whatsapp-web.js/blob/8fc6e6098c88e7280074e4a9bdaabedc0646589e/src/Client.js#L673-L814 https://github.com/easaiIT/whatsapp-web.js/blob/8fc6e6098c88e7280074e4a9bdaabedc0646589e/index.d.ts#L1376-L1494 https://github.com/easaiIT/whatsapp-web.js/blob/8fc6e6098c88e7280074e4a9bdaabedc0646589e/index.d.ts#L1038-L1363 https://github.com/easaiIT/whatsapp-web.js/blob/8fc6e6098c88e7280074e4a9bdaabedc0646589e/src/structures/Message.js#L225-L351

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
src/structures/Chat.js Add a new method exportChatHistory that retrieves all messages from the chat history using the fetchMessages method. The method should call a new helper function formatChatHistory from Util.js to format the messages into a user-friendly format. Then, it should use the fs module to create a file with the formatted chat history and return this file.
src/util/Util.js Add a new helper function formatChatHistory that takes an array of messages as input and returns a string with the formatted chat history. The function should iterate over the array of messages and format each message into a user-friendly format such as JSON or CSV.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add exportChatHistory method to Chat class sweep/feature/export-chat-history

Description

This PR adds a new method exportChatHistory to the Chat class in order to allow users to export the history of a selected conversation. The method retrieves all messages from the chat history using the existing fetchMessages method and formats them into a user-friendly format such as JSON or CSV. It also creates a downloadable file with the formatted chat history.

Summary of Changes

  • Added a new method exportChatHistory to the Chat class in src/structures/Chat.js
  • Created a new helper function formatChatHistory in src/util/Util.js to format the chat messages into a user-friendly format
  • Used the fs module to create a file with the formatted chat history
  • Updated the README.md file to include documentation for the new exportChatHistory method

Step 4: ⌨️ Coding

I have finished coding the issue. I am now reviewing it for completeness.


Step 5: 🔁 Code Review

Success! 🚀


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind! Join Our Discord