Request failed with status code 400
Hi!
I have problem with the the error when response to user via client.replyMessage function
error logs : error log
Hello there,
I saw your log. It seems like server has given your reason but the response field is not detailed so please make the response more clearly as now its data is [Object].
And please don't paste the token in your log. Be careful with your secret key.
i will close this for now, since i can't reproduce the error. I think i will re-open if i get one. Thanks for response @xingoxu !
i got the error message : { message: 'Invalid reply token' }
@EriecTanijaya
I think it's not sdk's error so please confirm https://developers.line.biz/en/reference/messaging-api/#error-messages as 'Invalid reply token' means An invalid reply token was used in the reply message.
weird, cause how the replyToken in event object is invalid?
@EriecTanijaya Invalid replyToken may be caused in different cases. Check your replyToken is exactly equals the token you received and be sure that token should be only used once.
And if you believe it is sdk problem, paste your code and the repsonse and the request you sent at here. (Be careful of your private access token, you don't need to paste it here.)
this is the code to reply to user
replyText: function(texts = []) {
let state = this.group_session.state;
let time = this.group_session.time;
texts = Array.isArray(texts) ? texts : [texts];
if (state !== "idle" && state !== "new") {
if (time < 15) {
let reminder = "💡 ";
if (time < 1) {
reminder +=
"Waktu sudah habis, ketik '/check' untuk lanjutkan proses";
} else {
reminder +=
"Waktu tersisa " +
time +
" detik lagi, nanti ketik '/check' untuk lanjutkan proses";
}
texts.push(reminder);
}
}
return this.client
.replyMessage(
this.event.replyToken,
texts.map(text => ({
type: "text",
text: text.trim()
}))
)
.catch(err => {
console.log("err di replyText", err.originalError.response.data);
});
},
the error is not always occuring, it happens rarely though
@EriecTanijaya I see your code but I think there's no big problem.
Because the reply token becomes invalid after a certain period of time, responses should be sent as soon as a message is received. Reply tokens can only be used once. https://developers.line.biz/en/reference/messaging-api/#send-reply-message
Do you response the message immediately?
@xingoxu yes, im response the message immediately, but i think its because of replyMessage with wrong replyToken
@EriecTanijaya do your replyToken is exactly the same as the replyToken in webhook payload?
I can't see your other part of code. If it does, I would like you to see your request sent and the webhook payload. If they're the same, that's not sdk side problem but maybe a server problem.
What I can do is only instruct you to submit a problem. @tkgauri
i think its not the sdk problem, but the way i store the event from req.body.events data to 'this'. I think the the value in 'this' is replaced with other data when the request was made. so, before the this.event.replyToken used, the this.event.replyToken is replaced with other request.
Oh... Then it will be a Javascript problem. Sorry but would you please diagnose your code by yourself? I will close this issue for the moment.