23 lines
625 B
JavaScript
23 lines
625 B
JavaScript
const commands = require('./commands')
|
|
const api = require('../api-action')
|
|
|
|
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) {
|
|
await api.line.replyMessage(replyToken, result.reply)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
textMessage
|
|
}
|