0

I have multiple devices streaming audio to my server.

My server is sending the audio to my custom skill

How do I pass extra state about the room the device is in to the adapter e.g "room name"?

my multipart request includes:

{
    'context': [
        {
            'header': {
                'namespace': 'AudioPlayer',
                'name': 'PlaybackState'
            },
            'payload': {
                'token': '',
                'offsetInMilliseconds': 0,
                'playerActivity': 'IDLE'
            }
        },
        {
            'header': {
                'namespace': 'Speaker',
                'name': 'VolumeState'
            },
            'payload': {
                'volume': 100,
                'muted': False,
            }
        },
        {
            'header': {
                'namespace': 'SpeechSynthesizer',
                'name': 'SpeechState'
            },
            'payload': {
                'token': '',
                'offsetInMilliseconds': 0,
                'playerActivity': 'FINISHED'
            }
        }
    ],
    'event': {
        'header': {
            'namespace': 'SpeechRecognizer',
            'name': 'Recognize',
            'messageId': 'my-messageId',
            'dialogRequestId': 'my-dialogRequestId',
        },
        'payload': {
            'profile': 'CLOSE_TALK',
            'format': 'AUDIO_L16_RATE_16000_CHANNELS_1'
        }
    }
}

I have tried passing arbitrary extra headers in context e.g.,

[
    'header': {
        'namespace': 'MyCustomSkill',
        'name': 'RoomState'
    },
    'payload': {
        'name': 'kitchen',
        'temperature': '40'
    }
]

but the adapter does not have access to those extra headers. The request looks like this:

{
   "request": {
      "locale": "en-GB",
      "type": "IntentRequest",
      "timestamp": "2017-10-05T22:33:35Z",
      "requestId": "amzn1.echo-api.request.a415ac1b-7b42-4520-830d-a48912956a45",
      "intent": {
         "slots": {
            "ROOM": {
               "value": "kitchen",
               "resolutions": {
                  "resolutionsPerAuthority": [
                     {
                        "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.c9fd57b8-b243-42ed-a6a9-5745fccb6746.ROOM",
                        "values": [
                           {
                              "value": {
                                 "id": "09228dac155633b13780552bc01dc2e0",
                                 "name": "kitchen"
                              }
                           }
                        ],
                        "status": {
                           "code": "ER_SUCCESS_MATCH"
                        }
                     }
                  ]
               },
               "name": "ROOM",
               "confirmationStatus": "NONE"
            }
         },
         "name": "ChatIntent",
         "confirmationStatus": "NONE"
      }
   },
   "context": {
      "AudioPlayer": {
         "playerActivity": "IDLE"
      },
      "System": {
         "user": {
            "userId": "my-user-id"
         },
         "apiEndpoint": "https://api.eu.amazonalexa.com",
         "device": {
            "deviceId": "my-device-id",
            "supportedInterfaces": {
               "AudioPlayer": {}
            }
         },
         "application": {
            "applicationId": "my-application-id"
         }
      }
   },
   "version": "1.0",
   "session": {
      "user": {
         "userId": "my-user-id"
      },
      "sessionId": "amzn1.echo-api.session.8c3e0d80-69e3-49ad-a981-d1073e0100b2",
      "new": true,
      "application": {
         "applicationId": my-application-id"
      }
   }
}

Is this possible to achieve with context?

Rich Tier
  • 9,021
  • 10
  • 48
  • 71

1 Answers1

0

You can create state handler if you wish to have contexts

https://github.com/alexa/skill-sample-nodejs-audio-player/blob/mainline/multiple-streams/js/audioEventHandlers.js#L8

or you can simply use

this.attributes to store your required information.

cypronmaya
  • 520
  • 1
  • 11
  • 24