alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Unable to make HTTP request to api.amazonalexa.com from lambda #556

Closed syberkitten closed 5 years ago

syberkitten commented 5 years ago

Hi

Using the Alexa simulator, and an actual device.

a skill times out when ever calling this method, sample: upsServiceClient: services.ups.UpsServiceClient = serviceClientFactory.getUpsServiceClient() phoneNumber = await upsServiceClient.getProfileMobileNumber() no exception, just after 6 (or X) seconds of timeout the skill returns: There was a problem with the requested skill's response

What could be the problem?


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X ] Bug report 
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Expected Behavior

Should Work or should throw an exception within the expected Alexa skill timeout duration. If the ApiClient fails it should fail in a timely fashion.

Current Behavior

Alexa times out giving back a default error: "There was a problem with the requested skill's response" {"type":"SessionEndedRequest","requestId":"amzn1.echo-api.request.89e0a390-6dcc-4839-8286-4deabcc4b9fc","timestamp":"2019-05-29T13:20:03Z","locale":"en-US","reason":"ERROR","error":{"type":"INVALID_RESPONSE","message":"An exception occurred while dispatching the request to the skill."}}

Possible Solution

Steps to Reproduce (for bugs)

Context

Running directly on AWS Lambda

Your Environment

Node.js and NPM Info

hideokamoto commented 5 years ago

The error code is "type":"INVALID_RESPONSE". So I think the issue might be in response object.

Could you check the response object by using the response interceptor ? In my case, I always add the following interceptor in my skill.

import * as Alexa from 'ask-sdk'
import { ResponseLogger, RequestLogger } from 'ask-utils'

export const handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        ...YOUR_HANDLERS
    )
    .addRequestInterceptors(RequestLogger)
    .addResponseInterceptors(ResponseLogger)
    .lambda()
syberkitten commented 5 years ago

Thanks for the lead.

I've tried different request libraries, such as: request-promise request-promise-native and request

locally when testing everything works and I'm getting a result from: https://api.amazonalexa.com/v2/accounts/~current/settings/Profile.mobileNumber

Yet when this is run from within a lambda, the promise looks to be lost.... there is NO continuation of the code after the async await, example:

The method to make the API call:

const requestNative = require('request-promise-native')

export async function callAlexaAPI2(apiEndpoint: string, method: string, apiAccessToken: string): Promise<any> {
    const headers: any = {
        Authorization: `Bearer ${apiAccessToken}`,
        'content-type': 'application/json'
    };

    const target: string = `${apiEndpoint}${method}`

    const options: any = {
        method: 'GET',
        uri: target,
        headers: headers,
        json: true
    }

    return requestNative(options).promise()
}

Code inside skill handler:


            const apiAccessToken: string = requestEnvelope.context.System.apiAccessToken
            const apiEndpoint: string = requestEnvelope.context.System.apiEndpoint
            const apiMethodPhone: string = `/v2/accounts/~current/settings/Profile.mobileNumber`
            const apiMethodEmail: string = `/v2/accounts/~current/settings/Profile.email`

            let phoneWithCode: string = ''

            let err: any
            let phoneNumber: any

            [err, phoneNumber] = await to(callAlexaAPI2(apiEndpoint, apiMethodPhone, apiAccessToken))

            console.log(`getting phone err: ${err}, email: ${phoneNumber}`)

the console log never reaches.

I'm using the interceptors, the request looks ok and the response is empty, since it never gets to the code which builds it.

please note the "to" method is a helper to get a functional like style of response, so you don't need the then/catch

export function to (promise: any) {
    return promise.then( (data: any) => {
        return [null, data]
    })
        .catch((err: any) => [err])
}

I've spend 3 days on this, and I'm running out of leads.

How can it be that locally using the same version of nodejs it works (all the methods work) but on the lambda no http request does.

Is it possible to get any more detailed error, or debug the lambda with breakpoints?

ps. I am able to make an http request to our own API hosted on an EC2. the calls don't make it to: api.amazonalexa.com from the lambda

syberkitten commented 5 years ago

This is a non issue, the problem was a network restriction.

nephisto1954 commented 5 years ago

@syberkitten. Any chances you could describe the steps you took to resolve the Network restriction as I am facing similar issues.

Many Thanks

sandeepknambiar commented 4 years ago

I am seeing maintenance screen when I access https://api.amazonalexa.com/

Is there any alternative way to connect or when will be this service available. Please help me in this.

Thanks for your time.

ShenChen93 commented 4 years ago

Hi, @sandeepknambiar I am going to check with the service team on this issue, btw, may I know what's the use case to directly access this api endpoint ?

Thanks, Shen

hnglong commented 4 years ago

Hi @ShenChen-Amazon ,

I saw the same issue: https://api.amazonalexa.com/ - "Website Temporarily Unavailable" My use case is to link the Alexa with my web app. Below is an instruction https://developer.amazon.com/en-US/docs/alexa/account-linking/app-to-app-account-linking-starting-from-your-app.html

Request In the request shown next, set HOST to one of the following, depending on the user's region: api.amazonalexa.com, api.eu.amazonalexa.com, or api.fe.amazonalexa.com

POST /v1/users/~current/skills/{skillId}/enablement HTTP/1.1 Host: api.amazonalexa.com, api.eu.amazonalexa.com, api.fe.amazonalexa.com Content-Type: application/json Authorization: "Bearer {Amazon Access Token}" { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://yourRedirectURI", "authCode": "Your user's authorization code from your authorization server", "type": "AUTH_CODE" } }

Thanks, Long

ShenChen93 commented 4 years ago

Hi, @hnglong I tested this endpoint by using other apis(use Post) and it works as expected. However, when I try to access the webpage of this api by using directly call, I see the same error page. I am not sure if access this api endpoint by using directly call is acceptable behavior, thus I want to check with you whether this api endpoint is working as expected for your use case ? If not, what is the error message ?

Thanks, Shen

hnglong commented 4 years ago

Hi @ShenChen-Amazon,

This is what I put to the post request. Do you know if the api.amazonalexa.com is really down?

POST api.amazonalexa.com/api/v1/users/~current/skills/amzn1.ask.skill.747xxxxx/enablement HTTP/1.1 Header: Authorization: bearer Atza%7CIwEBINojVdQdXPWMujb9-xxxxx Content-type: application/json Body { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://b1afad690bb4.test.io/callback/alexa", "authCode": "ANRZxxxxx", "type": "AUTH_CODE" } }

Response: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Website Temporarily Unavailable

 

website temporarily unavailable
ShenChen93 commented 4 years ago

Hi @hnglong ,

It seems the url path api.amazonalexa.com/api/v1/users/~current/skills/amzn1.ask.skill.747xxxxx/enablement HTTP/1.1 is not correct as it should not include api/ prefix. Could you try it again after removing this prefix. The api endpoint is working as I tested it by using other apis.

And I confirmed with service team that the current unavailable webpage is a placeholder for bad URL. The error message is misleading and the service team will improve that.

Thanks, Shen

hnglong commented 4 years ago

Hi @ShenChen-Amazon,

Thanks for helping me catch the issue. I removed the "api/" and now the got the new issue "Invalid account linking credentials". Look like I am almost getting there. Could you please help me to look into this one again?

Header: Authorization: bearer Atza%7CIwEBINojVdQdXPWMujb9-xxxxx <---- this I got from Alexa Developer Console (NOT from LWA) Content-type: application/json Body { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://b1afad690bb4.test.io/callback/alexa", "authCode": "ANRZxxxxx", <----- this I also got it Alexa Developer Console - Account Linking (NOT from LWA) "type": "AUTH_CODE" } }

The above auth code and token come from this request uri: https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.88xxxxx&response_type=code&scope=alexa::skills:account_linking&redirect_uri=https://b1afad690bb4.test.io/callback/alexa&state=1064cdd9-47bb-46b4-b333-0c30edca7404&access_type=online&approval_prompt=auto

image

Thanks, Long

sandeepknambiar commented 4 years ago

Hi,

Could any one brief on the way to access account of mine from API. Any document on this would help out. I need to check my device status (online/offline) from this.

Thanks in advance.

On Tue, Jul 28, 2020 at 8:43 PM hnglong notifications@github.com wrote:

Hi @ShenChen-Amazon https://github.com/ShenChen-Amazon,

Thanks for helping me catch the issue. I removed the "api/" and now the got the new issue "Invalid account linking credentials". Look like I am almost getting there. Could you please help me to look into this one again?

Header: Authorization: bearer Atza%7CIwEBINojVdQdXPWMujb9-xxxxx <---- this I got from Alexa Developer Console (NOT from LWA) Content-type: application/json Body { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://b1afad690bb4.test.io/callback/alexa", "authCode": "ANRZxxxxx", <----- this I also got it Alexa Developer Console

  • Account Linking (NOT from LWA) "type": "AUTH_CODE" } }

The above auth code and token come from this request uri:

https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.88xxxxx&response_type=code&scope=alexa::skills:account_linking&redirect_uri=https://b1afad690bb4.test.io/callback/alexa&state=1064cdd9-47bb-46b4-b333-0c30edca7404&access_type=online&approval_prompt=auto [image: image] https://user-images.githubusercontent.com/29156984/88753800-d1f7e980-d122-11ea-8954-18e2c32b30e3.png

Thanks, Long

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/556#issuecomment-665413189, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIPOJPTYYAS4JNAVEBPNUTR56LHPANCNFSM4HQMYVCA .

ShenChen93 commented 4 years ago

Hi @ShenChen-Amazon,

Thanks for helping me catch the issue. I removed the "api/" and now the got the new issue "Invalid account linking credentials". Look like I am almost getting there. Could you please help me to look into this one again?

Header: Authorization: bearer Atza%7CIwEBINojVdQdXPWMujb9-xxxxx <---- this I got from Alexa Developer Console (NOT from LWA) Content-type: application/json Body { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://b1afad690bb4.test.io/callback/alexa", "authCode": "ANRZxxxxx", <----- this I also got it Alexa Developer Console - Account Linking (NOT from LWA) "type": "AUTH_CODE" } }

The above auth code and token come from this request uri: https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.88xxxxx&response_type=code&scope=alexa::skills:account_linking&redirect_uri=https://b1afad690bb4.test.io/callback/alexa&state=1064cdd9-47bb-46b4-b333-0c30edca7404&access_type=online&approval_prompt=auto

image

Thanks, Long

Hi @hnglong ,

According to the screen cut you provided, it seems you use the LWA as the web autHorization URI. For my understanding, E.G., if you try to link your skill with google, you will need to provide google auth URI: https://accounts.google.com/o/oauth2/auth and google access token uri: https://oauth2.googleapis.com/token. And get the clientID and clientSecrect from google as well.

Sorry I am not an expert at account-linking side so I might be wrong. To get the most professional answer, I would recommend you to log your questions at Alexa Forum under account linking topic.

Thanks, Shen

ShenChen93 commented 4 years ago

Hi, Could any one brief on the way to access account of mine from API. Any document on this would help out. I need to check my device status (online/offline) from this. Thanks in advance. On Tue, Jul 28, 2020 at 8:43 PM hnglong @.***> wrote: Hi @ShenChen-Amazon https://github.com/ShenChen-Amazon, Thanks for helping me catch the issue. I removed the "api/" and now the got the new issue "Invalid account linking credentials". Look like I am almost getting there. Could you please help me to look into this one again? Header: Authorization: bearer Atza%7CIwEBINojVdQdXPWMujb9-xxxxx <---- this I got from Alexa Developer Console (NOT from LWA) Content-type: application/json Body { "stage": "skill stage", "accountLinkRequest": { "redirectUri": "https://b1afad690bb4.test.io/callback/alexa", "authCode": "ANRZxxxxx", <----- this I also got it Alexa Developer Console - Account Linking (NOT from LWA) "type": "AUTH_CODE" } } The above auth code and token come from this request uri: https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.88xxxxx&response_type=code&scope=alexa::skills:account_linking&redirect_uri=https://b1afad690bb4.test.io/callback/alexa&state=1064cdd9-47bb-46b4-b333-0c30edca7404&access_type=online&approval_prompt=auto [image: image] https://user-images.githubusercontent.com/29156984/88753800-d1f7e980-d122-11ea-8954-18e2c32b30e3.png Thanks, Long — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#556 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIPOJPTYYAS4JNAVEBPNUTR56LHPANCNFSM4HQMYVCA .

Hi @sandeepknambiar

Sorry as this is the repo for ASK SDK, I really don't have lot of context on your question. Would be great if you could log your question at Alexa Forum under account-linking topic, where people who has better context will help you figure out the solution.

Thanks, Shen