push.js 2.17 KB
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
request.post(
    {
        url: MULTI_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)
    });


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