mtfosbot/libs/line-message/index.js
2018-07-10 23:48:26 +08:00

28 lines
764 B
JavaScript

const commands = require('./commands')
const api = require('../api-action')
/**
* parse text message object
* @param {object} evt line message event object
*/
const textMessage = async (evt) => {
let {replyToken, source, message} = evt
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
let result = await commands(text, source)
if (result === null) return
if (typeof result === 'object' && 'reply' in result) {
console.log('reply message :::: ', result.reply)
await api.line.replyMessage(replyToken, result.reply)
}
}
module.exports = {
textMessage
}