add key word command not fin

This commit is contained in:
Jay
2018-07-13 00:29:41 +08:00
parent ceb522b21f
commit 4c56ff4300
5 changed files with 124 additions and 16 deletions
+34 -12
View File
@@ -36,6 +36,14 @@ const pushMessage = async (target, message = '') => {
await client(opts)
}
const textObject = (txt = '') => {
if (typeof txt !== 'string' || txt.trim().length === 0) return null
return {
type: 'text',
text: txt
}
}
/**
* send reply message
* @param {string} replyToken line message reply token
@@ -43,21 +51,35 @@ const pushMessage = async (target, message = '') => {
*/
const replyMessage = async (replyToken, message) => {
let url = '/message/reply'
let opts = {
method: 'post',
url,
data: {
replyToken,
messages: [
{
type: 'text',
text: message
}
]
let regex = /^\$(.+?)\$/
let m = message.match(regex)
let obj = null
message = message.replace(/^\$.+?\$/, '')
if (m !== null && m.length > 1) {
switch (m[1]) {
case 'image':
break
case 'text':
obj = textObject(message)
break
default:
obj = textObject(message)
}
}
await client(opts)
if (obj !== null) {
let opts = {
method: 'post',
url,
data: {
replyToken,
messages: [obj]
}
}
await client(opts)
}
}
module.exports = {