bbindreiter / node-red-contrib-alexa-remote2-applestrudel

Node-Red Nodes for interacting with Alexa
https://flows.nodered.org/node/node-red-contrib-alexa-remote2-applestrudel
MIT License
77 stars 21 forks source link

When using amazon.ca, the HTTPPush connection incorrectly defaults to bob-dispatch-prod-eu.amazon.com #204

Open danielbrunt57 opened 1 month ago

danielbrunt57 commented 1 month ago

I am new to node-red-contrib-alexa-remote2 as of yesterday but have been a long time user of the Alexa Media Player in HA and have been doing lots of debugging in it and alexapy which proved invaluable in figuring out what to set the "Push Dispatch Host" to despite the severe lack of user documentation on what that entry can be set to. My Echo devices are registered to my account in amazon.ca but that domain resulted in HTTP2 connecting by default to bob-dispatch-prod-eu.amazon.com. When I used amazon.com then HTTP2Push connected to the correct gateway (bob-dispatch-prod-na.amazon.com) but then I had zero devices. Before I delved inside the code, I tried entering the alexapy gateway alexa.na.gateway.devices.a2z.com and Push then worked. That alias is the same IP as the bob-dispatch-prod-na.amazon.com alias.

I therefore recommend that the /alexa-remote2/alexa-http2push.js should be amended as follows for amazon.ca:

    connect() {
        this.inClosing = false;
        this.update_access_token(token => {
            this.access_token = token;

            let host = 'bob-dispatch-prod-eu.amazon.com';
            if (this._options.pushDispatchHost) {
                host = this._options.pushDispatchHost;
            } else if (this._options.amazonPage === 'amazon.com') {
                host = 'bob-dispatch-prod-na.amazon.com';
            } else if (this._options.amazonPage === 'amazon.ca') {
                host = 'bob-dispatch-prod-na.amazon.com';
            } else if (this._options.amazonPage === 'amazon.com.br') {
                host = 'bob-dispatch-prod-na.amazon.com';
            } else if (this._options.amazonPage === 'amazon.co.jp') {
                host = 'bob-dispatch-prod-fe.amazon.com';
            } else if (this._options.amazonPage === 'amazon.com.au') {
                host = 'bob-dispatch-prod-fe.amazon.com';
            }
            this._options.logger && this._options.logger(`Alexa-Remote HTTP2-PUSH: Use host ${host}`);

I'd also recommend that the Alexa Account configuration node help info include the Push Dispatch Host field and the three possible settings for that field: bob-dispatch-prod-eu.amazon.com, bob-dispatch-prod-na.amazon.com' and 'bob-dispatch-prod-fe.amazon.com.

bbindreiter commented 1 month ago

Hi @danielbrunt57, thank you very much for your input! This part of the code sits here: https://github.com/Apollon77/alexa-remote

The maintainer @Apollon77 would surely appreciate a PR.

danielbrunt57 commented 1 month ago

As per alexapy/const.py, see PR 246 for 4 additional domain lookups: 'amazon.ca','amazon.com.mx': host 'bob-dispatch-prod-na.amazon.com' 'amazon.com.in','amazon.co.nz': host 'bob-dispatch-prod-fe.amazon.com'

Apollon77 commented 1 month ago

released in 7.0.5