diff --git a/exampleMassage/action.json b/exampleMassage/action.json new file mode 100644 index 0000000..416b863 --- /dev/null +++ b/exampleMassage/action.json @@ -0,0 +1,59 @@ +{ + "action": { + "type": "text", + "text": "Hello Quick Reply!", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "uri", + "label": "Add to Cart", + "uri": "https://developers.line.me" + } + }, + { + "type": "action", + "action": { + "type": "postback", + "label": "Postback", + "data": "action=buy&itemid=123" + } + }, + { + "type": "action", + "action": { + "type": "datetimepicker", + "label": "Datetime Picker", + "data": "storeId=12345", + "mode": "datetime", + "initial": "2018-09-11T00:00", + "max": "2018-12-31T23:59", + "min": "2018-01-01T00:00" + } + }, + { + "type": "action", + "action": { + "type": "camera", + "label": "Camera" + } + }, + { + "type": "action", + "action": { + "type": "cameraRoll", + "label": "Gallery" + } + }, + { + "type": "action", + "action": { + "type": "location", + "label": "Location" + } + } + ] + } + } +} \ No newline at end of file diff --git a/index.js b/index.js index e786934..30d9a78 100644 --- a/index.js +++ b/index.js @@ -18,12 +18,14 @@ const client = new line.Client(config); const app = express(); // webhook callback +let debugMode = false; app.use("/webhook", line.middleware(config)); app.post("/webhook", (req, res) => { // req.body.events should be an array of events if (!Array.isArray(req.body.events)) { return res.status(500).end(); } + console.log('req.body.events !',req.body.events) // handle events separately Promise.all( req.body.events.map((event) => { @@ -51,7 +53,7 @@ const handleEvent = (event) => { text: "Hello From PUI", }; - if (event.message.type == "text") { + if (event.type == "message" && event.message.type == "text") { let selecttext = String(event.message.text).toLowerCase(); let get_text = ContentService.mockText()[selecttext]; if (get_text) { @@ -61,6 +63,8 @@ const handleEvent = (event) => { payload.text = "Other Message =>>>" + JSON.stringify(event); } + console.log("SEND TO ==> " + JSON.stringify(payload)); + return client.replyMessage(event.replyToken, payload); }; @@ -71,12 +75,14 @@ app.get("/", (req, res) => { app.post("/push", (req, res) => { let body = req.body; - let { user_id } = body; + let { user_id, message } = body; console.log("push =>> body ::", body); - let message = { - type: "text", - text: `Push Message! to ${user_id}`, - }; + if (!message) { + message = { + type: "text", + text: `Push Message! to ${user_id}`, + }; + } client.pushMessage(user_id, message); res.json(message); }); diff --git a/services/ContentService.js b/services/ContentService.js index 6599c93..6d1dacc 100644 --- a/services/ContentService.js +++ b/services/ContentService.js @@ -1,9 +1,8 @@ - const flexMsg = require("./flexMsg"); +const { action } = require("../exampleMassage/action.json"); const genMsgContent = flexMsg.GenContentFlex; const flexs = flexMsg.flexs; - const ContentService = { mockText: () => { return { @@ -16,6 +15,7 @@ const ContentService = { bub4: flexs.bub4, bub5: flexs.bub5, bub6: flexs.bub6, + action: action, }; }, }; diff --git a/test.json b/test.json new file mode 100644 index 0000000..b3fea6d --- /dev/null +++ b/test.json @@ -0,0 +1,53 @@ +{ + "type": "flex", + "altText": "GenContentFlex!0", + "contents": { + "type": "bubble", + "direction": "ltr", + "header": { + "type": "box", + "layout": "vertical", + "contents": [ + { + "type": "text", + "text": "Header", + "align": "center", + "contents": [] + } + ] + }, + "hero": { + "type": "image", + "url": "https://1417094351.rsc.cdn77.org/articles/1439/1438984/thumbnail/small.gif?3", + "size": "full", + "aspectRatio": "1.51:1", + "aspectMode": "fit" + }, + "body": { + "type": "box", + "layout": "vertical", + "contents": [ + { + "type": "text", + "text": "Body", + "align": "center", + "contents": [] + } + ] + }, + "footer": { + "type": "box", + "layout": "horizontal", + "contents": [ + { + "type": "button", + "action": { + "type": "uri", + "label": "Button", + "uri": "https://linecorp.com" + } + } + ] + } + } +} \ No newline at end of file -- libgit2 0.21.2