osl-kustomer-archiver
v1.1.0
Published
Remove old conversations from Kustomer. Preserve stats to Google Sheets. Records an event log
Downloads
6
Readme
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:
https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication?id=service-account
Google Sheets
- Create a new Google Sheet
- Name one of the sheet tabs to "import", and another to "event_log":
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:
- google-spreadsheet
- js-console-log-colors
- node-fetch@2 (CommonJS version)
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