chatdb.js v2.4.2
ChatDB.js
A library that parses the chat.db file on Macs into a comprehensive data structure using ES6 promises.
Installation
$ npm install chatdb.js
Getting Started
// Import the package
const { Chat } = require('chatdb.js');
(async function () {
// Create new instance of Chat
// and initialize it asynchronously
const chat = await new Chat('/path/to/chat.db').init();
// ... Do the thing
}())
Examples
Simple Message Logger
const { Chat } = require('chatdb.js');
const fs = require('fs');
(async function() {
const chat = await new Chat().init(); // Initialize Client
const lastId = 0;
// Declare loop
async function loop() {
const msg = (await chat.getMessages(1, true))[0]; // Get the most recent message
if(msg.id != lastId) { // Check if the most recent message id changed
lastId = msg.id;
console.log(`${msg.isFromMe ? "Me" : msg.handle.name}: ${msg.text}`); // Format and log the message
}
}
setInterval(loop, 1000); // Start loop
}());
Common Problems
W.I.P.
Documentation
Constructors
Properties
Methods
- close
- dbDateToDate
- getConversationCount
- getConversations
- getHandleCount
- getHandles
- getMessageCount
- getMessages
- init
- parse
Constructors
constructor
+ new Chat(path?
: string): Chat
Defined in app.ts:12
Parameters:
Name | Type |
---|---|
path? | string |
Returns: Chat
Properties
db
• db: DatabaseSqlite‹Database, Statement›
Defined in app.ts:11
json
• json: Conversation[]
Defined in app.ts:12
path
• path: string
Defined in app.ts:10
Methods
close
▸ close(): Promise‹void›
Defined in app.ts:224
Returns: Promise‹void›
Private
dbDateToDate
▸ dbDateToDate(nano
: number): Date
Defined in app.ts:228
Parameters:
Name | Type |
---|---|
nano | number |
Returns: Date
getConversationCount
▸ getConversationCount(): Promise‹any›
Defined in app.ts:212
Returns: Promise‹any›
getConversations
▸ getConversations(max?
: number, reverse?
: boolean): Promise‹Conversation[]›
Defined in app.ts:130
Parameters:
Name | Type |
---|---|
max? | number |
reverse? | boolean |
Returns: Promise‹Conversation[]›
getHandleCount
▸ getHandleCount(): Promise‹any›
Defined in app.ts:216
Returns: Promise‹any›
getHandles
▸ getHandles(max?
: number, reverse?
: boolean): Promise‹Handle[]›
Defined in app.ts:109
Parameters:
Name | Type |
---|---|
max? | number |
reverse? | boolean |
Returns: Promise‹Handle[]›
getMessageCount
▸ getMessageCount(): Promise‹any›
Defined in app.ts:220
Returns: Promise‹any›
getMessages
▸ getMessages(max?
: number, reverse?
: boolean): Promise‹Message[]›
Defined in app.ts:151
Parameters:
Name | Type |
---|---|
max? | number |
reverse? | boolean |
Returns: Promise‹Message[]›
init
▸ init(): Promise‹Chat›
Defined in app.ts:19
Returns: Promise‹Chat›
parse
▸ parse(): Promise‹Conversation[]›
Defined in app.ts:28
Returns: Promise‹Conversation[]›
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago