node-red-contrib-line-messaging-api 0.3.0 → 0.3.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.
package/README.md CHANGED
@@ -34,17 +34,59 @@ AdminタブからInstall
34
34
 
35
35
  ### Push Message
36
36
 
37
- ![](https://i.gyazo.com/1562a3e4539469515c798d9e3c50d052.gif)
37
+ Pushメッセージを送るときにmsg.payloadにテキストを入れることでテキストメッセージの送信ができます。
38
+
39
+ > ![](https://i.gyazo.com/1562a3e4539469515c798d9e3c50d052.gif)
40
+
41
+ #### テキストメッセージv2でユーザーにメンション
42
+
43
+ Pushメッセージを送るときにmsg.payloadに`{hoge}`などのテキストを入れつつ、msg.substitutionを設定することでテキストメッセージv2を使ってユーザーにメンションすることができます。
44
+
45
+ - msg.payload: `Welcome, {user1}! {laugh}\n{everyone} There is a newcomer!`
46
+ - msg.substitution:
47
+
48
+ ```json
49
+ {"user1": {"type": "mention", "mentionee": {"type": "user", "userId": "Uxxxxxxxxxxxx"}},"laugh": {"type": "emoji","productId": "670e0cce840a8236ddd4ee4c","emojiId": "002"},"everyone": {"type": "mention","mentionee": {"type": "all"}}}
50
+ ```
51
+
52
+ > ![](https://i.gyazo.com/3fa696275f53251bf99e7a1354183d72.png)
53
+
54
+ #### 任意のメッセージ
55
+
56
+ msg.payloadに配列や[メッセージオブジェクト](https://developers.line.biz/ja/reference/messaging-api/#message-objects)を設定することで任意のメッセージを送信できます。
57
+
58
+ ```js
59
+ msg.payload = [
60
+ {
61
+ type: "text",
62
+ text: "hogehoge",
63
+ },
64
+ {
65
+ type: "image",
66
+ originalContentUrl: 'https://i.gyazo.com/e772c3b48a07716226f7184d7f417cda.png',
67
+ previewImageUrl: 'https://i.gyazo.com/e772c3b48a07716226f7184d7f417cda.png'
68
+ }
69
+ ]
70
+
71
+ return msg;
72
+ ```
38
73
 
39
74
  ### Bloadcast Message
40
75
 
41
76
  * 友達全員にメッセージ配信
42
77
 
43
- ![](https://i.gyazo.com/ef7c655a74e85e23db5ee156e5490e15.png)
78
+ > ![](https://i.gyazo.com/ef7c655a74e85e23db5ee156e5490e15.png)
79
+
80
+ ### Loading
81
+
82
+ ローディングを表示させます。
83
+
84
+ > ![](https://i.gyazo.com/355a5f5cca896740eaa50a7b9d76a8fc.gif)
85
+ > https://developers.line.biz/ja/reference/messaging-api/#display-a-loading-indicator
44
86
 
45
- ### LINE Notify
87
+ ### LINE Notify (2024/12/22追記: API自体が終了するため廃止予定です。)
46
88
 
47
- ![](https://i.gyazo.com/e64db6a7ee48cea43ed3c70b5fd2f05f.gif)
89
+ > ![](https://i.gyazo.com/e64db6a7ee48cea43ed3c70b5fd2f05f.gif)
48
90
 
49
91
  ### LINE Notify_new
50
92
 
@@ -10,7 +10,7 @@
10
10
  },
11
11
  inputs:1,
12
12
  outputs:1,
13
- icon: "comment.png",
13
+ icon: "watch.png",
14
14
  align: "right",
15
15
  label: function() {
16
16
  return this.name||"Limit";
@@ -0,0 +1,72 @@
1
+ <script>
2
+ RED.nodes.registerType('Loading',{
3
+ category: 'LINE',
4
+ color: '#01B301',
5
+ defaults: {
6
+ name: {value:""},
7
+ loadingSeconds: {value: 20}
8
+ },
9
+ credentials: {
10
+ channelAccessToken: { type: "password", required: true },
11
+ targetId:{type:"password", required:true}
12
+ },
13
+ inputs:1,
14
+ outputs:1,
15
+ icon: "timer.png",
16
+ align: "right",
17
+ label: function() {
18
+ return this.name||"Loading";
19
+ }
20
+ });
21
+ </script>
22
+
23
+ <script type="text/x-red" data-template-name="Loading">
24
+ <div class="form-row">
25
+ <label for="node-input-name"><i class="icon-tag"></i> Name</label>
26
+ <input type="text" id="node-input-name" placeholder="Name">
27
+ </div>
28
+
29
+ <div class="form-row">
30
+ <label for="node-input-channelAccessToken">
31
+ <i class="icon-tag"></i>
32
+ Channel Access Token
33
+ </label>
34
+ <input type="password" id="node-input-channelAccessToken" placeholder="LINE Channel AccessToken">
35
+ </div>
36
+
37
+ <div class="form-row">
38
+ <label for="node-input-targetId"><i class="icon-tag"></i> User Id</label>
39
+ <input type="text" id="node-input-targetId" placeholder="User Id">
40
+ </div>
41
+
42
+ <div class="form-row">
43
+ <label for="node-input-loadingSeconds">
44
+ <i class="icon-timer"></i> Loading Seconds
45
+ </label>
46
+ <select id="node-input-loadingSeconds">
47
+ <option value="5">5</option>
48
+ <option value="10">10</option>
49
+ <option value="15">15</option>
50
+ <option value="20" selected>20</option>
51
+ <option value="25">25</option>
52
+ <option value="30">30</option>
53
+ <option value="35">35</option>
54
+ <option value="40">40</option>
55
+ <option value="45">45</option>
56
+ <option value="50">50</option>
57
+ <option value="55">55</option>
58
+ <option value="60">60</option>
59
+ </select>
60
+ </div>
61
+
62
+ <p>
63
+ このノードは、指定した秒数だけローディングアニメーションを表示させます。<br>
64
+ 現状(2024年12月に記載)、グループには対応してなく<br>
65
+ UからはじまるユーザーIDのみ(個別チャット)です。
66
+ 詳細は<a href="https://developers.line.biz/ja/reference/messaging-api/#display-a-loading-indicator" target="_blank">公式ドキュメント</a>を参照下さい。
67
+ </p>
68
+ </script>
69
+
70
+ <script type="text/x-red" data-help-name="Loading">
71
+ <p>当月の送信メッセージのリミットを教えてくれます。</p>
72
+ </script>
@@ -0,0 +1,62 @@
1
+ module.exports = (RED) => {
2
+ 'use strict';
3
+
4
+ const line = require('@line/bot-sdk');
5
+
6
+ const main = function(config){
7
+ const node = this;
8
+ RED.nodes.createNode(node, config);
9
+
10
+ let lineconfig;
11
+ try {
12
+ lineconfig = require('../../env');
13
+ } catch (error) {
14
+ lineconfig = {
15
+ // channelSecret: node.credentials.channelSecret,
16
+ channelAccessToken: node.credentials.channelAccessToken
17
+ };
18
+ }
19
+ if(lineconfig.channelAccessToken === undefined || lineconfig.channelAccessToken === '') {
20
+ console.error('token not found');
21
+ return;
22
+ }
23
+ const client = new line.messagingApi.MessagingApiClient(lineconfig);
24
+ // const client = new line.Client(lineconfig);
25
+
26
+ node.on('input', async (msg, send, done) => {
27
+
28
+ //chat
29
+ const chatId = msg.targetId || node.credentials.targetId;
30
+ const loadingSeconds = msg.loadingSeconds || config.loadingSeconds;
31
+ // console.log(chatId,loadingSeconds);
32
+
33
+ try {
34
+ const res = await client.showLoadingAnimation({
35
+ chatId: chatId, //現状user idのみ
36
+ loadingSeconds: loadingSeconds,
37
+ });
38
+
39
+ // レスポンスが {}(空のJSONオブジェクト)なら成功らしい
40
+ if (res && Object.keys(res).length === 0) {
41
+ node.log('ローディングが成功しました: {} が返却されました');
42
+ } else {
43
+ node.warn('ローディング処理失敗:', res);
44
+ }
45
+ send(msg);
46
+ } catch (error) {
47
+ console.error(error.body);
48
+ node.error(error.body, msg.payload);
49
+ send(msg);
50
+ done(error);
51
+ }
52
+
53
+ });
54
+ }
55
+
56
+ RED.nodes.registerType("Loading", main, {
57
+ credentials: {
58
+ channelAccessToken: {type:"password"},
59
+ targetId: {type:"password"},
60
+ }
61
+ });
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-line-messaging-api",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Node-REDでLINE Botが作れます。",
5
5
  "main": "line.js",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  "PushMessage_New": "./nodes/_new/push/push.js",
19
19
  "BloadcastMessage": "./nodes/bloadcast/bloadcast.js",
20
20
  "Limit": "./nodes/limit/limit.js",
21
+ "Loading": "./nodes/loading/loading.js",
21
22
  "ReplyMessage": "./nodes/reply/reply.js",
22
23
  "PushMessage": "./nodes/push/push.js",
23
24
  "Notify_New": "./nodes/_new/notify/notify.js",