Comments (7)
Okay, that does not surprise me - we don't handle typescript files at the moment - I guess we would need to auto-translate them to the js name?
Another alternative, which you may have already discovered, is that you can pass the lambda function itself to handler. Like this:
const myFunction = function(event: any, context: any) {
context.done(null, { custom: true });
};
const virtualAlexa = VirtualAlexa.Builder()
.handler(myFunction)
.interactionModelFile("models/en-US.json")
.create();
Perhaps that is a more elegant way to use it with TS.
from virtual-alexa.
I was able to work around this by wrapping my handlers in a js file, i.e. in my init.js
(not init.ts
) file
const handler = require('./src/index').handler;
exports.handler = handler;
and in my integration test file
alexa = new va.VirtualAlexaBuilder()
.handler('./init.handler')
.intentSchemaFile('./speechAssets/IntentSchema.json')
.sampleUtterancesFile('./speechAssets/SampleUtterances.txt')
.create();
I guess this is fine. You can close this issue if this is the behavior you want.
Also, weird little edge case I found while messing around with this. I thnk when you are getting the module in ModuleInvoked.js
, the way you are getting the file name is splitting on periods (.
)
static invokeHandler(handler, event) {
const handlerParts = handler.split(".");
const functionName = handlerParts[handlerParts.length - 1];
const fileName = handlerParts.slice(0, handlerParts.length - 1).join("/") + ".js";
const fullPath = path.join(process.cwd(), fileName);
const handlerModule = require(fullPath);
return ModuleInvoker.invokeFunction(handlerModule[functionName], event);
}
so I was unable to name my init file something like init.test.js
as I get error:
Cannot find module '/my-skill-folder/init/test.js' from 'ModuleInvoker.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
at Function.invokeHandler (node_modules/virtual-alexa/lib/src/ModuleInvoker.js:10:31)
at LocalSkillInteractor.invoke (node_modules/virtual-alexa/lib/src/LocalSkillInteractor.js:13:50)
at LocalSkillInteractor.<anonymous> (node_modules/virtual-alexa/lib/src/SkillInteractor.js:77:39)
not sure if you'd want to open up another issue about fixing that one as it's probably not too important
from virtual-alexa.
I don't see here how you were initially calling it that led to the issue, so I'm not sure what issue you are working around. Please provide a sample of the code that you are having trouble with when submitting issues.
And I do see lots of other code, just not the code that caused the issue (which makes it difficult to help).
from virtual-alexa.
Sorry I was all over the place. In typescript jest test:
beforeEach(async (done: jest.DoneCallback) => {
// the below file paths are relative to where package.json is for some reason
// maybe because it's where the test command is called...
server = new bst.LambdaServer('./init', 10000, true);
alexa = new va.VirtualAlexaBuilder()
.handler('./init.handler')
.interactionModelFile('./speechAssets/InteractionModel.json')
.sampleUtterancesFile('./speechAssets/SampleUtterances.txt')
.applicationID(constants.appId)
.create();
await server.start();
done();
});
Only works with a javascript init file. If I rename my init.js
file toinit.ts
and run my ts-jest suite I get the error I pasted above:
Cannot find module '/my-skill-folder/init.js' from 'ModuleInvoker.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
at Function.invokeHandler (node_modules/virtual-alexa/lib/src/ModuleInvoker.js:10:31)
at LocalSkillInteractor.invoke (node_modules/virtual-alexa/lib/src/LocalSkillInteractor.js:13:50)
at LocalSkillInteractor.<anonymous> (node_modules/virtual-alexa/lib/src/SkillInteractor.js:77:39)
The contents of my init
file (typescript or javascript) are the same in both cases
const handler = require('./src/index').handler;
exports.handler = handler;
Honestly, this is fine for me. I don't mind having the javascript file as long as the rest of my tests are in typescript. It's up to you if you'd like to keep this open.
The other issue I was talking about is naming the init file init.test.js
is not currently possible, but let's not worry about that.
from virtual-alexa.
Hi @CoreyCole - thanks for this info. With regard to this code:
alexa = new va.VirtualAlexaBuilder()
.handler('./init.handler')
.interactionModelFile('./speechAssets/InteractionModel.json')
.sampleUtterancesFile('./speechAssets/SampleUtterances.txt')
.applicationID(constants.appId)
.create();
The name of the handler should index.handler, where index is the name of the file (such as index.js) and handler is the function being called.
Now, what you may have run into - we have a bug with handling "." in the filenames. This has been fixed in the latest beta version (you can give it a try by installing virtual-alexa@beta). But if you stay with the current version, do not use a period in the name, so it would just be:
.handler("index.handler")
I hope that helps!
from virtual-alexa.
Right, the name of my file is init.js
and the above beforeEach
code works. The problem is that when I change the init file name to typescript and call it init.ts
is when it does not work.
Thanks for all the help by the way!
from virtual-alexa.
Yeah, it's definitely not a big deal. What was interesting is that the ts setup worked with BSTAlexa. The ts-jest preprocessing converts everything to js files before running, so I was assuming something weird was going on.
I had not discovered that, thanks for the help!
from virtual-alexa.
Related Issues (20)
- session is undefined when using filter with addRequestInterceptors HOT 2
- How to simulate a linked account? HOT 2
- Howto: use a locally hosted lambda HOT 2
- Do you interest to support Amazon Presentation Language? HOT 2
- Support DynamoDB.DeleteItem in DynamoDB.mock() HOT 1
- Testing AMAZON.FallbackIntent HOT 1
- request builder - confirm intent requires named dialog to exist
- Add mock for `getSystemTemperatureUnit` (`UpsServiceClient `)
- Dialog Manager- returns response with missing parameters HOT 3
- Unable to mock countryAndPostalCode call due to missing nock for Options call HOT 3
- Setting the Viewport in the context is not supported HOT 2
- Missing support for new built-in intent AMAZON.SelectIntent HOT 5
- Ensure additional elements do not appear in generated docs HOT 1
- Incorrect type interface for IResponse HOT 7
- Dialog slot confirmation, documentation needed HOT 6
- sdk.emit(":tell", ...) doesn't end the session HOT 3
- Alexa code in Google Cloud HOT 2
- AlexaSkill ID verification failed. HOT 2
- Throws an error as elicitSlot when the invoking intent is not associated
- Dialog Flow broken HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from virtual-alexa.