Skip to content

Commit 5bf1863

Browse files
committed
New types for alexa skills and alexa smarthome events. Adding cloudwatch logs as well.
1 parent eeb41b0 commit 5bf1863

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

globals.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,72 @@ declare module '*.json' {
22
const value: any
33
export default value
44
}
5+
6+
export interface AlexaSmartHomeEvent {
7+
header: { [name: string]: string },
8+
payload: {
9+
switchControlAction: string,
10+
appliance: {
11+
additionalApplianceDetails: { [name: string]: string },
12+
applianceId: string,
13+
},
14+
accessToken: string
15+
}
16+
}
17+
18+
export interface AlexaSkillEvent {
19+
version: string,
20+
session: AlexaSkillSession,
21+
context: AlexaSkillContext,
22+
23+
24+
}
25+
26+
export interface AlexaSkillSession {
27+
new: boolean,
28+
sessionId: string,
29+
application: {
30+
applicationId: string
31+
},
32+
attributes: {
33+
[name: string]: string
34+
},
35+
user: AlexaSkillUser
36+
}
37+
38+
export interface AlexaSkillContext {
39+
System: {
40+
device: {
41+
deviceId: string,
42+
supportedInterfaces: {
43+
AudioPlayer: any
44+
}
45+
},
46+
application: {
47+
applicationId: string
48+
},
49+
user: AlexaSkillUser,
50+
apiEndpoint: string,
51+
apiAccessToken: string
52+
},
53+
AudioPlayer: {
54+
playerActivity: string,
55+
token: string,
56+
offsetInMilliseconds: number,
57+
}
58+
}
59+
60+
export interface AlexaSkillUser {
61+
userId: string,
62+
accessToken: string,
63+
permissions: {
64+
consentToken: string
65+
}
66+
}
67+
68+
export interface AlexaSkillRequest {
69+
type: string,
70+
requestId: string,
71+
timestamp: string,
72+
locale: string,
73+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"version": "1.0",
3+
"session": {
4+
"new": true,
5+
"sessionId": "amzn1.echo-api.session.[unique-value-here]",
6+
"application": {
7+
"applicationId": "amzn1.ask.skill.[unique-value-here]"
8+
},
9+
"attributes": {
10+
"key": "string value"
11+
},
12+
"user": {
13+
"userId": "amzn1.ask.account.[unique-value-here]",
14+
"accessToken": "Atza|AAAAAAAA...",
15+
"permissions": {
16+
"consentToken": "ZZZZZZZ..."
17+
}
18+
}
19+
},
20+
"context": {
21+
"System": {
22+
"device": {
23+
"deviceId": "string",
24+
"supportedInterfaces": {
25+
"AudioPlayer": {}
26+
}
27+
},
28+
"application": {
29+
"applicationId": "amzn1.ask.skill.[unique-value-here]"
30+
},
31+
"user": {
32+
"userId": "amzn1.ask.account.[unique-value-here]",
33+
"accessToken": "Atza|AAAAAAAA...",
34+
"permissions": {
35+
"consentToken": "ZZZZZZZ..."
36+
}
37+
},
38+
"apiEndpoint": "https://api.amazonalexa.com",
39+
"apiAccessToken": "AxThk..."
40+
},
41+
"AudioPlayer": {
42+
"playerActivity": "PLAYING",
43+
"token": "audioplayer-token",
44+
"offsetInMilliseconds": 0
45+
}
46+
},
47+
"request": {
48+
"type": "LaunchRequest",
49+
"requestId": "string",
50+
"timestamp": "string",
51+
"locale": "string"
52+
}
53+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"header": {
3+
"payloadVersion": "1",
4+
"namespace": "Control",
5+
"name": "SwitchOnOffRequest"
6+
},
7+
"payload": {
8+
"switchControlAction": "TURN_ON",
9+
"appliance": {
10+
"additionalApplianceDetails": {
11+
"key2": "value2",
12+
"key1": "value1"
13+
},
14+
"applianceId": "sampleId"
15+
},
16+
"accessToken": "sampleAccessToken"
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"awslogs": {
3+
"data": "H4sIAIOmuFwAA8tJLVGvUqjKLFAoycgsBgAzQsm5DgAAAA=="
4+
}
5+
}

lib/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { merge, cloneDeep } from 'lodash'
2-
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent } from 'aws-lambda'
2+
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent, CloudWatchLogsEvent } from 'aws-lambda'
3+
import { AlexaSmartHomeEvent, AlexaSkillEvent } from '../globals'
34
import { GeneratedEvent } from './generatedEvent'
45
import snsTemplate from './events/aws/sns-template.json'
56
import sqsTemplate from './events/aws/sqs-template.json'
@@ -8,6 +9,9 @@ import scheduledTemplate from './events/aws/scheduled-template.json'
89
import s3Template from './events/aws/s3-template.json'
910
import kinesisTemplate from './events/aws/kinesis-template.json'
1011
import dynamoTemplate from './events/aws/dynamo-stream-event-template.json'
12+
import cloudwatchLogsEventTemplate from './events/aws/cloudwatch-logs-event-template.json'
13+
import alexaSmartHomeEventTemplate from './events/aws/alexa-smart-home-event-template.json'
14+
import alexaSkillEventTemplate from './events/aws/alexa-skill-event-template.json'
1115

1216
const dictionary: any = {
1317
'aws:sns': snsTemplate as SNSEvent,
@@ -17,6 +21,9 @@ const dictionary: any = {
1721
'aws:s3': s3Template as S3Event,
1822
'aws:kinesis': kinesisTemplate as KinesisStreamEvent,
1923
'aws:dynamo': dynamoTemplate as DynamoDBStreamEvent,
24+
'aws:cloudwatchLogEvent': cloudwatchLogsEventTemplate as CloudWatchLogsEvent,
25+
'aws:alexaSmartHomeEvent': alexaSmartHomeEventTemplate as AlexaSmartHomeEvent,
26+
'aws:alexaSkillEvent': alexaSkillEventTemplate as AlexaSkillEvent,
2027
}
2128

2229
export default function createEvent(eventType: string, body: any): GeneratedEvent {

0 commit comments

Comments
 (0)