Botpress-我想调用外部API,但我不知道我必须将代码粘贴到哪个文件中

时间:2019-02-05 07:53:14

标签: axios

我引用了以下代码来在botpress社区版中调用外部API,但是我想知道我需要在哪个文件中添加此代码。谁能建议我该怎么做?

以下是我要添加到botpress中但不知道粘贴位置的代码。

  repoStarsByInput: async (state, event) => {
  const endPoint = 'https://api.github.com/repos'
  try {
    const { data: { stargazers_count } } = await axios.get(`${endPoint}/${event.text}`)
    await event.reply('#builtin_text', { text: `This repo has ${stargazers_count} ★` })
  } catch (e) {
    await event.reply('#builtin_text', { text: `Failed to fetch data for this repo` })
  }
}

0 个答案:

没有答案