Alexa Lambda function to get user's full name

Viewed 1491

Using the Alexa Custom skills, and AWS Lambda Functions, I want to be able to just get the user's name from their account. I already set up permissions and account linking and verified that it works. However, there are no resources available for python 3.6 methods for retrieving the actual user info.

There is this page which has the method I need to use (get_profile_name()): https://github.com/alexa/alexa-skills-kit-sdk-for-python/blob/master/docs/en/SERVICE_CLIENTS.rst#upsserviceclient

However, it does not give me info on how I can access that method inside a Lambda Function.

My main function runs from:

def lambda_handler(event, context):

Event only has the JSON from the user input from the custom Alexa skill, which does not include a name, so I'm stuck on how to access anything that has the get_profile_name()

The only example I can possibly find is from this: https://forums.developer.amazon.com/questions/181267/new-sdk-and-python-36-progressive-response-sample.html

which uses

handler_input.service_client_factory.get_profile_name()

But I cannot figure out how the handler_input is different from my "event"

I figured it would be simple to just get a name, but this is pretty complex. Has anyone done this before?

2 Answers

Please see the Alexa Customer Profile API documentation to get customers' name, email address and phone number.

This documentation details the request process -- here's an example from this documentation to get the phone number: Host: api.amazonalexa.com Accept: application/json Authorization: Bearer MQEWY...6fnLok GET https://api.amazonalexa.com/v2/accounts/~current/settings/Profile.name

Note you must obtain an access token to use as part of the request (how to obtain a token is also detailed on that page).

If the ASK Python SDK does not contain built-in support for the Alexa Customer Profile API it seems that you can just create a RESTful request as detailed.

Your code needs to have handler classes for your skill's intents with two methods:

can_handle(self, handler_input)

and

handle(self, handler_input)

This is how you get the handler_input via parameter.

There's a similar example here but to retrieve the address.

Related