Remove old conversations from Kustomer. Preserves stats to Google Sheets. Keeps an event log of what was done.
- Node.js v16.15.0 or later
- npm v8.5.5 or later (included with Node.js)
- API Key with the following 4 roles:
- org.permission.conversation.delete
- org.permission.conversation.read
- org.permission.search_execution.create
- org.permission.tag.read
- 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
- Setup a new Google Project and create a "Service account", with this guide:
- 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
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"
}
}
- google-spreadsheet
- js-console-log-colors
- node-fetch@2 (CommonJS version)
node index.js
OR
npm start
- Open crontab
$ crontab -e
0 * * * * node /path/to/this/repo/index.js >/dev/null 2>&1
0 14 * * * node /path/to/this/repo/index.js >/dev/null 2>&1