Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8697

【Node.js】LINE BOT グループにプッシュ通知を送る

$
0
0

はじめに

LINE APIを使ってグループにpush通知を送る個人的メモ

モジュールインストール

axiosを使うと非常にシンプルにPOSTリクエストが送れるので採用

$ npm i axios

コード

index.js
constaxios=require('axios')constlinePost=async(msg)=>{console.log('linePost...')consttoken='API TOKENを入力してください'constreq_url='https://api.line.me/v2/bot/message/push'try{constres=awaitaxios.post(req_url,{//グループID"to":"グループのIDを設定してください","messages":[{"type":"text","text":msg}]},{headers:{Authorization:`Bearer ${token}`,'Content-Type':'application/json; charset=UTF-8'},})console.log(JSON.stringify(res))}catch(e){console.log(e.response.data)}}(async()=>{awaitlinePost('テストメッセージ')})()

実行方法

$ node index.js

Viewing all articles
Browse latest Browse all 8697

Trending Articles