Reputation: 1
i am trying to add webhook to line programatically via channel access token. My code sets the webhook to line, but the webhook does gets enabled.
Below is my code for it:
async function setWebhook(channelAccessToken) {
const config = {
headers: {
"Content-Type": "application/json",
"x-line-signature": "2e7306a15c5c775341f003d65fe62d72",
Authorization: `Bearer ${channelAccessToken}`,
},
};
const data = {
endpoint: `${baseUrl}/line/webhook`
};
try {
const result = await axios.put(
"https://api.line.me/v2/bot/channel/webhook/endpoint",
data,
config
);
console.log("result.data ============= ", result.data);
return result;
} catch (error) {
// console.log("tester ========== ", error)
throw new Error("Error setting webhook: " + error.message);
}
}
But when i hit the below api, it gives response which shows that webhook is set but not enabled.
const verifyResult = await axios.get(
"https://api.line.me/v2/bot/channel/webhook/endpoint",
config
);
Below is the response:
{
"endpoint": "https://1f29-45-248-162-227.ngrok-free.app/line/webhook",
"active": false
}
Do anyone have any idea, how to solve it, any small help will be really appreciated !!!
I have tried to pass enable:true while setting up the webhook, but that also didn't worked. Can somebody help?
Upvotes: 0
Views: 266
Reputation: 2668
A wild guess, maybe you did not enable the webhook by clicking Use Webhook
see here?:
Upvotes: 0
Reputation: 4608
You have to verify the webhook url after creating.
It can be done in two ways,
const response = await axios.post(
'https://api.line.me/v2/bot/channel/webhook/test',
{
endpoint: `${baseUrl}/line/webhook`
},
{
headers: {
Authorization: 'Bearer {CHANNEL_ACCESS_TOKEN}',
'Content-Type': 'application/json'
}
}
);
LINE Doc for verifying webhook url
Upvotes: 0