Comments (25)
That the documentation is not good is completely agreed :-) IOn fact the types file contains a bit in that direction
In fact after initialization you need the serialnumber of the device you want to send the command to (or the right device object). then call
alexa.sendSequenceCommand(serialOrDeviceObject, 'textCommand', 'What time is it', (err, res) => {
....
})
from alexa-remote.
could be DSN ... best check the alexa.serialNumbers list for the device details (you find objects in there that have all details)
from alexa-remote.
https://github.com/Apollon77/alexa-remote/blob/master/example/example.js#L36 there you find the object you need to store and provide in formerRegistrationData and the value of the subkey "macDms" you hand over as macDms
from alexa-remote.
no there is no response because this command just sends a command into the amazon cloud.
Please have in mind it is the same API that the amazon Alexa app uses ... so it only can do what the app can!!
For response you need to provide macDMS correctly and then you can especblish a wsmwtt connection and react to events for push informations ... one type are "device activities" ... there you can find the answers ... and it is no "direct 1:1 way" ... but how this all works I have no documentation, just "reality implementations" ... so check out this as satrting point https://github.com/Apollon77/ioBroker.alexa2/blob/master/main.js#L4658-L4664 ...
from alexa-remote.
Hi , so i have connected alexa to web as guided here : http://www.gehrig.info/alexa/Alexa.html
i got cookie from it but looks like the init block need some more info
alexa.init({
cookie: cookie, // cookie if already known, else can be generated using proxy
proxyOnly: true,
proxyOwnIp: 'localhost',
proxyPort: 3001,
proxyLogLevel: 'info',
bluetooth: true,
logger: console.log, // optional
alexaServiceHost: 'layla.amazon.de', // optional, e.g. "pitangui.amazon.com" for amazon.com, default is "layla.amazon.de"
// userAgent: '...', // optional, override used user-Agent for all Requests and Cookie determination
// acceptLanguage: '...', // optional, override Accept-Language-Header for cookie determination
// amazonPage: '...', // optional, override Amazon-Login-Page for cookie determination and referer for requests
useWsMqtt: true, // optional, true to use the Websocket/MQTT direct push connection
cookieRefreshInterval: 7*24*60*1000, // optional, cookie refresh intervall, set to 0 to disable refresh
formerDataStorePath: '...', // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: { ... }, // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: { ... }, // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
},
so can u guide on these three specially macDms which is required
formerDataStorePath: '...', // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: { ... }, // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: { ... }, // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
thanks
from alexa-remote.
- macDMS is needed if you want to use the wsMQTT push connection to receive piush messages from alexa actions. Else irrelevant.
- formerRegistrationData are needed when you get the cookie via this lib and also want to do the refresh of the cookie over it because there important infos from the cookie gathering process are stored whcih are needed for refreshs
- formerDataStorePath is used to store some basic data fropm the cookei gathering process (like a unique device id) so that this is reused even if you get new cookies without providing formerRegistrationData
from alexa-remote.
- macDMS is needed if you want to use the wsMQTT push connection to receive piush messages from alexa actions. Else irrelevant.
- formerRegistrationData are needed when you get the cookie via this lib and also want to do the refresh of the cookie over it because there important infos from the cookie gathering process are stored whcih are needed for refreshs
- formerDataStorePath is used to store some basic data fropm the cookei gathering process (like a unique device id) so that this is reused even if you get new cookies without providing formerRegistrationData
ok so i have set these 3 parameters to blank ""
as am not sure how to set them correctly or get their values.
so now when i run node index.js
giving me error
Alexa-Remote: Use as User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Alexa-Remote: Use as Login-Amazon-URL: amazon.de
Alexa-Remote: Use as Base-URL: layla.amazon.de
Alexa-Remote: cookie was provided
Alexa-Remote: Sending Request with {"host":"layla.amazon.de","path":"/api/bootstrap?version=0","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: 401 Unauthorized
Error: Error while checking Authentication: Error: 401 Unauthorized
maybe something wrong with host ? the .de
seems its not for US , can u tell which host is for US. is it alexa.amazon.com
?
from alexa-remote.
No, before setting them to black strings please simply do not provide them /optionally means exactly this).
In fact the path you can simply set to a valid path where the prociess could store file
The other two are "alexa.cookieData" and "alexa.cookieData.macDms" and best to store it after getting the cookie with the proxy.
Please do not provide alexaServiceHost when it is german default ... does it work then?
Seems I need to update the example
from alexa-remote.
ok i have set paths
formerDataStorePath: './storage/', // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: "./storage/alexa.cookieData", // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: "./storage/alexa.cookieData.macDms", // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
now it seems working in storage folder it created alexa.cookieData
file
from alexa-remote.
now it seems working but i have to go to http://localhost:3001 every time when i run script and login and then it will fetch cookie . so what can be done about it so that it save cookie
Alexa-Remote: Use as Login-Amazon-URL: amazon.de
Alexa-Remote: Use as Base-URL: alexa.amazon.de
Alexa-Remote: cookie was provided
Alexa-Remote: former registration data exist, try refresh
"./storage/alexa.cookieData"
Alexa-Remote: Error from refreshing cookies
Alexa-Remote: No cookie given, generate one
Alexa-Cookie: Use as Login-Amazon-URL: amazon.de
Alexa-Cookie: Use as Base-Amazon-URL: amazon.com
Alexa-Cookie: Use as Accept-Language: de-DE
Alexa-Cookie: Proxy mode disabled
[HPM] Proxy created: !/cookie-success -> https://alexa.amazon.com
[HPM] Proxy rewrite rule created: "^/www.amazon.com" ~> ""
[HPM] Proxy rewrite rule created: "^/alexa.amazon.com" ~> ""
Alexa-Cookie: Proxy-Server listening on port 3001
Alexa-Remote: Error from retrieving cookies
Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.
from alexa-remote.
Sorry but what you did? Only the one parameter with "path" in Name is a path, the others should be data objects or not provided
from alexa-remote.
Sorry but what you did? Only the one parameter with "path" in Name is a path, the others should be data objects or not provided
my formerDataStorePath
is set to
formerDataStorePath: './storage/alexa.cookieData',
you said that
the others should be data objects or not provided
so i have commentedmacDms
.
however if commentformerRegistrationData
i getError: 401 Unauthorized
unless its set to
formerRegistrationData: "alexa.cookieData"
then i get no error and it just ask for
Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.
after visiting when cookie is retrieved then it start working.
so my Question is what am doing wrong here so that i have not to visithttp://localhost:3001/
for cookie every time i run script and sorry for the NOOOOBS Questions.
thanks
from alexa-remote.
i see , seems like i need to use your another project : https://github.com/Apollon77/alexa-cookie for the cookie issue. will check it :). just wondering this alexa-cookie module should be already part of alexa-remote ?
from alexa-remote.
No you do not need. This is used by alexa-remote under the hood automatically ... see the proxy* Settings in alexa-remote
from alexa-remote.
No you do not need. This is used by alexa-remote under the hood automatically ... see the proxy* Settings in alexa-remote
ok then can u tell what am doing wrong :(
my formerDataStorePath
is set to
formerDataStorePath: './storage/alexa.cookieData',
you said that
the others should be data objects or not provided
so i have commentedmacDms
.
however if commentformerRegistrationData
i getError: 401 Unauthorized
unless its set to
formerRegistrationData: "alexa.cookieData"
then i get no error and it just ask for
Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.
after visiting when cookie is retrieved then it start working.
so my Question is what am doing wrong here so that i have not to visithttp://localhost:3001/
for cookie every time i run script and sorry for the NOOOOBS Questions.
thanks
from alexa-remote.
https://github.com/Apollon77/alexa-remote/blob/master/example/example.js#L36 there you find the object you need to store and provide in formerRegistrationData and the value of the subkey "macDms" you hand over as macDms
oh i see i was not writing these objects to disk , ok am now writing them but am still getting that error when i run the script again although cookie data and etc objects are written to disk and passed to formerRegistrationData
updated
// storage box path
const storage_box = "./storage/";
alexa.init({
cookie: cookie, // cookie if already known, else can be generated using proxy
proxyOnly: true,
proxyOwnIp: 'localhost',
proxyPort: 3001,
proxyLogLevel: 'info',
bluetooth: true,
logger: console.log, // optional
// alexaServiceHost: 'pitangui.amazon.com', // optional, e.g. "pitangui.amazon.com" for amazon.com, default is "layla.amazon.de"
// userAgent: '...', // optional, override used user-Agent for all Requests and Cookie determination
// acceptLanguage: '...', // optional, override Accept-Language-Header for cookie determination
// amazonPage: '...', // optional, override Amazon-Login-Page for cookie determination and referer for requests
useWsMqtt: false, // optional, true to use the Websocket/MQTT direct push connection
cookieRefreshInterval: 7*24*60*1000, // optional, cookie refresh intervall, set to 0 to disable refresh
formerDataStorePath: storage_box+"alexa.baseic_info", // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: storage_box+"alexa.cookieData", // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: storage_box+"alexa.cookieData.macDms", // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
},
async function (err) {
if (err) {
console.log (err);
return;
}
// write cookie data to disk
fs.writeFileSync(storage_box+'alexa.cookie', JSON.stringify(alexa.cookie));
fs.writeFileSync(storage_box+'alexa.csrf', JSON.stringify(alexa.csrf));
fs.writeFileSync(storage_box+'alexa.cookieData.macDms', JSON.stringify(alexa.cookieData.macDms));
fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData));
//fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData['loginCookie']));
error visit local to get cookie
Alexa-Remote: Use as User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Alexa-Remote: Use as Login-Amazon-URL: amazon.de
Alexa-Remote: Use as Base-URL: alexa.amazon.de
Alexa-Remote: cookie was provided
Alexa-Remote: former registration data exist, try refresh
"./storage/alexa.cookieData"
Alexa-Remote: Error from refreshing cookies
Alexa-Remote: No cookie given, generate one
Alexa-Cookie: Use as Login-Amazon-URL: amazon.de
Alexa-Cookie: Use as Base-Amazon-URL: amazon.com
Alexa-Cookie: Use as User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Alexa-Cookie: Use as Accept-Language: de-DE
Alexa-Cookie: Proxy mode disabled
[HPM] Proxy created: !/cookie-success -> https://alexa.amazon.com
[HPM] Proxy rewrite rule created: "^/www.amazon.com" ~> ""
[HPM] Proxy rewrite rule created: "^/alexa.amazon.com" ~> ""
Alexa-Cookie: Proxy-Server listening on port 3001
Alexa-Remote: Error from retrieving cookies
Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.
from alexa-remote.
Again:
- formerDataStorePath is the ONLY one that is a path!
- formerRegistrationData and macDms needs to be the object! SO Read your data make JSON parse and provide the object
from alexa-remote.
Again:
- formerDataStorePath is the ONLY one that is a path!
- formerRegistrationData and macDms needs to be the object! SO Read your data make JSON parse and provide the object
ok i tried that too but now getting 401 error
Error: Error while checking Authentication: Error: 401 Unauthorized
what am doing is that i read and then parse it
// storage box path
const storage_box = "./storage/";
const Alexa_cookie_data = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData", 'utf8'));
const Alexa_macDms = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData.macDms", 'utf8'));
const Alexa_cookie = JSON.parse(fs.readFileSync(storage_box+"alexa.cookie", 'utf8'));
alexa.init({
cookie: cookie, // cookie if already known, else can be generated using proxy
proxyOnly: true,
proxyOwnIp: 'localhost',
proxyPort: 3001,
proxyLogLevel: 'info',
bluetooth: true,
logger: console.log, // optional
//alexaServiceHost: 'pitangui.amazon.com', // optional, e.g. "pitangui.amazon.com" for amazon.com, default is "layla.amazon.de"
// userAgent: '...', // optional, override used user-Agent for all Requests and Cookie determination
// acceptLanguage: '...', // optional, override Accept-Language-Header for cookie determination
// amazonPage: '...', // optional, override Amazon-Login-Page for cookie determination and referer for requests
useWsMqtt: false, // optional, true to use the Websocket/MQTT direct push connection
cookieRefreshInterval: 7*24*60*1000, // optional, cookie refresh intervall, set to 0 to disable refresh
formerDataStorePath: storage_box+"alexa.baseic_info", // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: Alexa_cookie_data, // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: Alexa_macDms, // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
},
async function (err) {
if (err) {
console.log (err);
return;
}
// write cookie data to disk
fs.writeFileSync(storage_box+'alexa.cookie', JSON.stringify(alexa.cookie));
fs.writeFileSync(storage_box+'alexa.cookieData.macDms', JSON.stringify(alexa.cookieData.macDms));
fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData));
//fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData['loginCookie']));
from alexa-remote.
Should
cookie: cookie, // cookie if already known, else can be generated using proxy
not be
cookie: Alexa_cookie, // cookie if already known, else can be generated using proxy
??
from alexa-remote.
Aaaand ... example updated
from alexa-remote.
Should
cookie: cookie, // cookie if already known, else can be generated using proxy
not be
cookie: Alexa_cookie, // cookie if already known, else can be generated using proxy
??
ya its because i had pre fetched cookie as guided in : https://www.gehrig.info/alexa/Alexa.html and had declared it as var cookie = // fetched as guided in https://www.gehrig.info/alexa/Alexa.html
however i had even changed to
cookie: Alexa_cookie, // cookie if already known, else can be generated using proxy
but now getting 401
Alexa-Remote: Use as Login-Amazon-URL: amazon.de
Alexa-Remote: Use as Base-URL: alexa.amazon.de
Alexa-Remote: cookie was provided
Alexa-Remote: Sending Request with {"host":"alexa.amazon.de","path":"/api/bootstrap?version=0","method":"GET","timeout":10000,"headers":{}}
Alexa-Remote: Response: 401 Unauthorized
Error: Error while checking Authentication: Error: 401 Unauthorized
at C:\Alexa\alexa-remote.js:153:49
at C:\Alexa\alexa-remote.js:1080:28
at handleResponse (C:\Alexa\alexa-remote.js:883:24)
at Gunzip.cb (C:\Alexa\alexa-remote.js:1006:37)
at Gunzip.zlibBufferOnEnd (node:zlib:161:10)
at Gunzip.emit (node:events:390:28)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
here is my full code of index.js can u have please look to see whats wrong ??
let Alexa = require('./alexa-remote');
let alexa = new Alexa();
const fs = require('fs');
/***************************************************************/
const timer = ms => new Promise( res => setTimeout(res, ms));
// storage box path
const storage_box = "./storage/";
const Alexa_cookie_data = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData", 'utf8'));
const Alexa_macDms = JSON.parse(fs.readFileSync(storage_box+"alexa.cookieData.macDms", 'utf8'));
const Alexa_cookie = JSON.parse(fs.readFileSync(storage_box+"alexa.cookie", 'utf8'));
alexa.init({
cookie: Alexa_cookie, // cookie if already known, else can be generated using proxy
proxyOnly: true,
proxyOwnIp: 'localhost',
proxyPort: 3001,
proxyLogLevel: 'info',
bluetooth: false,
logger: console.log, // optional
//alexaServiceHost: 'pitangui.amazon.com', // optional, e.g. "pitangui.amazon.com" for amazon.com, default is "layla.amazon.de"
// userAgent: '...', // optional, override used user-Agent for all Requests and Cookie determination
// acceptLanguage: '...', // optional, override Accept-Language-Header for cookie determination
// amazonPage: '...', // optional, override Amazon-Login-Page for cookie determination and referer for requests
useWsMqtt: true, // optional, true to use the Websocket/MQTT direct push connection
cookieRefreshInterval: 7*24*60*1000, // optional, cookie refresh intervall, set to 0 to disable refresh
formerDataStorePath: storage_box+"alexa.baseic_info", // optional: overwrite path where some of the formerRegistrationData are persisted to optimize against Amazon security measures
formerRegistrationData: Alexa_cookie_data, // optional/preferred: provide the result object from subsequent proxy usages here and some generated data will be reused for next proxy call too
macDms: Alexa_macDms, // required since version 4.0 to use Push connection! Is returned in cookieData.macDms
},
async function (err) {
if (err) {
console.log (err);
return;
}
// write cookie data to disk
fs.writeFileSync(storage_box+'alexa.cookie', JSON.stringify(alexa.cookie));
fs.writeFileSync(storage_box+'alexa.cookieData.macDms', JSON.stringify(alexa.cookieData.macDms));
fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData));
//fs.writeFileSync(storage_box+'alexa.cookieData', JSON.stringify(alexa.cookieData['loginCookie']));
// console.log(JSON.stringify(alexa.cookie));
// console.log(JSON.stringify(alexa.csrf));
// console.log(JSON.stringify(alexa.cookieData));
// console.log(alexa);
for (let deviceSerial of Object.keys(alexa.serialNumbers)) {
// console.log (deviceSerial);
}
console.log("\n sending command....");
}
);
from alexa-remote.
So you did the procexy process with the lib and now you get a 401? No idea what you do wrong ... please verify (maybe by logging) that the data are really the corrct one .. becaue 401 means that the cookie is not a valid session ... so something is strange
from alexa-remote.
So you did the procexy process with the lib and now you get a 401? No idea what you do wrong ... please verify (maybe by logging) that the data are really the corrct one .. becaue 401 means that the cookie is not a valid session ... so something is strange
ya logins creds are valid because when script ask to visit http://localhost:3001/
and i visit webpage and login then it fetch cookie and the script start working ok but on next restart it give 401 error with same saved cookie
from alexa-remote.
ok so finally problem is solved. now am not getting 401 unauthroized error.
after playing with it , i found cause of it , cause was : macDms dumped data. so by just passing macDms = "" blank not getting anymore 401.
thanks for the amazing support :)
from alexa-remote.
one another question how to get and parse Alexa reply , like if i ask alexa what time is it
alexa.sendSequenceCommand(device_id, 'textCommand', 'What time is it', (err, res) => {
console.log("command sent...");
console.log(res);
})
currently console.log(res);
is just displaying { success: true }
i guess here i should see alexa response that time is xxxxxxxxx
from alexa-remote.
Related Issues (20)
- Reminder time is time only. Expected: Date+ Time HOT 1
- Unable to generate cookie, getting 404 (not found) HOT 4
- retrieve shopping list HOT 2
- Stay logged in HOT 2
- Allow to edit Routines
- Alexa sendSequenceCommand speak/ssml dosn't work HOT 3
- No activity triggered anymore HOT 2
- Exponential Backoff Reconnect Logic is Incorrect HOT 1
- Alexa web page localhost:3456 don't have hte username and password fields for login HOT 2
- TuneIn starting do not work anymore
- Remove getActivities because API disabled HOT 3
- no csrf found HOT 2
- notification (timer) HOT 2
- simulate whispering textcommand to alexa HOT 1
- getCustomerHistoryRecords error 500 HOT 7
- failed to load notifications: "no body HOT 1
- Notes/comment on a list item HOT 3
- Add list from todo HOT 1
- Sorry...we couldn't find that page HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alexa-remote.