alexa-js/alexa-app

Chained callbacks not working.

pierluigizagaria opened this issue · 2 comments

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
    }
);

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?

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.