push.js 2.48 KB
const { send } = require('express/lib/response');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
const USER_ID = '사Uc4258407a7677769f74ba184ec036651'

//Single User
// request.post(
//     {
//         url: TARGET_URL,
//         headers: {
//             'Authorization': `Bearer ${TOKEN}`
//         },
//         json: {
//             "to": `${USER_ID}`,
//             "messages":[
//                 {
//                     "type":"text",
//                     "text":"Hello, user"
//                 },
//                 {
//                     "type":"text",
//                     "text":"May I help you?"
//                 }
//             ]
//         }
//     },(error, response, body) => {
//         console.log(body)
//     });


// Multicast User

function Multicast(sendMsg){
    request.post(
        {
            url: MULTI_TARGET_URL,
            headers: {
                'Authorization': `Bearer ${TOKEN}`
            },
            json: {
                "to": [`${USER_ID}`],
                "messages":[
                    {
                        "type":"text",
                        "text":sendMsg
                    },
                    {
                        "type":"text",
                        "text":"May I help you?"
                    }
                ]
            }
        },(error, response, body) => {
            console.log(body)
        });
}


exports.SendMessage = function(sendMessage){
    Multicast(sendMessage);
}

// // Broadcast
//     request.post(
//         {
//             url: BROAD_TARGET_URL,
//             headers: {
//                 'Authorization': `Bearer ${TOKEN}`
//             },
//             json: {
//                 "messages":[
//                     {
//                         "type":"text",
//                         "text":"This is broadcast message."
//                     },
//                     {
//                         "type":"text",
//                         "text":"May I help you?"
//                     }
//                 ]
//             }
//         },(error, response, body) => {
//             console.log(body)
//         });