Skip to content

Instantly share code, notes, and snippets.

@Thainainan03
Last active September 16, 2019 15:58
Show Gist options
  • Save Thainainan03/932355f872f3192981631d0df78e58bc to your computer and use it in GitHub Desktop.
Save Thainainan03/932355f872f3192981631d0df78e58bc to your computer and use it in GitHub Desktop.
noti-end-of-month#04
exports.CountEndOfMonth = functions.pubsub.schedule("* * * * *").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