Ошибка обработчика: «Для события GreetMeIntent не определена функция обработчика и не определена функция« Необработанный ».» ALEXA - PullRequest
0 голосов
/ 21 февраля 2020

это ошибка, которая выводится, когда я пытаюсь проверить обработчик. Но, к сожалению, я не могу это исправить. Можете ли вы мне помочь? "errorMessage": "В состоянии:. Для события GreetMeIntent не определена никакая функция-обработчик и не была определена функция" Необработанная ".", "trace": ["Ошибка: В состоянии:. Для события GreetMeIntent не определена никакая функция-обработчик «Необработанная» функция была определена. /node_modules/alexa-sdk/lib/alexa.js:181:23) "," в AlexaRequestEmitter.HandleLambdaEvent (/var/task/node_modules/alexa-sdk/lib/alexa.js:126:25) "," в AlexaRequestEmitter.value (/var/task/node_modules/alexa-sdk/lib/alexa.js:100:31) "," в Runtime.exports.handler (/var/task/index.js: 393: 11) "," в Runtime.handleOnce (/var/runtime/Runtime.js:66:25) "]}

const alexa_info = require('ask-sdk-core');
  const LaunchRequest = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
      return handlerInput.responseBuilder.speak(messages.WELCOME)
          .reprompt(messages.HELP)        
          .reprompt(messages.WHAT_DO_YOU_WANT)
          .getResponse();
    },
  };
  //per Accesso ai dati 1.0
  const LaunchRequestHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
      const speechText = messages.WELCOME;
      const reprompt = messages.WHAT_DO_YOU_WANT;

      return handlerInput.responseBuilder
        .speak(speechText)
        .reprompt(reprompt)
        .withSimpleCard(APP_NAME, speechText)
        .getResponse();
    },
  };

  //per accesso ai dati 1.1
  const GreetMeIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'GreetMeIntent';
    },
    async handle(handlerInput) {
      const { serviceClientFactory, responseBuilder } = handlerInput;
      try {
        const upsServiceClient = serviceClientFactory.getUpsServiceClient();
        const profileName = await upsServiceClient.getProfileName();
        const speechResponse = messages.NAME_AVAILABLE + profileName;
        return responseBuilder
                        .speak(speechResponse)
                        .withSimpleCard(APP_NAME, speechResponse)
                        .getResponse();
      } catch (error) {
        console.log(JSON.stringify(error));
        if (error.statusCode == 403) {
          return responseBuilder
          .speak(messages.NOTIFY_MISSING_PERMISSIONS)
          .withAskForPermissionsConsentCard([FULL_NAME_PERMISSION])   
          .getResponse();
        }
        console.log(JSON.stringify(error));
        const response = responseBuilder.speak(messages.ERROR).getResponse();
        return response;
      }
    },
  };

  //Accesso ai dati 1.2
  const EmailIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'EmailIntent';
    },
    async handle(handlerInput) {
      const { serviceClientFactory, responseBuilder } = handlerInput;
      try {
        const upsServiceClient = serviceClientFactory.getUpsServiceClient();
        const profileEmail = await upsServiceClient.getProfileEmail();
        if (!profileEmail) {
          const noEmailResponse = messages.EMAIL_MISSING;
          return responseBuilder
                        .speak(noEmailResponse)
                        .withSimpleCard(APP_NAME, noEmailResponse)
                        .getResponse();
        }
        const speechResponse = messages.EMAIL_AVAILABLE + profileEmail;
        return responseBuilder
                        .speak(speechResponse)
                        .withSimpleCard(APP_NAME, speechResponse)
                        .getResponse();
      } catch (error) {
        console.log(JSON.stringify(error));
        if (error.statusCode == 403) {
          return responseBuilder
          .speak(messages.NOTIFY_MISSING_PERMISSIONS)
          .withAskForPermissionsConsentCard([EMAIL_PERMISSION])  
          .getResponse();
        }
        console.log(JSON.stringify(error));
        const response = responseBuilder.speak(messages.ERROR).getResponse();
        return response;
      }
    },
  };
  //Accesso ai dati 1.3
  const MobileIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'MobileIntent';
    },
    async handle(handlerInput) {
      const { serviceClientFactory, responseBuilder } = handlerInput;
      try {
        const upsServiceClient = serviceClientFactory.getUpsServiceClient();
        const profileMobileObject = await upsServiceClient.getProfileMobileNumber();
        if (!profileMobileObject) {
          const errorResponse = messages.NUMBER_MISSING;
          return responseBuilder
                        .speak(errorResponse)
                        .withSimpleCard(APP_NAME, errorResponse)
                        .getResponse();
        }
        const profileMobile = profileMobileObject.phoneNumber;
        const speechResponse = messages.NUMBER_AVAILABLE+ profileMobile;//<say-as interpret-as="telephone">profileMobile</say-as>;
        const cardResponse = messages.NUMBER_AVAILABLE+ profileMobile;
        return responseBuilder
                        .speak(speechResponse)
                        .withSimpleCard(APP_NAME, cardResponse)
                        .getResponse();
      } catch (error) {
        console.log(JSON.stringify(error));
        if (error.statusCode == 403) {
          return responseBuilder
          .speak(messages.NOTIFY_MISSING_PERMISSIONS)
          .withAskForPermissionsConsentCard([MOBILE_PERMISSION]) 
          .getResponse();
        }
        console.log(JSON.stringify(error));
        const response = responseBuilder.speak(messages.ERROR).getResponse();
        return response;
      }
    },
  };
  const HelpIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
    },
    handle(handlerInput) {
      const speechText = messages.HELP_MESSAGE;

      return handlerInput.responseBuilder
        .speak(speechText)
        .reprompt(speechText)
        .withSimpleCard('Buongiorno, ', speechText)
        .getResponse();
    },
  };

  const CancelAndStopIntentHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
          || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
    },
    handle(handlerInput) {
      const speechText = messages.GOODBYE;

      return handlerInput.responseBuilder
        .speak(speechText)
        .getResponse();
    },
  };

  const SessionEndedRequestHandler = {
    canHandle(handlerInput) {
      return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
    },
    handle(handlerInput) {
      console.log('Sessione terminata per la seguente ragione: ' + handlerInput.requestEnvelope.request.reason);

      return handlerInput.responseBuilder.getResponse();
    },
  };

  const ErrorHandler = {
    canHandle() {
      return true;
    },
    handle(handlerInput, error) {
      console.log('Errore Handle:'+error.message);

      return handlerInput.responseBuilder
        .speak(messages.UNHANDLED)
        .reprompt(messages.UNHANDLED)
        .getResponse();
    },
  };

  const RequestLog = {
    process(handlerInput) {
      console.log('Richiesta :'+ JSON.stringify(handlerInput.requestEnvelope));
    },
  };

  const ResponseLog = {
    process(handlerInput) {
      console.log('Costruttore risposta: '+JSON.stringify(handlerInput));
    },
  };
exports.handler = alexa_info.SkillBuilders.custom()
  .addRequestHandlers(
    LaunchRequest,
    LaunchRequestHandler,
    GreetMeIntentHandler,
    EmailIntentHandler,
    MobileIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
    )
    .addRequestInterceptors(RequestLog)
    .addResponseInterceptors(ResponseLog)
    .addErrorHandlers(ErrorHandler)
    .withApiClient(new alexa_info.DefaultApiClient())
    .lambda();

/*    
    exports.handler = (event, context) => {
        const alexa = Alexa.handler(event, context);
        alexa.APP_ID = APP_ID;
        alexa.registerHandlers(handlers);
        alexa.execute();
    };

*/
...