osl-kustomer-archiver

1.1.0 • Public • Published

osl-kustomer-archiver

Remove old conversations from Kustomer. Preserves stats to Google Sheets. Keeps an event log of what was done.

Prerequisites

  • Node.js v16.15.0 or later
  • npm v8.5.5 or later (included with Node.js)

Setup

Kustomer API:

  • API Key with the following 4 roles:
    • org.permission.conversation.delete
    • org.permission.conversation.read
    • org.permission.search_execution.create
    • org.permission.tag.read

Kustomer Saved Search:

  • Make a Saved Search, and remember to make it publicly viewable in it's settings. Note it's ID (taken from the URL when you edit it) which is used in the config.json

Google API:

  • Setup a new Google Project and create a "Service account", with this guide:

Google Developers Console

image

https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication?id=service-account

image

Google Sheets

  • Create a new Google Sheet
  • Name one of the sheet tabs to "import", and another to "event_log":

image

If you protect the sheets, make sure to give the Google Service Account permission to edit!

  • On the "import" sheet tab, set columns B, E & F to be a datetime format of your choice
  • On the "event_log" sheet tab, set column B to be a datetime format of your choice
  • Share the google sheet with the Service Account email address as per the Google API Guide

Node.js

In your Node.js working directory install the package:

npm -i osl-kustomer-archiver

Copy ./config/config.template.json file to ./config/config.json and edit the values.

Most are self-explanatory.

Firstly, set ENVIRONMENT.NAME accordingly.

If there is an unexpected error, setting DEBUG_MODE to true will show some verbose variable information in the terminal output.

To execute a saved-search in Kustomer, you need to aquire a CSRF token from the frontend request when testing the saved search, since they are not accisible directly through the API. This can easily be aquired using devtools, and looking for the "/execute" request

The SHEET_ID is simply the id in the URL when you open the google sheet: https://docs.google.com/spreadsheets/d/ THIS_PART_HERE /edit

{
  "ENVIRONMENT": {
    "NAME": "My Environment",
    "DEBUG_MODE": false
  },
  "KUSTOMER": {
    "API_KEY": "Get from Kustomer settings",
    "HEADER_CSRF_TOKEN": "Copy from frontend request",
    "COOKIE_CSRF_TOKEN": "Copy from frontend request",
    "SAVED_SEARCH_ID": "Get from the URL when editing a Saved Search"
  },
  "GOOGLE": {
    "SERVICE_ACCOUNT_EMAIL": "copied from service account credentials generated by google",
    "PRIVATE_KEY": "copied from service account credentials generated by google",
    "SHEET_ID": "the long ID in the sheets URL"
  }
}

Included Dependancies:

Usage

Run manually:

node index.js

OR

npm start

Run periodically:

  • Open crontab
$ crontab -e

Every Hour

0 * * * * node /path/to/this/repo/index.js >/dev/null 2>&1

2pm Every Day

0 14 * * * node /path/to/this/repo/index.js >/dev/null 2>&1

Readme

Keywords

Package Sidebar

Install

npm i osl-kustomer-archiver

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

26.4 kB

Total Files

5

Last publish

Collaborators

  • hannibal_hacktor