Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# lit-pics
🐱 Simple app to make sure me and my girlfriend are cleaning the damn litter box.

### Initial Setup
Initial Firebase setup (1 time only):
1. Navigate to 'rules' tab on database (https://console.firebase.google.com/u/0/project/:id/database/:id/rules)
2. Set:
```
{
"rules": {
".read": true,
".write": true
}
}
```

### Setup
1. Create a `config.json` file in app's root directory based off of `config.template.json`
2. Replace the info in the participants array matching this format:
Expand Down
12 changes: 10 additions & 2 deletions config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
"alertTime": "0 19 * * *",
"timezone": "America/Chicago"
},
"firebase": {
"apiKey": "",
"authDomain": "",
"databaseURL": "",
"projectId": "",
"storageBucket": "",
"messagingSenderId": ""
},
"twilio": {
"number": "+17777777777",
"accountSid": "xyz",
"authToken": "xyz"
"accountSid": "",
"authToken": ""
}
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const CronJob = require('cron').CronJob
const { alertTime, timezone } = require('./config').preferences
const { participants, port } = require('./config')
const { deleteImage, sendMessage } = require('./lib/messenger')
const { addParticipant, updateKarma } = require('./lib/firebase')

app.use(parser.urlencoded({ extended: false }))

Expand Down Expand Up @@ -49,7 +50,7 @@ app.post('/incoming', wrap(async (req, res) => {
if (isImage) {
await sendMessage(getNextParticipant().number, { body: 'Does this litter look fit for a critter? If so, respond with "ok".', mediaUrl: MediaUrl0 })
await sendMessage(From, { body: 'Lit pic successfully sent...hopefully you did a good job :)' })
await setTimeout(() => await deleteImage(MessageSid, MediaSid), 10000)
await setTimeout(() => deleteImage(MessageSid, MediaSid), 10000)
}
if (isConfirmation) {
const prevParticipant = currentParticipant
Expand Down
29 changes: 29 additions & 0 deletions lib/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const firebase = require('firebase')
const config = require('../config').firebase
firebase.initializeApp(config)
const db = firebase.database()

module.exports.addParticipant = function addParticipant(name, phoneNumber) {
const uid = db.ref().child('participants').push().key
const newParticipant = db.ref().child(`participants/${uid}`)
newParticipant.set({
uid,
name,
phoneNumber,
karma: 0
})
.catch(err => console.log(err))
return uid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should move this return statement into a resolved promise

}

module.exports.updateKarma = function updateKarma(uid, increaseBy) {
const ref = db.ref().child(`participants/${uid}`)
const karmaRef = db.ref().child(`participants/${uid}/karma`)

ref.once('value').then(snapshot => {
let { karma } = snapshot.val()
karma += increaseBy
return karmaRef.set(karma)
})
.catch(err => console.log(err))
}
13 changes: 0 additions & 13 deletions lib/karma.js

This file was deleted.

Loading