This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
kitchen-sink.ts
67 lines (62 loc) · 1.8 KB
/
kitchen-sink.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as Alexa from '../src/index'
type State = 'Started' | 'Other'
const routes: Alexa.Routes<State> = {
// Type-checked state management
InitialState: 'Started',
Launch: () =>
new Promise<Alexa.Response<State>>(resolve =>
resolve({
// Can return promises
Say: { Text: 'Hello world' }, // Low-ceremony responses
NewState: 'Other', // Changing the state as part of the response
}),
),
SessionEnded: () => {
console.log('Session ended')
},
Standard: {
// Support for built-in standard intents
Help: state => ({
Say: { SSML: '<speak> try saying <emphasis>hello</emphasis> </speak>' }, // Can also return synchronously or using SSML
}),
Stop: state => ({
Say: { Text: 'Bye!' },
EndSession: true, // Can end a session immediately (leaves open by default).
}),
},
Custom: [
[
'MyCustomIntent',
(state, slots) => ({
// Support for custom intents
Say: { Text: 'Something interesting' },
EndSession: true,
}),
],
],
}
const auth: Alexa.Pipe = (event, next) => {
// Define custom middleware for things like account linking
if (event.session.user.accessToken) {
// TODO: Perform custom authorisation
return next(event)
} else {
return Alexa.response({
Say: { Text: 'Please link your account to use this skill.' },
Card: { Type: 'LinkAccount' },
})
}
}
const unhandled: Alexa.Handler = event =>
Alexa.response({
// Default unhandled response
Say: { Text: "Sorry, I don't seem able to respond to that right now." },
EndSession: true,
})
export const handler = Alexa.Lambda.pipe([
// Host router as an AWS Lambda function
Alexa.Pipe.tracer(), // Log all requests + responses to the console
auth,
Alexa.Pipe.router(routes),
unhandled,
])