Skip to content

Commit

Permalink
feat: init talkyjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidetaka Okamoto committed Jul 6, 2020
1 parent 664b5e0 commit 63e8727
Show file tree
Hide file tree
Showing 22 changed files with 564 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
package-lock.json
.DS_Store
.ask/
build/
build/
dist/
60 changes: 45 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,61 @@ Please follow the wizard to start your Alexa skill project ->
? Please type in your skill name: alexa-skill-sample-helloworld-typescript
? Please type in your folder name for the skill project (alphanumeric): alexa-skill-sample-helloworld-typescript
% tree alexa-skill-sample-helloworld-typescript -L 3 -I node_modules
alexa-skill-sample-helloworld-typescript
% tree alexa-skill-sample-helloworld-typescript -I node_modules
.
├── LICENSE.txt
├── README.md
├── ask-resources.json
├── hooks
└── build.sh
   └── build.sh
├── infrastructure
│ └── cfn-deployer
│ └── skill-stack.yaml
│   └── lambda-deployer
├── lambda
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ │ └── util.ts
│ ├── tsconfig.json
│ └── webpack.config.ts
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── src
│   │   ├── HelpIntent
│   │   │   ├── HelpIntent.router.ts
│   │   │   ├── HelpIntent.speech.tsx
│   │   │   └── tests
│   │   │   ├── HelpIntent.router.spec.ts
│   │   │   └── HelpIntent.speech.spec.tsx
│   │   ├── LaunchRequest
│   │   │   ├── LaunchRequest.router.ts
│   │   │   ├── LaunchRequest.speech.tsx
│   │   │   └── tests
│   │   │   ├── LaunchRequest.router.spec.ts
│   │   │   └── LaunchRequest.speech.spec.tsx
│   │   ├── StopAndCancelAndNoIntent
│   │   │   ├── StopAndCancelAndNoIntent.router.ts
│   │   │   ├── StopAndCancelAndNoIntent.speech.tsx
│   │   │   └── tests
│   │   │   ├── StopAndCancelAndNoIntent.router.spec.ts
│   │   │   └── StopAndCancelAndNoIntent.speech.spec.tsx
│   │   ├── index.ts
│   │   └── tests
│   │   └── index.spec.ts
│   ├── tsconfig.json
│   └── webpack.config.ts
└── skill-package
├── assets
├── en-US_largeIcon.png
└── en-US_smallIcon.png
   ├── en-US_largeIcon.png
   └── en-US_smallIcon.png
├── interactionModels
│ └── custom
│   └── custom
│   └── en-US.json
└── skill.json
9 directories, 12 files
16 directories, 27 files
```

## [Optional] Manually setup

```bash
$ rm -rf lambda/*
$ npx @talkyjs/cli new --path lambda --database=dynamodb --controller=handler --ssml=default --no-test
```

## Deployment
Expand Down
2 changes: 1 addition & 1 deletion ask-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"skillInfrastructure": {
"userConfig": {
"runtime": "nodejs12.x",
"handler": "build/index.handler",
"handler": "dist/index.handler",
"awsRegion": "us-east-1"
},
"type": "@ask-cli/lambda-deployer"
Expand Down
21 changes: 21 additions & 0 deletions lambda/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# package directories
node_modules
jspm_packages

# Serverless directories
.serverless

# Webpack directories
.webpack
.envrc

# Build files
dist/
build/

# ASK CLI files
.ask/lambda

# Misc
.DS_Store
24 changes: 24 additions & 0 deletions lambda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Alexa skill functions

## Development

### Unit test

```bash
$ yarn test

# Watch mode
$ yarn test:dev
```

### Build code

We have to build the project before deploy to AWS Lambda

```
$ yarn build
```

### Lambda entrypoint
By the default, the Lambda function information is in `./dist/index.js`.
And the handler name is `handler`.
62 changes: 62 additions & 0 deletions lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "hello-world",
"version": "0.0.0",
"description": "alexa utility for quickly building skills",
"main": "/index.js",
"scripts": {
"build": "webpack",
"test": "jest",
"test:watch": "jest --watch",
"test:dev": "jest --watch --silent=false --verbose false --coverage"
},
"author": "TalkyJS team",
"license": "MIT",
"dependencies": {
"@talkyjs/core": "0.x",
"@ask-utils/router": "3.x",
"@ask-utils/speech-script": "3.x",
"ask-sdk-core": "^2.6.0",
"ask-sdk-model": "^1.18.0"
},
"directories": {
"lib": "src",
"test": "tests"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"tsx",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.(ts|tsx)$",
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
}
}
},
"devDependencies": {
"@ask-utils/test": "3.x",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.5",
"@types/webpack": "^4.41.12",
"jest": "^26.0.1",
"source-map-support": "^0.5.19",
"ts-jest": "^25.5.1",
"ts-loader": "^7.0.2",
"ts-node": "^8.10.1",
"typescript": "^3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
}
}
21 changes: 21 additions & 0 deletions lambda/src/HelpIntent/HelpIntent.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Router } from "@ask-utils/router";

import { HelpIntentScript } from './HelpIntent.speech'


export const HelpIntentRouter: Router = {
requestType: "IntentRequest",
intentName: "AMAZON.HelpIntent",
handler: async (handlerInput) => {


const script = new HelpIntentScript(handlerInput)
return script
.createResponseBuilder()
.getResponse();


}
}

export default HelpIntentRouter
24 changes: 24 additions & 0 deletions lambda/src/HelpIntent/HelpIntent.speech.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @jsx ssml */
import {
ssml,
SpeechScriptJSX,
} from '@ask-utils/speech-script'

export class HelpIntentScript extends SpeechScriptJSX {
speech() {
return (
<speak>
<p>Hello! It's a nice development. How are you?</p>
</speak>
)
}

reprompt() {
return (
<speak>
<p>How are you?</p>
</speak>
)
}

}
32 changes: 32 additions & 0 deletions lambda/src/HelpIntent/tests/HelpIntent.router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { HandlerInputCreator } from '@ask-utils/test';
import { RequestHandlerFactory } from '@ask-utils/router';
import { RequestHandler } from 'ask-sdk-core';
import { HelpIntentRouter } from '../HelpIntent.router'

describe('HelpIntentRouter', () => {
let handler: RequestHandler;
beforeEach(() => {
handler = RequestHandlerFactory.create(HelpIntentRouter);
});
describe('canHandle', () => {
it('should return false when given a not LaunchRequest', async () => {
const handlerInput = new HandlerInputCreator().createLaunchRequest();
await expect(handler.canHandle(handlerInput)).resolves.toEqual(false);
});

it('should return false when given a not IntentRequest', async () => {
const handlerInput = new HandlerInputCreator().createIntentRequest({
name: "AMAZON.HelpIntent",
confirmationStatus: 'NONE'
});
await expect(handler.canHandle(handlerInput)).resolves.toMatchSnapshot();
});

});
describe('handle', () => {
it('should match snapshot', async () => {
const handlerInput = new HandlerInputCreator().createLaunchRequest();
await expect(handler.handle(handlerInput)).resolves.toMatchSnapshot();
});
});
});
15 changes: 15 additions & 0 deletions lambda/src/HelpIntent/tests/HelpIntent.speech.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HandlerInputCreator } from '@ask-utils/test';
import { HelpIntentScript } from '../HelpIntent.speech'

describe('HelpIntentScript', () => {

it('should return false when given a not IntentRequest', async () => {
const handlerInput = new HandlerInputCreator().createIntentRequest({
name: "AMAZON.HelpIntent",
confirmationStatus: 'NONE'
});
const script = new HelpIntentScript(handlerInput);
expect(script.createResponse()).toMatchSnapshot();
});

});
21 changes: 21 additions & 0 deletions lambda/src/LaunchRequest/LaunchRequest.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Router } from "@ask-utils/router";

import { LaunchRequestScript } from './LaunchRequest.speech'


export const LaunchRequestRouter: Router = {
requestType: "LaunchRequest",

handler: async (handlerInput) => {


const script = new LaunchRequestScript(handlerInput)
return script
.createResponseBuilder()
.getResponse();


}
}

export default LaunchRequestRouter
24 changes: 24 additions & 0 deletions lambda/src/LaunchRequest/LaunchRequest.speech.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @jsx ssml */
import {
ssml,
SpeechScriptJSX,
} from '@ask-utils/speech-script'

export class LaunchRequestScript extends SpeechScriptJSX {
speech() {
return (
<speak>
<p>Hello! It's a nice development. How are you?</p>
</speak>
)
}

reprompt() {
return (
<speak>
<p>How are you?</p>
</speak>
)
}

}
32 changes: 32 additions & 0 deletions lambda/src/LaunchRequest/tests/LaunchRequest.router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { HandlerInputCreator } from '@ask-utils/test';
import { RequestHandlerFactory } from '@ask-utils/router';
import { RequestHandler } from 'ask-sdk-core';
import { LaunchRequestRouter } from '../LaunchRequest.router'

describe('LaunchRequestRouter', () => {
let handler: RequestHandler;
beforeEach(() => {
handler = RequestHandlerFactory.create(LaunchRequestRouter);
});
describe('canHandle', () => {
it('should return false when given a not LaunchRequest', async () => {
const handlerInput = new HandlerInputCreator().createLaunchRequest();
await expect(handler.canHandle(handlerInput)).resolves.toEqual(true);
});

it('should return false when given a not IntentRequest', async () => {
const handlerInput = new HandlerInputCreator().createIntentRequest({
name: "LaunchRequest",
confirmationStatus: 'NONE'
});
await expect(handler.canHandle(handlerInput)).resolves.toMatchSnapshot();
});

});
describe('handle', () => {
it('should match snapshot', async () => {
const handlerInput = new HandlerInputCreator().createLaunchRequest();
await expect(handler.handle(handlerInput)).resolves.toMatchSnapshot();
});
});
});
Loading

0 comments on commit 63e8727

Please sign in to comment.