node-red-contrib-line-messaging-api 0.2.1 → 0.2.2

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.
@@ -12,6 +12,7 @@
12
12
  outputs:1,
13
13
  icon: "comment.png",
14
14
  align: "right",
15
+ paletteLabel: 'Notify_New',
15
16
  label: () => this.name || 'Notify_New',
16
17
  });
17
18
  </script>
@@ -1,5 +1,5 @@
1
1
  <script>
2
- RED.nodes.registerType('ReplyMessage',{
2
+ RED.nodes.registerType('ReplyMessage_New',{
3
3
  category: 'LINE',
4
4
  color: '#01B301',
5
5
  defaults: {
@@ -11,17 +11,17 @@
11
11
  channelAccessToken: {type:"password", required:true},
12
12
  },
13
13
  inputs:1,
14
- outputs:0,
14
+ outputs:1,
15
15
  icon: "comment.png",
16
16
  align: "right",
17
- paletteLabel: 'Reply',
17
+ paletteLabel: 'Reply_New',
18
18
  label: function () {
19
- return this.name || 'ReplyMessage';
19
+ return this.name || 'ReplyMessage_New';
20
20
  }
21
21
  });
22
22
  </script>
23
23
 
24
- <script type="text/x-red" data-template-name="ReplyMessage">
24
+ <script type="text/x-red" data-template-name="ReplyMessage_New">
25
25
  <div class="form-row">
26
26
  <label for="node-input-name"><i class="icon-tag"></i> Name</label>
27
27
  <input type="text" id="node-input-name" placeholder="Name">
@@ -43,6 +43,6 @@
43
43
  </div>
44
44
  </script>
45
45
 
46
- <script type="text/x-red" data-help-name="ReplyMessage">
46
+ <script type="text/x-red" data-help-name="ReplyMessage_New">
47
47
  <p>A simple node that converts the message payloads into all ReplyMessage characters</p>
48
48
  </script>
@@ -53,15 +53,20 @@ module.exports = (RED) => {
53
53
  }
54
54
 
55
55
  // 新仕様
56
- const reply = (msg) => {
56
+ const reply = async (msg) => {
57
+ console.log(typeof msg.payload, msg.payload);
57
58
  if (!msg.line || !msg.line.event || !msg.line.event.type) {
58
59
  throw 'no valid LINE event found within msg';
59
60
  } else if (!msg.line.event.replyToken) {
60
61
  throw 'no replyable LINE event received';
61
62
  } else if (!msg.payload) {
62
63
  throw 'reply content (msg.payload) is empty';
63
- } else if (typeof msg.payload === 'object' && msg.payload.type) {
64
- // payloadがオブジェクトの場合はメッセージオブジェクト扱いで送信される
64
+ } else if(typeof msg.payload === 'object' && Array.isArray(msg.payload) && msg.payload.length !== 0 && msg.payload[0].type){
65
+ // payloadが配列かつメッセージオブジェクトが中身の場合
66
+ return client.replyMessage(msg.line.event.replyToken, msg.payload);
67
+ }
68
+ else if (typeof msg.payload === 'object' && msg.payload.type) {
69
+ // payloadがオブジェクトの場合
65
70
  return client.replyMessage(msg.line.event.replyToken, msg.payload);
66
71
  } else {
67
72
  // payloadがそれ以外なら強制的に文字列に変換しテキストメッセージ扱いで送信する
@@ -76,9 +81,8 @@ module.exports = (RED) => {
76
81
  if (msg.line && msg.line.event) {
77
82
  // 新仕様
78
83
  try {
79
- const result = await reply(msg);
80
- console.info(result);
81
- send(msg);
84
+ msg.payload = await reply(msg);
85
+ send(msg); //次のノードへ
82
86
  done();
83
87
  } catch (err) {
84
88
  console.warn(err);
@@ -104,7 +108,7 @@ module.exports = (RED) => {
104
108
  });
105
109
  }
106
110
 
107
- RED.nodes.registerType('ReplyMessage', main, {
111
+ RED.nodes.registerType('ReplyMessage_New', main, {
108
112
  credentials: {
109
113
  channelSecret: { type:'password' },
110
114
  channelAccessToken: { type:'password' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-line-messaging-api",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Node-REDでLINE Botが作れます。",
5
5
  "main": "line.js",
6
6
  "repository": {
@@ -19,9 +19,9 @@
19
19
  "BloadcastMessage": "./nodes/bloadcast/bloadcast.js",
20
20
  "Limit": "./nodes/limit/limit.js",
21
21
  "Notify": "./nodes/notify/notify.js",
22
- "Notify_new": "./nodes/_new/notify/notify.js",
23
- "ReplyMessage_new": "./nodes/_new/reply/reply.js",
24
- "PushMessage_new": "./nodes/_new/push/push.js"
22
+ "Notify_New": "./nodes/_new/notify/notify.js",
23
+ "ReplyMessage_New": "./nodes/_new/reply/reply.js",
24
+ "PushMessage_New": "./nodes/_new/push/push.js"
25
25
  }
26
26
  },
27
27
  "keywords": ["node-red"],