mtfosbot/libs/line-message/index.js

28 lines
767 B
JavaScript
Raw Normal View History

2018-06-27 09:50:56 +00:00
const commands = require('./commands')
2018-07-13 05:30:54 +00:00
const api = require('@libs/api-action')
2018-06-28 13:26:44 +00:00
/**
* parse text message object
* @param {object} evt line message event object
*/
const textMessage = async (evt) => {
let {replyToken, source, message} = evt
2018-06-27 09:50:56 +00:00
if (!source || !('type' in source) || source.type !== 'group') return
if (!message || message.type !== 'text') return
let {text} = message
if (typeof text !== 'string') return
text = text.trim()
if (text.length === 0) return
2018-06-27 09:50:56 +00:00
let result = await commands(text, source)
if (result === null) return
if (typeof result === 'object' && 'reply' in result) {
2018-07-10 15:48:26 +00:00
console.log('reply message :::: ', result.reply)
2018-06-28 09:37:33 +00:00
await api.line.replyMessage(replyToken, result.reply)
2018-06-27 09:50:56 +00:00
}
}
module.exports = {
2018-06-28 09:37:33 +00:00
textMessage
}