Skip to content

Latest commit

 

History

History
137 lines (99 loc) · 2.77 KB

README.md

File metadata and controls

137 lines (99 loc) · 2.77 KB

💬 Whatsapp chat parser 📋

Last modified: 31/03/2022

Introduction

This package allow to convert your exported whatsapp chats to JSON format.

Next Features

  • SUPPORT FOR CHAT GROUP

Avaliable Features

  • QR image that contain the link to audio and video files

Installation 💻

$ go get github.com/yellyoshua/whatsapp-chat-parser

Example 📜

package main

import (
	"io/ioutil"
	"log"
	"path"

	"github.com/yellyoshua/whatsapp-chat-parser/chat"
	"github.com/yellyoshua/whatsapp-chat-parser/constants"
)

func readFile(filename string) []byte {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Fatal(err)
	}
	return data
}

func main() {
	var whatsappChat = readFile("chat.txt")
	parser := chat.Create(whatsappChat, chat.Configuration{
		UrlForQrFiles: "https://my-bucket.assets/file/",
	})

	chatInstance, rawMessages := parser.ParseMessages(
		"en"
	)
	log.Printf("%v - %s - %s",
		rawMessages[0].Date,
		rawMessages[0].Author,
		rawMessages[0].Message,
	)

	messages, err := chatInstance.NewPaperBook().ExportJSON()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Were processed %d messages", messages.Count)
	log.Print(string(messages.Value))
	// {author: "", message: "", date: "", attachment: {}...}
}

API

💬 Struct of whatsapp.Message

github.com/yellyoshua/whatsapp-chat-parser/whatsapp

type DateFormat struct {
	Hours  string `json:"hours"`
	Mins   string `json:"mins"`
	Format string `json:"format"`
	Day    int    `json:"day"`
	Month  int    `json:"month"`
	Year   int    `json:"year"`
	UTC    string `json:"utc"`
}

type Attachment struct {
	Exist     bool   `json:"exist"`
	FileName  string `json:"fileName,omitempty"`
	Extension string `json:"extension,omitempty"`
}

// Message _
type Message struct {
	Date       DateFormat `json:"date"`
	Author     string     `json:"author"`
	IsSender   bool       `json:"isSender"`
	IsInfo     bool       `json:"isInfo"`
	IsReceiver bool       `json:"isReceiver"`
	Message    string     `json:"message"`
	Attachment Attachment `json:"attachment"`
}

📚 Interface of paper.Book

github.com/yellyoshua/whatsapp-chat-parser/paper

// Book __
type Book interface {
	Export() []whatsapp.Message
	ExportJSON() (MessagesJSON, error)
}

📋 Exports from chat package

github.com/yellyoshua/whatsapp-chat-parser/whatsapp

func Create(chatContent string, config Configuration) Parser

Technologies used for this project

Powered by yellyoshua

Buy Me A Coffee