Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
whatsapp-chat-parser
Advanced tools
A package to parse WhatsApp chats with Node.js or in the browser 💬
A package to parse WhatsApp chats with Node.js or in the browser 💬
🚨 v4.0.0
brings some BREAKING CHANGES, check out the release page for more info.
This library allows you to parse WhatsApp chat logs from text format into javascript objects, enabling you to more easily manipulate the data, create statistics, export it in different formats, etc.
You can test the package online with this example website:
whatsapp-chat-parser.netlify.app (Source code)
$ npm install whatsapp-chat-parser
import fs from 'node:fs';
import * as whatsapp from 'whatsapp-chat-parser';
const text = fs.readFileSync('path/to/_chat.txt', 'utf8');
const messages = whatsapp.parseString(text);
console.log(messages);
Add the script to your HTML file (usually just before the closing </body>
tag).
Then use it in your JavaScript code, the whatsappChatParser
variable will be globally available.
<script src="path/to/index.global.js"></script>
<script>
const messages = whatsappChatParser.parseString(
'06/03/2017, 00:45 - Sample User: This is a test message',
);
console.log(messages);
</script>
Or with type="module"
loading the ESM version:
<script type="module">
import * as whatsapp from 'path/to/index.js';
const messages = whatsapp.parseString(
'06/03/2017, 00:45 - Sample User: This is a test message',
);
console.log(messages);
</script>
You can also use the jsDelivr CDN.
<script src="https://cdn.jsdelivr.net/npm/whatsapp-chat-parser/dist/index.global.js"></script>
<!-- Or use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/whatsapp-chat-parser@4.0.2/dist/index.global.js"></script>
The messages
variable is an array of objects like this:
[
{
date: '2018-06-02T22:45:00.000Z', // Date object
author: 'Luke',
message: 'Hey how are you?',
},
{
date: '2018-06-02T23:48:00.000Z', // Date object
author: 'Joe',
message: 'All good, thanks',
},
];
When using the option parseAttachments
, the message may contain an additional property attachment
:
[
{
date: '2018-06-02T23:50:00.000Z', // Date object
author: 'Joe',
message: '<attached: 00000042-PHOTO-2020-06-07-15-13-20.jpg>',
attachment: {
fileName: '00000042-PHOTO-2020-06-07-15-13-20.jpg',
},
},
];
In the case of a system message, the author will be null
[
{
date: '2018-06-02T22:45:00.000Z', // Date object
author: null,
message: 'You created group "Party 🎉"',
},
];
string
Type: string
Raw string of the WhatsApp conversation
options
Type: object
A configuration object, more details below
Name | Type | Default | Description |
---|---|---|---|
daysFirst | Boolean | undefined | Specify if the dates in your log file start with a day (true ) or a month (false ). Manually specifying this may improve performance. By default the program will try to infer this information using 3 different methods (look at date.ts for the implementation), if all fails it defaults to days first. |
parseAttachments | Boolean | false | Specify if attachments should be parsed. If set to true , messages with attachments will include an attachment property with information about the attachment. |
Sometimes, likely due to connection issues, WhatsApp exports contain messages that are not chronologically ordered.
This library won't change the order of the messages, but if your application expects a certain order make sure to sort the array of messages accordingly before use.
See #247 for more info.
Node.js >= 8.0.0
This package is written in TypeScript with target compilation to ES6.
It should work in all relevant browsers from ~2017 onwards.
FAQs
A package to parse WhatsApp chats with Node.js or in the browser 💬
The npm package whatsapp-chat-parser receives a total of 136 weekly downloads. As such, whatsapp-chat-parser popularity was classified as not popular.
We found that whatsapp-chat-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.