1
votes

I want to write a back up script to transfer my chat history to a Google spreadsheet.

1

1 Answers

0
votes

This may have been the route you tried previously, although you haven't provided a great deal of information so it's hard to tell.

In the GmailApp class there is a method for returning chat threads (https://developers.google.com/apps-script/reference/gmail/gmail-app#getChatThreads()), you can specify the max amount of threads returned and the starting index position.

function chatThreadsExample() {

  // get first 10 chat threads
  var threads = GmailApp.getChatThreads(0,10);

  //get first thread messages
  var messages = threads[0].getMessages();

  //get first thread first message contents
  Logger.log(messages[0].getBody());

}

As you can see archiving each chat thread and its contents to a spreadsheet is definitely possible, but pretty intensive (depending on how many chats there are and how long each chat is).