首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何在Alan AI项目中删除我的错误?

我如何在Alan AI项目中删除我的错误?
EN

Stack Overflow用户
提问于 2021-04-26 13:02:15
回答 1查看 36关注 0票数 1

我正在尝试建立一个语音助理新闻应用程序使用艾伦人工智能。在我的代码中,我使用了newsapi.org API。当我尝试执行代码时,它显示了2个错误。"uncaught user exception“和"Cannot read property 'length' of undefined”。如果可能的话,请大家帮助一下如何摆脱这个错误。这是我的代码

代码语言:javascript
复制
intent('What does this app do?', 'What can I do here?', 
    reply('This is a news project.'));

const API_KEY = 'e1f728171ee54ccd861576421b6a9fbc';
let savedArticles = [];

intent('Give me the news from $(source* (.*))', (p) => {
    let NEWS_API_URL = `https://newsapi.org/v2/top-headlines?apiKey=${API_KEY}`;

    if(p.source.value){
        NEWS_API_URL = `${NEWS_API_URL}&sources=${p.source.value.toLowerCase().split(" ").join('-')}`
    }
  
    api.request(NEWS_API_URL, (error, response, body) => {
        const  {articles}  = JSON.parse(body);
     
        if(!articles.length) {
            p.play('Sorry, please try searching for news from a different source');
            return;
        }
        
        savedArticles = articles;
        
        p.play({ command: 'newHeadlines', articles });
        p.play(`Here are the (latest|recent) ${p.source.value}.`);
    
    });
})
EN

回答 1

Stack Overflow用户

发布于 2021-10-16 04:14:09

我最近才了解到这一点,问题是,当你试图从CNN或ESPN (没有"-“连字符符号的单词)中调用新闻时,它会显示未定义,

尝试先拨打BBC-news或ABC-news,然后再拨打CNN或任何其他新闻提要,这对我很管用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67261081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档