Wikipedia API无法运行Alexa JavaScript

问题描述

我对亚马逊技能和JavaScript还是很陌生,我正尝试创建一种返回维基百科第一段的技能。我正在尝试使用Promise从外部api检索内容,但是似乎找不到我的问题。我也尝试过异步并等待,但是没有得到任何帮助。

这是我的代码

'''

const GetInfoIntentHandler = {
 canHandle(handlerInput) {
    return (
      handlerInput.requestEnvelope.request.type === "IntentRequest" &&
      handlerInput.requestEnvelope.request.intent.name === "GetInfoIntent"
    );
  },async handle(handlerInput) {
    let outputSpeech = 'This is the default message.';

    await getRemoteData("https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=god&origin=*&format=json")
      .then((response) => {
        const data = JSON.parse(response);
        outputSpeech = data;
      })
      .catch((err) => {
        console.log(`ERROR: ${err.message}`);
        // set an optional error message here
        outputSpeech = "hereeeee";
      });

    return handlerInput.responseBuilder
      .speak(outputSpeech)
      .getResponse();
  },};


const getRemoteData = (url) => new Promise((resolve,reject) => {
  const client = url.startsWith('https') ? require('https') : require('http');
  const request = client.get(url,(response) => {
    if (response.statusCode < 200 || response.statusCode > 299) {
      reject(new Error(`Failed with status code: ${response.statusCode}`));
    }
    const body = [];
    response.on('data',(chunk) => body.push(chunk));
  });
  //request.on('error',(err) => reject(err));
});

''' [我的错误] [1]

这是我正在使用的API:“ https://en.wikipedia.org/w/api.php?format=json&origin=*&action=query&prop=extracts&exlimit=max&explaintext&titles=” + query +“&redirects =”,

[我的构建] [2]

你能告诉我我要去哪里了吗 [1]:https://i.stack.imgur.com/Gvp2Q.png [2]:https://i.stack.imgur.com/bAvzR.png

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...