add line push/reply , add fb parser post
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
const axios = require('axios')
|
||||
const config = require('../../config')
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: 'https://api.line.me/v2/bot',
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.line.access}`
|
||||
}
|
||||
})
|
||||
|
||||
const pushMessage = async (target, message = '') => {
|
||||
if (typeof target !== 'string' || target.trim().length === 0) return
|
||||
if (typeof message !== 'string' || message.trim().length === 0) return
|
||||
|
||||
let data = {
|
||||
to: target,
|
||||
messages: [
|
||||
{
|
||||
type: 'text',
|
||||
text: message
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
let opts = {
|
||||
method: 'post',
|
||||
url: '/message/push',
|
||||
data
|
||||
}
|
||||
|
||||
await client(opts)
|
||||
}
|
||||
|
||||
const textMessage = async (evt) => {
|
||||
let replyURL = '/message/reply'
|
||||
let {replyToken, source, message} = evt
|
||||
if (!message || message.type !== 'text') return
|
||||
let {text} = message
|
||||
if (typeof text !== 'string') return
|
||||
text = text.trim()
|
||||
if (text.length === 0) return
|
||||
|
||||
let opts = {
|
||||
method: 'post',
|
||||
url: replyURL,
|
||||
data: {
|
||||
replyToken,
|
||||
messages: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'test message'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
await client(opts)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
textMessage,
|
||||
pushMessage
|
||||
}
|
||||
Reference in New Issue
Block a user