Skip to content
A package to parse WhatsApp chats with Node.js or in the browser πŸ’¬
JavaScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
src πŸ› Fix multiline messages that contain a datetime Aug 22, 2019
tests πŸ› Fix multiline messages that contain a datetime Aug 22, 2019
types πŸ’‘ Add Typescript typings Aug 18, 2019
.babelrc πŸ”§ Added babel config, changed rollup config to generate the unminifie… May 28, 2019
.eslintrc ✨ New functions to help with date and time format Aug 8, 2018
.gitignore πŸ› Fix coverage report Jun 13, 2019
.prettierignore
.prettierrc βž• Added prettier and pretty-quick Aug 2, 2018
.renovaterc πŸ”§ Configure renovate Jun 13, 2019
CHANGELOG.md πŸ“ Update changelog Aug 22, 2019
LICENSE πŸ“„ Added MIT license Aug 9, 2018
README.md πŸ”– Bump version to 2.0.6 Aug 22, 2019
global-setup.js πŸ› Platform agnostic timezone setup Jun 14, 2019
jest.config.js πŸ› Fix TZ=UTC not available on windows Jun 13, 2019
package-lock.json πŸ”– Bump version to 2.0.6 Aug 22, 2019
package.json πŸ”– Bump version to 2.0.6 Aug 22, 2019
rollup.config.js πŸ”§ Add sourcemap to minified version May 29, 2019

README.md

WhatsApp Chat Parser

CircleCI npm version minified size

A package to parse WhatsApp chat logs πŸ’¬

You can test the package online with this example website:
whatsapp-chat-parser.netlify.com (Source code)

Install

$ npm install whatsapp-chat-parser

Usage

Node

const fs = require('fs');
const whatsapp = require('whatsapp-chat-parser');

const fileContents = fs.readFileSync('path/to/file.txt', 'utf8');

whatsapp
  .parseString(fileContents)
  .then(messages => {
    // Do whatever you want with messages
  })
  .catch(err => {
    // Something went wrong
  });

Browser

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/whatsapp-chat-parser.min.js"></script>
<script>
  whatsappChatParser
    .parseString('06/03/2017, 00:45 - Sample User: This is a test message')
    .then(messages => {
      // Do whatever you want with messages
    })
    .catch(err => {
      // Something went wrong
    });
</script>

You can also use the jsDelivr CDN.

<script src="https://cdn.jsdelivr.net/npm/whatsapp-chat-parser/dist/whatsapp-chat-parser.min.js"></script>
<!-- Or use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/whatsapp-chat-parser@2.0.6/dist/whatsapp-chat-parser.min.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',
  },
];

In the case of a system message, the author will be System

[
  {
    date: '2018-06-02T22:45:00.000Z', // Date object
    author: 'System',
    message: 'You created group "Party πŸŽ‰"',
  },
];

API

parseString(string, [options]) β†’ Promise

string

Type: string

Raw string of the WhatsApp conversation

options

Type: object

A configuration object, more details below

Options

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.js for the implementation), if all fails it defaults to interpret the first digit as the day.

How to export WhatsApp chats

Technologies used

Requirements

Node

Node.js >= 8.0.0

Browser

This package is written in ES6 and transpiled to ES5.
It should work in all relevant browsers.
If the browsers you're targeting support Promises / Set / String.prototype.padStart you're probably good to go.

Changelog

CHANGELOG

License

MIT

You can’t perform that action at this time.