alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

Chained callbacks not working. #400

Closed pierluigizagaria closed 4 years ago

pierluigizagaria commented 4 years ago

Hi, can anyone help me with this cose?

I'm tried to return false or return the promise from the ytdl.getInfo promise but nothing works.

With this return false alexa returns me an error.

app.intent("PlayIntent", {
    "slots": { "query": "AMAZON.SearchQuery" },
    }, (request, response) => {
        var searchQuery = request.slot("query");
        ytsr(searchQuery, { limit: 1 }, (err, queryResults) => {
            if (err) throw err
            let videoTitle = queryResults[0].title
            let videoLink = queryResults[0].link
            console.log(`Found video: ${videoTitle}`)
            response.say(`Riproduco ${videoTitle}`);
            ytdl.getInfo(videoLink, (err, videoInfo) => {
                if (err) throw err
                let audioInfo = ytdl.chooseFormat(videoInfo.formats, { quality: 'highestaudio' });
                if (audioInfo) {
                    console.log(`Found audio stream link: ${audioInfo.url}`)
                    response.send();
                }
            });
        })
        return false
    }
);
dblock commented 4 years ago

You should be returning a promise. The code above does not. Make the changes and edit/update. Double check that it returns a promise from all paths.

Define "nothing works", too?

pierluigizagaria commented 4 years ago

You should be returning a promise. The code above does not. Make the changes and edit/update. Double check that it returns a promise from all paths.

Define "nothing works", too?

I know, my question was very horrible. I was frustrated but yhea, I've declared and returned a promise and now everything works.