Last active
October 15, 2019 17:09
-
-
Save spasiu/73f74c2a9b180cd3f1c4dd7bbf7e0325 to your computer and use it in GitHub Desktop.
script for collating all Smooch logs from the dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Run this script by logging into your Smooch dashboard, | |
| navigating to the app for which you want to collect logs, | |
| and pasting the script into the JavaScript console. | |
| The output is a global variable called `results`. | |
| */ | |
| async function getLogs(ts=undefined, hasMore=true, events=[]) { | |
| const appId = location.pathname.split('/')[2]; | |
| ts = ts || Date.now() / 1000; | |
| if (!hasMore) return events; | |
| const response = await fetch(`https://app.smooch.io/webapi/apps/${appId}/logs?before=${ts}`, { | |
| 'credentials':`include`, | |
| 'headers':{ | |
| 'accept':`application/json`, | |
| 'accept-language':`en-US,en;q=0.9`, | |
| 'content-type':`application/json`, | |
| 'sec-fetch-mode':`cors`, | |
| 'sec-fetch-site':`same-origin`, | |
| 'x-requested-with':`XMLHttpRequest` | |
| } | |
| }); | |
| const data = await response.json(); | |
| const eventBatch = data.events || []; | |
| const lastEvent = eventBatch.slice(-1).pop() || {}; | |
| return getLogs(lastEvent.timestamp, data.hasMore, events.concat(eventBatch)) | |
| } | |
| getLogs() | |
| .then(events => results = events) | |
| .then(() => console.log(results)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment