回答編集履歴
4
修正
test
CHANGED
@@ -74,13 +74,13 @@
|
|
74
74
|
|
75
75
|
}
|
76
76
|
|
77
|
-
|
77
|
+
appendFooterAndSend();
|
78
78
|
|
79
79
|
});
|
80
80
|
|
81
81
|
} else {
|
82
82
|
|
83
|
-
|
83
|
+
appendFooterAndSend();
|
84
84
|
|
85
85
|
}
|
86
86
|
|
@@ -118,4 +118,6 @@
|
|
118
118
|
|
119
119
|
}
|
120
120
|
|
121
|
+
|
122
|
+
|
121
123
|
```
|
3
追記
test
CHANGED
@@ -19,3 +19,103 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
補足: 上の最後の文は、`request.get`を`for`ループ内で毎回実行するのではなく、最初に一回だけ行う、という前提での話でした。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
---------------
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
細かい所は適当ですがこんな感じの構成にすればいいのではないでしょうか。
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
if (body.notifications.length > 0) {
|
34
|
+
|
35
|
+
ref1 = body.notifications;
|
36
|
+
|
37
|
+
request.get({
|
38
|
+
|
39
|
+
url: "https://slack.com/api/users.list?token=" + process.env.HUBOT_SLACK_TOKEN
|
40
|
+
|
41
|
+
}, function(err, response, body) {
|
42
|
+
|
43
|
+
var member;
|
44
|
+
|
45
|
+
var j, len1, ref2;
|
46
|
+
|
47
|
+
ref2 = JSON.parse(body).members;
|
48
|
+
|
49
|
+
for (i = 0, len = ref1.length; i < len; i++) {
|
50
|
+
|
51
|
+
a = ref1[i];
|
52
|
+
|
53
|
+
username = "" + a.user.name;
|
54
|
+
|
55
|
+
message += "" + a.user.name; //名前表示
|
56
|
+
|
57
|
+
console.log(a.user.name);
|
58
|
+
|
59
|
+
console.log(a.user.id);
|
60
|
+
|
61
|
+
for (j = 0, len1 = ref2.length; j < len1; j++) {
|
62
|
+
|
63
|
+
member = ref2[j];
|
64
|
+
|
65
|
+
if (member.profile.display_name === username) { //slackの表示名とバックログの名前が一致した時に、slackID
|
66
|
+
|
67
|
+
var memberid = member.id; //slackID取得
|
68
|
+
|
69
|
+
message += "<@" + memberid + ">";
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
sendMessage();
|
78
|
+
|
79
|
+
});
|
80
|
+
|
81
|
+
} else {
|
82
|
+
|
83
|
+
sendMessage();
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
function appendFooterAndSend() {
|
90
|
+
|
91
|
+
message += "\n[" + body.project.projectKey + "-" + body.content.key_id + "] - ";
|
92
|
+
|
93
|
+
message += body.content.summary + " _by" + body.createdUser.name + "_\n>>> ";
|
94
|
+
|
95
|
+
if (((ref2 = body.content.comment) !== null ? ref2.content : void 0) !== null) {
|
96
|
+
|
97
|
+
message += body.content.comment.content + "\n";
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
message += "" + url;
|
102
|
+
|
103
|
+
console.log('message = ' + message);
|
104
|
+
|
105
|
+
if (message !== null) {
|
106
|
+
|
107
|
+
robot.messageRoom(room, message);
|
108
|
+
|
109
|
+
return res.end("OK");
|
110
|
+
|
111
|
+
} else {
|
112
|
+
|
113
|
+
robot.messageRoom(room, "Backlog integration error.");
|
114
|
+
|
115
|
+
return res.end("Error");
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
```
|
2
補足
test
CHANGED
@@ -15,3 +15,7 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
`request.get`は非同期なので完了を待って結果を得てから送信しなければいけません。つまり`request.get`の後に書いてある処理はすべて`request.get`のコールバックで実行する必要があります。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
補足: 上の最後の文は、`request.get`を`for`ループ内で毎回実行するのではなく、最初に一回だけ行う、という前提での話でした。
|
1
修正
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
原因はおそらく、`memberid`がグローバル変数になっていて`request.get`内で非同期に値が変わるため、このような状況なのではないかと思います。
|
1
|
+
原因はおそらく、`memberid`がグローバル変数になっていて`request.get`のコールバック内で非同期に値が変わるため、このような状況になっているのからではないかと思います。
|
2
2
|
|
3
3
|
|
4
4
|
|