mtfosbot/libs/line-message/index.js

23 lines
625 B
JavaScript
Raw Normal View History

2018-06-27 09:50:56 +00:00
const commands = require('./commands')
2018-06-28 09:37:33 +00:00
const api = require('../api-action')
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-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
}