Skip to content

Commit

Permalink
New types for alexa skills and alexa smarthome events. Adding cloudwa…
Browse files Browse the repository at this point in the history
…tch logs as well.
  • Loading branch information
astuyve committed Apr 18, 2019
1 parent eeb41b0 commit 5bf1863
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 1 deletion.
69 changes: 69 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,72 @@ declare module '*.json' {
const value: any
export default value
}

export interface AlexaSmartHomeEvent {
header: { [name: string]: string },
payload: {
switchControlAction: string,
appliance: {
additionalApplianceDetails: { [name: string]: string },
applianceId: string,
},
accessToken: string
}
}

export interface AlexaSkillEvent {
version: string,
session: AlexaSkillSession,
context: AlexaSkillContext,


}

export interface AlexaSkillSession {
new: boolean,
sessionId: string,
application: {
applicationId: string
},
attributes: {
[name: string]: string
},
user: AlexaSkillUser
}

export interface AlexaSkillContext {
System: {
device: {
deviceId: string,
supportedInterfaces: {
AudioPlayer: any
}
},
application: {
applicationId: string
},
user: AlexaSkillUser,
apiEndpoint: string,
apiAccessToken: string
},
AudioPlayer: {
playerActivity: string,
token: string,
offsetInMilliseconds: number,
}
}

export interface AlexaSkillUser {
userId: string,
accessToken: string,
permissions: {
consentToken: string
}
}

export interface AlexaSkillRequest {
type: string,
requestId: string,
timestamp: string,
locale: string,
}
53 changes: 53 additions & 0 deletions lib/events/aws/alexa-skill-event-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.[unique-value-here]",
"application": {
"applicationId": "amzn1.ask.skill.[unique-value-here]"
},
"attributes": {
"key": "string value"
},
"user": {
"userId": "amzn1.ask.account.[unique-value-here]",
"accessToken": "Atza|AAAAAAAA...",
"permissions": {
"consentToken": "ZZZZZZZ..."
}
}
},
"context": {
"System": {
"device": {
"deviceId": "string",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"application": {
"applicationId": "amzn1.ask.skill.[unique-value-here]"
},
"user": {
"userId": "amzn1.ask.account.[unique-value-here]",
"accessToken": "Atza|AAAAAAAA...",
"permissions": {
"consentToken": "ZZZZZZZ..."
}
},
"apiEndpoint": "https://api.amazonalexa.com",
"apiAccessToken": "AxThk..."
},
"AudioPlayer": {
"playerActivity": "PLAYING",
"token": "audioplayer-token",
"offsetInMilliseconds": 0
}
},
"request": {
"type": "LaunchRequest",
"requestId": "string",
"timestamp": "string",
"locale": "string"
}
}
18 changes: 18 additions & 0 deletions lib/events/aws/alexa-smart-home-event-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"header": {
"payloadVersion": "1",
"namespace": "Control",
"name": "SwitchOnOffRequest"
},
"payload": {
"switchControlAction": "TURN_ON",
"appliance": {
"additionalApplianceDetails": {
"key2": "value2",
"key1": "value1"
},
"applianceId": "sampleId"
},
"accessToken": "sampleAccessToken"
}
}
5 changes: 5 additions & 0 deletions lib/events/aws/cloudwatch-logs-event-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"awslogs": {
"data": "H4sIAIOmuFwAA8tJLVGvUqjKLFAoycgsBgAzQsm5DgAAAA=="
}
}
9 changes: 8 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { merge, cloneDeep } from 'lodash'
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent } from 'aws-lambda'
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent, CloudWatchLogsEvent } from 'aws-lambda'
import { AlexaSmartHomeEvent, AlexaSkillEvent } from '../globals'
import { GeneratedEvent } from './generatedEvent'
import snsTemplate from './events/aws/sns-template.json'
import sqsTemplate from './events/aws/sqs-template.json'
Expand All @@ -8,6 +9,9 @@ import scheduledTemplate from './events/aws/scheduled-template.json'
import s3Template from './events/aws/s3-template.json'
import kinesisTemplate from './events/aws/kinesis-template.json'
import dynamoTemplate from './events/aws/dynamo-stream-event-template.json'
import cloudwatchLogsEventTemplate from './events/aws/cloudwatch-logs-event-template.json'
import alexaSmartHomeEventTemplate from './events/aws/alexa-smart-home-event-template.json'
import alexaSkillEventTemplate from './events/aws/alexa-skill-event-template.json'

const dictionary: any = {
'aws:sns': snsTemplate as SNSEvent,
Expand All @@ -17,6 +21,9 @@ const dictionary: any = {
'aws:s3': s3Template as S3Event,
'aws:kinesis': kinesisTemplate as KinesisStreamEvent,
'aws:dynamo': dynamoTemplate as DynamoDBStreamEvent,
'aws:cloudwatchLogEvent': cloudwatchLogsEventTemplate as CloudWatchLogsEvent,
'aws:alexaSmartHomeEvent': alexaSmartHomeEventTemplate as AlexaSmartHomeEvent,
'aws:alexaSkillEvent': alexaSkillEventTemplate as AlexaSkillEvent,
}

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

0 comments on commit 5bf1863

Please sign in to comment.