Skip to content

Commit ec8f828

Browse files
committed
[BUG] fix headerParams
1 parent 6b2eb61 commit ec8f828

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

generator/src/main/resources/line-bot-sdk-nodejs-generator/apiBody/normal.pebble

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"{{param.paramName}}": {{param.paramName}},
1919
{% endfor %}
2020
};
21-
{% elseif op.hasHeaderParams %}const headerParams = {
21+
{% endif %}
22+
{% if op.hasHeaderParams %}const headerParams = {
2223
{% for param in op.headerParams -%}
2324
"{{param.baseName}}": {{param.paramName}},
2425
{% endfor %}
@@ -31,10 +32,10 @@
3132
.replace("{{ "{" + param.paramName + "}" }}", String({{ param.paramName }}))
3233
{% endfor %},
3334

34-
{% if op.hasBodyParam %}params,{% endif %}
35-
{% if op.hasFormParams %}formParams,{% endif %}
36-
{% if op.hasQueryParams %}queryParams,{% endif %}
37-
{% if op.hasHeaderParams %}headerParams,{% endif %}
35+
{% if op.hasBodyParam %}params,
36+
{% elseif op.hasFormParams %}formParams,
37+
{% elseif op.hasQueryParams %}queryParams,{% endif %}
38+
{% if op.hasHeaderParams %}{headers: headerParams},{% endif %}
3839
);
3940
return ensureJSON(res);
4041
{% endif %}

lib/messaging-api/api/messagingApiClient.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,15 @@ export class MessagingApiClient {
128128
): Promise<object> {
129129
const params = broadcastRequest;
130130

131+
const headerParams = {
132+
"X-Line-Retry-Key": xLineRetryKey,
133+
};
134+
131135
const res = this.httpClient.post<object>(
132136
"/v2/bot/message/broadcast",
133137
params,
134138

135-
headerParams,
139+
{ headers: headerParams },
136140
);
137141
return ensureJSON(res);
138142
}
@@ -779,11 +783,15 @@ export class MessagingApiClient {
779783
): Promise<object> {
780784
const params = multicastRequest;
781785

786+
const headerParams = {
787+
"X-Line-Retry-Key": xLineRetryKey,
788+
};
789+
782790
const res = this.httpClient.post<object>(
783791
"/v2/bot/message/multicast",
784792
params,
785793

786-
headerParams,
794+
{ headers: headerParams },
787795
);
788796
return ensureJSON(res);
789797
}
@@ -800,11 +808,15 @@ export class MessagingApiClient {
800808
): Promise<object> {
801809
const params = narrowcastRequest;
802810

811+
const headerParams = {
812+
"X-Line-Retry-Key": xLineRetryKey,
813+
};
814+
803815
const res = this.httpClient.post<object>(
804816
"/v2/bot/message/narrowcast",
805817
params,
806818

807-
headerParams,
819+
{ headers: headerParams },
808820
);
809821
return ensureJSON(res);
810822
}
@@ -821,11 +833,15 @@ export class MessagingApiClient {
821833
): Promise<PushMessageResponse> {
822834
const params = pushMessageRequest;
823835

836+
const headerParams = {
837+
"X-Line-Retry-Key": xLineRetryKey,
838+
};
839+
824840
const res = this.httpClient.post<PushMessageResponse>(
825841
"/v2/bot/message/push",
826842
params,
827843

828-
headerParams,
844+
{ headers: headerParams },
829845
);
830846
return ensureJSON(res);
831847
}
@@ -842,11 +858,15 @@ export class MessagingApiClient {
842858
): Promise<Types.MessageAPIResponseBase> {
843859
const params = pnpMessagesRequest;
844860

861+
const headerParams = {
862+
"X-Line-Delivery-Tag": xLineDeliveryTag,
863+
};
864+
845865
const res = this.httpClient.post(
846866
"/bot/pnp/push",
847867
params,
848868

849-
headerParams,
869+
{ headers: headerParams },
850870
);
851871
return ensureJSON(res);
852872
}

test/libs-messagingApi.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,24 @@ describe("messagingApi", () => {
3737
equal(scope.isDone(), true);
3838
deepEqual(res, {});
3939
});
40+
41+
it("pushMessage", async () => {
42+
const scope = nock("https://api.line.me/", {
43+
reqheaders: {
44+
Authorization: "Bearer test_channel_access_token",
45+
"User-Agent": `${pkg.name}/${pkg.version}`,
46+
"content-type": "application/json",
47+
"x-line-retry-key": "KEYKEYKEYKEY",
48+
},
49+
})
50+
.post("/v2/bot/message/push")
51+
.reply(200, {});
52+
53+
const res = await client.pushMessage(
54+
{ to: "uAAAAAAAAAAAAAA", messages: [{ type: "text", text: "aaaaaa" }] },
55+
"KEYKEYKEYKEY",
56+
);
57+
equal(scope.isDone(), true);
58+
deepEqual(res, {});
59+
});
4060
});

0 commit comments

Comments
 (0)