Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from okhiroyuki/feature/modify-output
Browse files Browse the repository at this point in the history
modify output
  • Loading branch information
okhiroyuki committed Mar 8, 2020
2 parents aab6386 + 77bff0e commit a644390
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
16 changes: 10 additions & 6 deletions nodes/line-notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ module.exports = function(RED) {

node.on('input', function(msg) {
if(!node.accessToken){
sendError(node, "toeken is empty");
msg.payload = "token is empty";
msg.status = -1;
sendError(node, msg);
return;
}
let datajson = {
Expand Down Expand Up @@ -130,19 +132,21 @@ module.exports = function(RED) {
};

axios.request(lineconfig).then((res) => {
msg.payload = res.data;
msg.status = res.data.status;
node.send(msg);
node.status({fill: "blue", shape: "dot", text: "success"});
})
.catch((error) => {
sendError(node, error.message);
msg.status = error.response.data.status;
msg.payload = error.response.data.message;
sendError(node, msg);
});
});
}

function sendError(node, message){
node.error(message);
node.status({ fill: "red", shape: "ring", text: message});
function sendError(node, msg){
node.error(msg);
node.status({ fill: "red", shape: "ring", text: msg.payload});
}

function linetoken(n){
Expand Down
8 changes: 7 additions & 1 deletion nodes/locales/en-US/line-nofify.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script type="text/x-red" data-help-name="line-notify">
<p>You can send notifications to LINE at this node.</p>
<h3>入力</h3>
<h3>Input</h3>
<dl class="message-properties">
<dt class="optional">payload <span class="property-type">string</span></dt>
<dd>message</dd>
Expand All @@ -13,10 +13,16 @@ <h3>入力</h3>
<dt class="optional">stickerId <span class="property-type">number</span></dt>
<dd>stikckerId</dd>
</dl>
<h3>Output</h3>
<dl class="message-properties">
<dt>status <span class="property-type">number</span></dt>
<dd>status code</dd>
</dl>
<h3>Detials</h3>
<p>Message and image URL can be overwritten with msg variable only when the set value is empty.</p>
<p>If no thumbnail is specified, it will be overwritten with the full size image URL.</p>
<p>For further details of see <a href="https://notify-bot.line.me/doc/en/">LINE Notify API Document</a>.</p>
<p>If an error occurs, an error message is output to msg.payload.</p>
</script>

<script type="text/x-red" data-help-name="line-notify">
Expand Down
6 changes: 6 additions & 0 deletions nodes/locales/ja/line-notify.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ <h3>入力</h3>
<dt class="optional">stickerId <span class="property-type">number</span></dt>
<dd>ステッカーId</dd>
</dl>
<h3>出力</h3>
<dl class="message-properties">
<dt>status <span class="property-type">number</span></dt>
<dd>ステータスコード</dd>
</dl>
<h3>詳細</h3>
<p>メッセージおよび画像URLは、設定した値が空の場合のみmsg変数で上書きすることが可能です。</p>
<p>サムネイルが指定されていない場合は、フルサイズの画像URLで上書きします。</p>
<p>詳しくは、<a href="https://notify-bot.line.me/doc/ja/">LINE Notify API Document</a>を参照ください。</p>
<p>エラーの場合、msg.payloadにはエラーメッセージが出力されます。</p>
</script>

<script type="text/x-red" data-help-name="line-notify">
Expand Down
40 changes: 31 additions & 9 deletions test/line-notify_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,32 @@ describe("Line Notify Node", () => {
helper.load(node, flow, {creds:{accessToken: "dummy"}}, () => {
const n1 = helper.getNode("n1");
n1.on("call:error", (err) => {
should.equal(err.lastArg.payload,"token is empty");
should.equal(err.lastArg.status,-1);
done();
});
n1.receive({});
});
});

it("error token", (done) => {
const flow = [
{ id: "n1", type: "line-notify", name: "test", message:"message test", creds: "creds", contentType: "message", wires:[["n2"]]},
{ id: "creds", type: "linetoken"},
{ id: "n2", type: "helper" }
];
helper.load(node, flow, {creds:{accessToken: "hoge"}},() => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n1.on("call:error", (err) => {
should.equal(err.lastArg.status,401);
should.equal(err.lastArg.payload, "Invalid access token");
done();
});
n1.receive({payload: "test"});
});
});

(process.env.GITHUB_ACTIONS ? describe.skip : describe)("should send returned message", () => {
const tests=[
{title:"send message" , flow: { id: "n1", type: "line-notify", name: "test", message:"message test", creds: "creds", contentType: "message", wires:[["n2"]]}},
Expand All @@ -63,7 +83,8 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
should.equal(msg.payload, "test");
done();
});
n1.on("call:error", (err) => {
Expand All @@ -86,7 +107,8 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
should.equal(msg.payload, "can overwrite");
});
n1.on("call:warn", (msg) => {
should.equal(msg.lastArg,"line-notify.warn.nooverride.message");
Expand All @@ -105,7 +127,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
done();
});
n1.receive({payload: "can overwrite"});
Expand All @@ -124,7 +146,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
});
n1.on("call:warn", (msg) => {
should.equal(msg.lastArg,"line-notify.warn.nooverride.imageUrl");
Expand Down Expand Up @@ -158,7 +180,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
done();
});
n1.receive({imageUrl: "https://dummyimage.com/640x640"});
Expand All @@ -177,7 +199,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
});
n1.on("call:warn", (msg) => {
should.equal(msg.lastArg,"line-notify.warn.nooverride.imageThumbnail");
Expand All @@ -196,7 +218,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
done();
});
n1.receive({imageThumbnail: "https://dummyimage.com/64x64"});
Expand Down Expand Up @@ -232,7 +254,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
done();
});
n1.receive({
Expand Down Expand Up @@ -271,7 +293,7 @@ describe("Line Notify Node", () => {
const n2 = helper.getNode("n2");
const n1 = helper.getNode("n1");
n2.on("input", (msg) => {
should.equal(msg.payload.status,200);
should.equal(msg.status,200);
done();
});
n1.receive({
Expand Down

0 comments on commit a644390

Please sign in to comment.