Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export const webhookLINE = functions.region(REGION).https.onRequest( async(req, res) => {
console.log('🚀 Start Webhook!!', JSON.stringify(req.body) )
if(!req.body.events) { res.status(200).end()}
const event = req.body.events[0]
if(typeof(event) === 'undefined') { res.status(200).end()}
try {
await util_line.verify_signature(req, res)
let replyMessage: any = null
switch (event.type) {
case 'message':
if (event.message.type === 'text') {
const message = event.message.text
if(message.toLowerCase() === 'trello') {
replyMessage = await getBoardPayload()
}
if(replyMessage) {
await util_line.reply(event.replyToken, replyMessage)
}
}
break
case 'postback':
break
default:
}
} catch (err) {
console.error(err)
res.status(500).end()
}
res.status(200)
})
const getBoardPayload = async() => {
const data = await firestore.collection('board').orderBy('changeTime', 'desc').limit(13).get()
if (!data.empty) {
const payloadBoardList = data.docs.map( (doc:any) => {
const {id, name, changeTime} = doc.data()
return msgTrello.boardItem(id, name, formatTime(changeTime))
})
return msgTrello.boardMain(payloadBoardList)
} else {
return msgTrello.boardEmpty()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment