node-red-contrib-line-messaging-api 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ <script>
2
+ RED.nodes.registerType('Notify_New',{
3
+ category: 'LINE',
4
+ color: '#1ad823',
5
+ defaults: {
6
+ name: {value:""},
7
+ },
8
+ credentials: {
9
+ AccessToken: { type: "password", required: true }
10
+ },
11
+ inputs:1,
12
+ outputs:0,
13
+ icon: "comment.png",
14
+ align: "right",
15
+ label: function() {
16
+ return this.name||"Notify_New";
17
+ }
18
+ });
19
+ </script>
20
+
21
+ <script type="text/x-red" data-template-name="Notify_New">
22
+ <div class="form-row">
23
+ <label for="node-input-name"><i class="icon-tag"></i> Name</label>
24
+ <input type="text" id="node-input-name" placeholder="Name">
25
+ </div>
26
+
27
+ <div class="form-row">
28
+ <label for="node-input-AccessToken">
29
+ <i class="icon-tag"></i>
30
+ LINE Notify AccessToken
31
+ </label>
32
+ <input type="password" id="node-input-AccessToken" placeholder="LINE Notify AccessToken">
33
+ </div>
34
+ </script>
35
+
36
+ <script type="text/x-red" data-help-name="Notify">
37
+ <p><a href="https://notify-bot.line.me/my/">LINE Notify</a>でアクセストークンを取得して設定して下さい。</p>
38
+ </script>
@@ -0,0 +1,47 @@
1
+ module.exports = (RED) => {
2
+ 'use strict';
3
+
4
+ const LINE_NOTIFY_BASE_URL = 'https://notify-api.line.me';
5
+ const LINE_NOTIFY_PATH = '/api/notify';
6
+ let REQUEST_OPTIONS = {};
7
+
8
+ const main = function(config){
9
+ const node = this;
10
+ RED.nodes.createNode(node, config);
11
+
12
+ const LINE_NOTIFY_TOKEN = node.credentials.AccessToken;
13
+ REQUEST_OPTIONS = {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/x-www-form-urlencoded',
17
+ 'Authorization': `Bearer ${LINE_NOTIFY_TOKEN}`
18
+ }
19
+ };
20
+
21
+
22
+ /**
23
+ * 実行時の処理
24
+ */
25
+ node.on('input', async (msg, send, done) => {
26
+ const mes = msg.payload;
27
+ const REQUEST_URL = `${LINE_NOTIFY_BASE_URL}${LINE_NOTIFY_PATH}?message=${encodeURI(mes)}`;
28
+ try {
29
+ const response = await fetch(REQUEST_URL, REQUEST_OPTIONS);
30
+ const data = await response.json();
31
+ msg.payload = data;
32
+ console.log(data); // { status: 200, message: 'ok' }
33
+ send(msg);
34
+ done();
35
+ } catch (error) {
36
+ console.log(error);
37
+ done(error);
38
+ }
39
+ });
40
+ }
41
+
42
+ RED.nodes.registerType("Notify_New", main, {
43
+ credentials: {
44
+ AccessToken: {type:"password"}
45
+ }
46
+ });
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-line-messaging-api",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Node-REDでLINE Botが作れます。",
5
5
  "main": "line.js",
6
6
  "repository": {
@@ -18,7 +18,8 @@
18
18
  "PushMessage": "./nodes/push/push.js",
19
19
  "BloadcastMessage": "./nodes/bloadcast/bloadcast.js",
20
20
  "Limit": "./nodes/limit/limit.js",
21
- "Notify": "./nodes/notify/notify.js"
21
+ "Notify": "./nodes/notify/notify.js",
22
+ "Notify_new": "./nodes/_new/notify/notify.js"
22
23
  }
23
24
  },
24
25
  "keywords": ["node-red"],