0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

はじめに

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

モジュールインストール

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

$ npm i axios

コード

index.js
const axios = require('axios')

const linePost = async (msg) => {
	console.log('linePost...')
	const token = 'API TOKENを入力してください'

	const req_url = 'https://api.line.me/v2/bot/message/push'
	try {
		const res = await axios.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 () => {
	await linePost('テストメッセージ')
})()

実行方法

$ node index.js
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?