bespoken / virtual-alexa

:robot: Easily test and debug Alexa skills programmatically
https://bespoken.io
Apache License 2.0
112 stars 35 forks source link

session is undefined when using filter with addRequestInterceptors #100

Closed dgreene1 closed 5 years ago

dgreene1 commented 5 years ago

Description:

the filter method doesn't work with .addRequestInterceptors(theRequestInterceptor) as the replaced value of session is not set. Filter works fine for setting values that will appear in each intent handler (as recommended by the VirtualAlexa readme) but if I had to guess I would say that the "filtered value" is only passed through to the intent handlers and not to the interceptor.

Environment:

Steps To Reproduce

Steps to reproduce the behavior:

  1. set handlerInput.requestEnvelope.session.user.accessToken to a value by using filter
  2. utilize .addRequestInterceptors by passing in an object of type Alexa.RequestInterceptor as defined in ask-sdk
  3. set a breakpoint in that object's process method and check out what the value is

Expected behavior

The value set in filter will be the value that gets sent into the interceptor

Actual behavior

The value set in filter is undefined in the interceptor's process function

Code example

The interceptor

export const theRequestInterceptor : Alexa.RequestInterceptor = {
    async process(handlerInput : Alexa.HandlerInput) {
            const accessToken = handlerInput.requestEnvelope.session ? handlerInput.requestEnvelope.session.user.accessToken : undefined;
            debugger;
        }
    }
};

The code that uses it:

Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        ...allHandlers
    )
    .addRequestInterceptors(theRequestInterceptor)
    .addErrorHandlers(ErrorHandler)
    .lambda();

The test code:

            const utteranceResponse = await alexa
                .filter(requestJson => {
                    requestJson.session.user.accessToken = token2use;
                })
                .utter("help");
jperata commented 5 years ago

Hi @dgreene1, I tried reproducing the issue but in my case, the filter works correctly. alexaSDK2Interceptor.zip is the sample I used for my tests. After doing an npm install you can run node test/index.test.js and it should print in the console the values affected by the filter.

Can you verify if that scenario is what you have reported?, or if I skipped something you did?

dgreene1 commented 5 years ago

Thanks @jperata. I’ll try to reproduce my issue again. At the moment I cannot so I will close this issue. If it reoccurs for some reason, I will reopen the issue. Thank you for investigating.