Skip to content

Instantly share code, notes, and snippets.

@titounnes
Forked from gesteves/gist:1051628
Created January 15, 2020 02:46
Show Gist options
  • Save titounnes/1b0330c2076f86d73112bce56d18d3fa to your computer and use it in GitHub Desktop.
Save titounnes/1b0330c2076f86d73112bce56d18d3fa to your computer and use it in GitHub Desktop.
Google Apps script to export Google Talk chat logs to a Google Docs spreadsheet
/*
Quick instructions:
1. Go to Google Docs and open a new spreadsheet.
2. Go to Tools > Script editor...
3. Delete everything, paste this code in the script editor, and save it.
4. Go back to the spreadsheet, Tools > Script manager...
5. Select getChats, and press the "run" button.
6. It'll ask for a bunch of authorizations. Grant them.
7. When it says "now you can run the script", repeat step 5.
8. Your chats should being filling the spreadsheet. It'll probably take a while.
When it's done, you can save it, and export it as CSV, Excel or whatever.
*/
function getChats() {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1).setValue("Date");
sheet.getRange(1, 2).setValue("Subject");
sheet.getRange(1, 3).setValue("Body");
var row = 2;
var chats = GmailApp.getChatThreads();
var chat_count = chats.length;
for (var i = 0; i < chat_count; i++) {
var count = chats[i].getMessageCount();
var messages = chats[i].getMessages();
for (var j = 0; j < count; j++) {
var chat_date = messages[j].getDate();
var subject = messages[j].getSubject();
var body = messages[j].getBody();
sheet.getRange(row, 1).setValue(chat_date);
sheet.getRange(row, 2).setValue(subject);
sheet.getRange(row, 3).setValue(body);
row++;
}
}
Browser.msgBox("All done!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment