node-red-contrib-line-messaging-api 0.1.9 → 0.1.12

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.
package/README.md CHANGED
@@ -53,7 +53,7 @@ AdminタブからInstall
53
53
  * [npm](https://www.npmjs.com/package/node-red-contrib-line-messaging-api)
54
54
 
55
55
  ## release
56
-
56
+ - 2023/12/10: NotifyノードにNotify_newを追加。内部を少し更新。
57
57
  - 2021/8/1: Reply Messageが画像に対応(thanks [@ukkz](https://github.com/ukkz))
58
58
  - 2020/12/17: Bloadcast Messageに対応、Reply MessageがFlex Messageに対応(thanks [@gaomar](https://github.com/gaomar))
59
59
  - 2019/2/13: PUSH MessageとLINE Notify対応
@@ -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
+ }
@@ -20,7 +20,7 @@ module.exports = (RED) => {
20
20
 
21
21
  const client = new line.Client(lineconfig);
22
22
 
23
- node.on('input', async (msg) => {
23
+ node.on('input', async (msg, send, done) => {
24
24
 
25
25
  try {
26
26
  const res = await client.broadcast([{
@@ -34,10 +34,11 @@ module.exports = (RED) => {
34
34
  };
35
35
 
36
36
  msg.payload = output;
37
- node.send(msg);
37
+ send(msg);
38
+ done();
38
39
  } catch (error) {
39
40
  console.log(error);
40
- node.error(error);
41
+ done(error);
41
42
  }
42
43
  });
43
44
  }
@@ -15,7 +15,7 @@ module.exports = (RED) => {
15
15
  }
16
16
  });
17
17
 
18
- node.on('input', async (msg) => {
18
+ node.on('input', async (msg, send, done) => {
19
19
  const mes = msg.payload;
20
20
  try {
21
21
  const resLimit = await axios.get(`/`);
@@ -29,9 +29,11 @@ module.exports = (RED) => {
29
29
  }
30
30
 
31
31
  msg.payload = output;
32
- node.send(msg);
32
+ send(msg);
33
+ done();
33
34
  } catch (error) {
34
35
  console.log(error);
36
+ done(error);
35
37
  }
36
38
 
37
39
  });
@@ -15,14 +15,16 @@ module.exports = (RED) => {
15
15
  }
16
16
  });
17
17
 
18
- node.on('input', async (msg) => {
18
+ node.on('input', async (msg, send, done) => {
19
19
  const mes = msg.payload;
20
20
  try {
21
21
  const res = await axios.post(`/api/notify?message=${encodeURI(mes)}`);
22
22
  msg.payload = res.data;
23
- node.send(msg);
23
+ send(msg);
24
+ done();
24
25
  } catch (error) {
25
26
  console.log(error);
27
+ done(error);
26
28
  }
27
29
 
28
30
  });
@@ -19,8 +19,8 @@ module.exports = (RED) => {
19
19
 
20
20
  const client = new line.Client(lineconfig);
21
21
 
22
- node.on('input', async (msg) => {
23
- const userId = node.credentials.targetId;
22
+ node.on('input', async (msg, send, done) => {
23
+ const userId = msg.targetId || node.credentials.targetId;
24
24
  try {
25
25
  const res = await client.pushMessage(userId, {
26
26
  type: 'text',
@@ -28,10 +28,11 @@ module.exports = (RED) => {
28
28
  });
29
29
 
30
30
  msg.payload = res.data;
31
- node.send(msg);
31
+ send(msg);
32
+ done();
32
33
  } catch (error) {
33
34
  console.log(error);
34
- node.error(error);
35
+ done(error);
35
36
  }
36
37
  });
37
38
  }
@@ -72,15 +72,17 @@ module.exports = (RED) => {
72
72
  }
73
73
  }
74
74
 
75
- node.on('input', async (msg) => {
75
+ node.on('input', async (msg, send, done) => {
76
76
  if (msg.line && msg.line.event) {
77
77
  // 新仕様
78
78
  try {
79
79
  const result = await reply(msg);
80
80
  console.info(result);
81
+ send(msg);
82
+ done();
81
83
  } catch (err) {
82
84
  console.warn(err);
83
- node.error(err);
85
+ done(err);
84
86
  }
85
87
  } else if (msg.payload.events) {
86
88
  // 旧仕様
@@ -92,10 +94,11 @@ module.exports = (RED) => {
92
94
  result = { status: 200, message: 'Success' }
93
95
  }
94
96
  msg.payload = result;
95
- node.send(msg)
97
+ send(msg);
98
+ done();
96
99
  }).catch(err => {
97
100
  console.log(err);
98
- node.error(err);
101
+ done(err);
99
102
  });
100
103
  }
101
104
  });
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "node-red-contrib-line-messaging-api",
3
- "version": "0.1.9",
4
- "description": "LINE Messaging APIです",
3
+ "version": "0.1.12",
4
+ "description": "Node-REDでLINE Botが作れます。",
5
5
  "main": "line.js",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/n0bisuke/node-red-contrib-line-messaging-api.git"
9
9
  },
10
10
  "scripts": {
11
- "git-push": "git add -A && git commit -m 'update' && git push origin master",
11
+ "deploy": "git add -A && git commit -m 'update' && git push origin main",
12
12
  "test": "echo \"Error: no test specified\" && exit 1"
13
13
  },
14
14
  "node-red": {
@@ -18,13 +18,11 @@
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
- "keywords": [
25
- "line",
26
- "node-red"
27
- ],
25
+ "keywords": [],
28
26
  "author": "n0bisuke",
29
27
  "license": "Apache 2.0",
30
28
  "dependencies": {