Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?

Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?

我有一个函数 returns Promise

  function superHero_with_name (name) {
    return new Promise((resolve, reject) => {
        var encoded_superhero_name = name.split(" ").join("%20");
        var path_superhero = '/api.php/' + superhero_access_token + '/search/' + encoded_superhero_name ;
        console.log('API Request: ' + host_superhero + path_superhero);

        http.get({host: host_superhero, path: path_superhero}, (res) => {
            let body = '';
            res.on('data', (d) => { body += d;});
            res.on('end', () => {
                // console.log("BODY:", body);
                let output = JSON.parse(body);
                resolve(output);

            });
            res.on('error', (error) => {
                console.log(`Error while calling the API ${error}` );
            });
        });
    });
  }

我正在使用 Actions SDK,调用这个函数后抛给我的错误是

No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?

我调用这个函数的函数是

  superhero.intent('superherocard', (conv, {superhero_entity}) => {
    superHero_with_name(superhero_entity).then((output)=>{
        if(output.response === 'success'){
            var super_name = output.results[0].name ;

            // Assigned values to all the variables used below this comment

            conv.ask("Here's your Superhero");
            conv.ask(new BasicCard({
                text: `Your SuperHero is the mighty **${super_name}**.  \n**INTELLIGENCE** *${intelligence}*  \n**STRENGTH** *${strength}*  \n**SPEED** *${speed}*  \n**DURABILITY** *${durability}*  \n**POWER** *${power}*  \n**COMBAT** *${combat}*`,
                title: super_name,
                subtitle: super_publisher,
                image: new Image({
                    url: image_superhero,
                    alt: super_name,
                }),
            }));

            conv.ask(text_1);

            conv.ask(new Suggestions(itemSuggestions));

        } else{
            conv.ask('Sorry, I cannot find the superhero you are finding! But you can become one by helping and motivating people.');
        }
        return console.log("superHeroCard executed");
    }).catch(()=> {
        conv.ask('Sorry, I cannot find the superhero you are finding! But you can become one by helping and motivating people.');
    });
  });

我在返回 Promise 时找不到错误,但意图处理程序无法读取它。

问题是 Intent Handler 正在 读取它,但它不是 returning 它。

如果您正在进行异步调用,您的处理程序 必须 return 一个将在异步部分完成时解析的 Promise。如果您不进行异步调用,那么您不需要 return 承诺 - 因为处理程序调度程序在发送回回复之前不需要等待任何事情。如果您正在进行异步调用,Promise 会向调度程序指示它需要等待 Promise 完全解析才能 return 您设置的响应。

在您的情况下,您可以将处理程序的前两行调整为 return 由函数调用和 then() 链 return 编辑的 Promise。可能是这样的:

superhero.intent('superherocard', (conv, {superhero_entity}) => {
  return superHero_with_name(superhero_entity).then((output)=>{
    // ...