Merge pull request #4 from SConaway/fetchOldest-fetchNewest-grab-valid

Make fetchOldest and fetchLatest search for a valid number
This commit is contained in:
Avi 2021-01-08 12:41:15 -08:00 committed by GitHub
commit 2f142d1981
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 136 additions and 8 deletions

115
.gitignore vendored Normal file
View file

@ -0,0 +1,115 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env*.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# End of https://www.toptal.com/developers/gitignore/api/node

View file

@ -38,9 +38,16 @@ async function fetchLatest(id) {
const result = await app.client.conversations.history({
token: token,
channel: id,
limit: 1,
limit: 100,
});
const number = extractNumber(result.messages[0].text)
let number;
for (let x = 0; x < result.messages.length; x++) {
number = extractNumber(
result.messages[x].text,
);
if (!isNaN(number)) break;
}
return number;
} catch (error) {
console.error(error);
@ -49,14 +56,20 @@ async function fetchLatest(id) {
async function fetchOldest(id) {
try {
let last24Hrs;
const result = await app.client.conversations.history({
token: token,
channel: id,
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1596326400, actual: Math.floor(Date.now() / 1000) - 86400
inclusive: false
oldest: Math.floor(Date.now() / 1000) - 86400, //debug: 1609295166, actual: Math.floor(Date.now() / 1000) - 86400
inclusive: false,
});
const number = extractNumber(result.messages[result.messages.length - 2].text);
let number;
for (let x = result.messages.length - 2; x >= 0 ; x--) {
number = extractNumber(
result.messages[x].text,
);
if (!isNaN(number)) break;
}
return number - 1;
} catch (error) {
console.error(error);

View file

@ -2,9 +2,9 @@
"name": "bolt-app-template",
"version": "0.0.1",
"description": "A basic template to spin up a Bolt app for Slack",
"main": "app.js",
"main": "api/app.js",
"scripts": {
"start": "node app.js"
"start": "node api/app.js"
},
"dependencies": {
"@slack/bolt": "^2.2.3",