I'm trying to do a Alexa Skill, but she says There was a problem with the requested Skill's response

Viewed 31

i tested the command on cmd with console.log(lojaMensagem) and is working, but when i put on Alexa Skill it gives me a error, can you help me? And yes, i put the npm packages correctly! Sorry if the question is soo obvious, i'm new on Alexa Skills

const LojaDoDiaHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
        && Alexa.getIntentName(handlerInput.requestEnvelope) === 'LojaDoDia';
},
handle(handlerInput) {
    const { get } = require('axios');

    (async handle => {
        const itemsName = []

        const shop = await get(
            'https://fortniteapi.io/v2/shop?lang=pt-BR',
            { headers: { Authorization: 'my api key' } }
        )

    for (const item of shop.data.shop)
        itemsName.push(item.displayName)

    const lojaMensagem = `Os itens da loja de hoje são ${itemsName.join('. ')}`
    console.log(lojaMensagem)
    return handlerInput.responseBuilder
            .speak(lojaMensagem)
            .reprompt('') // Se eu quiser resposta
            .getResponse
    })()
    
}`
1 Answers

You return nothing from your handle method - you just call your function (return is inside of it), so then the handle method returns undefined and that's why you hear message about a problem with the response. Another problem is that you don't call getResponse function (missing ()).

BTW You can make the handle method async:

const LojaDoDiaHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
        && Alexa.getIntentName(handlerInput.requestEnvelope) === 'LojaDoDia';
},
async handle(handlerInput) {
    const { get } = require('axios');

    const itemsName = []

    const shop = await get(
        'https://fortniteapi.io/v2/shop?lang=pt-BR',
        { headers: { Authorization: 'my api key' } }
    )

    for (const item of shop.data.shop)
        itemsName.push(item.displayName)

    const lojaMensagem = `Os itens da loja de hoje são ${itemsName.join('. ')}`
    console.log(lojaMensagem)
    return handlerInput.responseBuilder
            .speak(lojaMensagem)
            .reprompt('') // Se eu quiser resposta
            .getResponse()
    
}
Related