Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@kkoiwai

SORACOM LTE-M ButtonからLINEにメッセージを送る

More than 1 year has passed since last update.

やったことは、LINEのAPIに登録して、SORACOM LTE-M Button powered by AWS をクリックしてSlackに通知する | Getting Started with SORACOM LTE-M Button | SORACOM Developers の、Lambdaのソースコードを下記に変えただけです。

const https = require('https');

exports.handler = (event, context, callback) => {
    console.log('Received event:', JSON.stringify(event, null, 2));

   // var text = event.stdEvent.clickType;

    var payload = {
        "to": [process.env.RECIPIENT_LINE_ID],
        "messages": [{
                "type": "text",
                "text": "こんにちは! LTE-M Buttonが押されたよ!"
            }
        ]
    }

    var body = JSON.stringify(payload);

    var req = https.request({
        hostname: "api.line.me",
        port: 443,
        path: "/v2/bot/message/multicast",
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Content-Length": Buffer.byteLength(body),
            "Authorization": "Bearer " + process.env.CHANNEL_ACCESS_TOKEN
        }
    }, function(res) {
        if (res.statusCode === 200) {
            console.log('Posted to LINE');
            callback(null, { "result": "ok" });
        }
        else {
            callback(false, { "result": "ng", "reason": 'Failed to post to LINE ' + res.statusCode });
        }
        return res;
    });
    req.write(body);
    req.end();
};

Lambdaの環境変数は、下記2点。
スクリーンショット 2018-11-05 22.42.47.png

 いずれも、LINEのチャネル基本設定から参照します。
アクセストークンは、ロングタームトークンの「再発行」を押すと発行できます。

スクリーンショット 2018-11-05 22.43.52.png
スクリーンショット 2018-11-05 22.44.51.png

7
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kkoiwai
小岩井航介

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?