Last active
September 16, 2019 15:59
-
-
Save zerojame/a49e29b1fd41142600de625991989788 to your computer and use it in GitHub Desktop.
noti-end-of-month#03
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
const functions = require('firebase-functions') | |
const moment = require('moment') | |
const request = require('request') | |
exports.CountEndOfMonth = functions.pubsub.schedule("0 7 * * *").timeZone('Asia/Bangkok').onRun((context) => { | |
const endDateOfMonth = moment().endOf('month').format('DD') | |
const currentDate = moment().format('DD') | |
let message = '' | |
if (currentDate === endDateOfMonth) { | |
message = `วันนี้เป็นวันสิ้นเดือนจ้า เย่เย้ ~~ 😁😁` | |
} else { | |
message = `อีก ${endDateOfMonth - currentDate} วัน จะสิ้นเดือน สู้สู้จ้า 🎉🎉` | |
} | |
request({ | |
method: 'POST', | |
uri: 'https://notify-api.line.me/api/notify', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
}, | |
auth: { | |
'bearer': <access_token> //คัดลอก line notify access token มาวางไว้ที่นี้ | |
}, | |
form: { | |
message: message | |
} | |
}, (err, httpResponse, body) => { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log(body) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment