Line webhook 未以编程方式激活

问题描述 投票:0回答:1

我正在尝试通过通道访问令牌以编程方式将 webhook 添加到线路。我的代码将 webhook 设置为 line,但 webhook 确实已启用。

下面是我的代码:

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);
  }
}

但是当我点击下面的 api 时,它给出的响应表明 webhook 已设置但未启用。

const verifyResult = await axios.get(
  "https://api.line.me/v2/bot/channel/webhook/endpoint",
  config
);

以下是回复:

{
    "endpoint": "https://1f29-45-248-162-227.ngrok-free.app/line/webhook",
    "active": false
}

任何人有任何想法,如何解决它,任何小的帮助将不胜感激!!!

我尝试在设置 webhook 时传递enable:true,但这也不起作用。有人可以帮忙吗?

node.js api line webhooks line-api
1个回答
0
投票

创建后您必须验证 webhook url。

可以通过两种方式完成,

  1. 使用axios
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'
        }
    }
);
  1. 使用 LINE Developers Console,单击 webhook URL 的验证按钮以执行验证。

enter image description here

LINE Doc 用于验证 webhook url

© www.soinside.com 2019 - 2024. All rights reserved.