I am making LINE BOT with Bluemix and Nodejs, but I stumbled when I registered my IP in the whitelist on LINE side.
As for Bluemix, it seems that the IP changes with each deployment, so I tried to fix the IP pseudo using Statica using this article.
However, an error message such as 40403 error, Access to this API denied due to the following reason: Your ip address [XXX.XX.XXX.XXX] is not allowed to access this API. Please add your IP to the IP whitelist in the developer center. 」 returned and could not be sent.
The IP part was completely different from that of Statica.
The source code looks like the following:
I don't know much about the server, so I don't know what caused it at all.
How can I achieve static IP?
const express=require("express");
const bodyParser=require("body-parser")
const request=require("request")
const app=express();
const cfenv=require("cfenv");
constappEnv = cfenv.getAppEnv();
const ChannelAccessToken="ACCESS TOKEN"
const vcap_services=JSON.parse(process.env.VCAP_SERVICES);
const proxyURL=vcap_services["statica"][0].credentials.STATICA_URL;
app.use(bodyParser.urlencoded({
extended —true
}));
app.use(bodyParser.json())
app.use(express.static(__dirname+"/public"))
app.listen(appEnv.port, "0.0.0.0", function(){
console.log("AppLog:server starting on" + appEnv.url);
});
var heads = {
"Content-Type": "application/json; charset=UTF-8",
"Authorization": "Bearer {"+ChannelAccessToken+"}",
"User-Agent": "node.js"
}
app.post("/",(req,res)=>{
var events = req.body ["events" ]
var replyToken= events [0] [ "replyToken" ]
var type=events[0]["message"]["type"]
var replyText=""
if(type=="text"){
replyText=events[0]["message"]["text"]
console.log (replyText)
var body = {
"replyToken"—replyToken,
"messages": [{
"type": "text",
"text": "Reply Text"
}]
}
var options = {
url: "https://api.line.me/v2/bot/message/reply",
proxy —proxyURL,
headers —headers,
json —true,
body:body
}
request.post(options,(error, response, body)=>{
if(!error&response.statusCode==200){
console.log("AppLog:success")
}
else{
console.log("AppLog:"+response.statusCode+"error,"+response.body.message)
}
})
}
})
Statica is the only one that secures the IP to reach the server. It is separate from the IP of the server request.
IP address specification is optional in the Messaging API and does not necessarily need to be specified.
You can resolve the issue by removing the Server IP Whitelist configuration in the Developer Center and leaving it blank.
© 2024 OneMinuteCode. All rights reserved.