Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const functions = require("firebase-functions")
const axios = require("axios")
const notiToken = 'REPLACE LINE NOTIFY TOKEN HERE'
exports.monitorData = functions.region("asia-southeast1").database.ref('Product/{id}').onWrite(async (snap, context) => {
message = `\มีข้อมูลเปลี่ยนแปลง
name จาก ${snap.before._data['1']} -> ${snap.after._data['1']}
stock จาก ${snap.before._data['2']} -> ${snap.after._data['2']}
`
const params = {
message: message
};
const data = Object.keys(params)
.map((key) => `${key}=${encodeURIComponent(params[key])}`)
.join('&');
await axios({
method: "post",
url: "https://notify-api.line.me/api/notify",
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${notiToken}`
},
data: data
}).then((response) => {
console.log(response)
}).catch((error) => {
console.log(error)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment