bklavet / Echo-skill-to-control-Directv

amazon echo skill that will control a networked Directv Receiver so that users can control Directv with their voice
18 stars 67 forks source link

getTuned getProgInfo... #7

Closed bklavet closed 7 years ago

bklavet commented 8 years ago

Maybe someone can help with this. I think it would be great to be able to ask alexa to retrieve the current program info (getTuned) and have the lambda function parse the JSON response and send the parsed information back to alexa. exp. Get Tuned - http://STBIP:port/tv/getTuned

I think there would also be some added value to be able to ask about other program information without changing to that channel, (getProgInfo). I would like to eventually be able to ask about program information based on time. exp. "what is on CNN/202 at 10:00 today?" Get Program Info - http://STBIP:port/tv/getProgInfo?major=202[&minor=65535][&time=2200]

I am not sure how to parse the response, Does anyone have any ideas on how?

vmweaver commented 8 years ago

Interesting. I may have to look at that. On Jun 15, 2016 12:44 PM, "B money" notifications@github.com wrote:

Maybe someone can help with this. I think it would be great to be able to ask alexa to retrieve the current program info (getTuned) and have the lambda function parse the JSON response and send the parsed information back to alexa. exp. Get Tuned - http://STBIP:port/tv/getTuned

I think there would also be some added value to be able to ask about other program information without changing to that channel, (getProgInfo). I would like to eventually be able to ask about program information based on time. exp. "what is on CNN/202 at 10:00 today?" Get Program Info - http://STBIP:port /tv/getProgInfo?major=202[&minor=65535][&time=2200]

I am not sure how to parse the response, Does anyone have any ideas on how?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/7, or mute the thread https://github.com/notifications/unsubscribe/ACibPegPcmsZJzbIIBhRh3n74ZVXnQKKks5qMDnKgaJpZM4I2nUh .

bklavet commented 7 years ago

found a cool video on youtube: this is his github https://github.com/AlwaysBCoding/Episodes/blob/master/amazon-echo/lambda-function.js

and was looking at modifying this to maybe get the desired affect

case "GetVideoViewCountSinceDate": console.log(event.request.intent.slots.SinceDate.value) var endpoint = "" // ENDPOINT GOES HERE var body = "" https.get(endpoint, (response) => { response.on('data', (chunk) => { body += chunk }) response.on('end', () => { var data = JSON.parse(body) var viewCount = data.items[0].statistics.viewCount context.succeed( generateResponse( buildSpeechletResponse(Current view count is ${viewCount}, true), {} ) ) }) }) break;

for the /tv/getTuned command, this comes back from the reciever (note my receiver was not on so nothing showed up, but this is the format of the JS response { "callsign": "", "duration": 0, "isPclocked": 0, "isPpv": false, "isRecording": false, "isVod": false, "major": 0, "minor": 0, "programId": "", "rating": "", "startTime": 0, "status": { "code": 500, "commandResult": 1, "msg": "The requested program does not exist.", "query": "/tv/getTuned" }, "title": "" }

So maybe the getTuned argument could look something like this? case "what is this": console.log(event.request.intent.slots.Program.value) var endpoint = "/tv/getTuned" // ENDPOINT GOES HERE var body = "" var options = { host: local_ip, port: 8080, // default port for DTV interface path: '' + endpoint, // Modify if path is prefixed method: 'GET' } http.get(options, (response) => { response.on('data', (chunk) => { body += chunk }) response.on('end', () => { var data = JSON.parse(body) var title = data.items[0].title context.succeed( generateResponse( buildSpeechletResponse(Current view count is ${title}, true), {} ) ) }) }) break;

Would something along these lines produce the title of the current program? any help would be appreciated greatly!

bklavet commented 7 years ago

added a folder on the main page named "future" , showing my misgivings with JSON.parse... I have broken down the Index file for now to only give the title of the show currently being watched. This seemed like a good approach. Figure out how to JSON.parse the JSON string the Directv's server is giving. If I can sort out how to get the title, then ratings, network name, channel, and a bunch of other information could be received from the alexa skill.

If anyone would like to take a look, and give me their coding expertise, it would be GREAT.

vmweaver commented 7 years ago

​I am not in a position to fully test this, but I think "var title = data.items[0].title"​ should be "var title = data.episodeTitle"

I just did some quick testing on it and that seems to pull back the proper title info.

On Thu, Feb 9, 2017 at 3:58 PM, B money notifications@github.com wrote:

added a folder on the main page named "future" , showing my misgivings with JSON.parse... I have broken down the Index file for now to only give the title of the show currently being watched. This seemed like a good approach. Figure out how to JSON.parse the JSON string the Directv's server is giving. If I can sort out how to get the title, then ratings, network name, channel, and a bunch of other information could be received from the alexa skill.

If anyone would like to take a look, and give me their coding expertise, it would be GREAT.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/7#issuecomment-278787253, or mute the thread https://github.com/notifications/unsubscribe-auth/ACibPfsSiLD-_qYCUAMPsBqygI3QfbIfks5ra4v9gaJpZM4I2nUh .

vmweaver commented 7 years ago

Or maybe just "data.title". My dtv returns both.

Sent from my iPad

On Feb 9, 2017, at 9:44 PM, Mark Weaver geekweaver@gmail.com wrote:

​I am not in a position to fully test this, but I think "var title = data.items[0].title"​ should be "var title = data.episodeTitle"

I just did some quick testing on it and that seems to pull back the proper title info.

On Thu, Feb 9, 2017 at 3:58 PM, B money notifications@github.com wrote: added a folder on the main page named "future" , showing my misgivings with JSON.parse... I have broken down the Index file for now to only give the title of the show currently being watched. This seemed like a good approach. Figure out how to JSON.parse the JSON string the Directv's server is giving. If I can sort out how to get the title, then ratings, network name, channel, and a bunch of other information could be received from the alexa skill.

If anyone would like to take a look, and give me their coding expertise, it would be GREAT.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

bklavet commented 7 years ago

Hey friend,  Just to clarify are you testing with the index file in the future folder? Yesterday I changed the var title = data.items[0].titel to var title = data.title, but have not updated my test skill to reflect it.

vmweaver commented 7 years ago

I was just testing the nodejs code on my laptop since the json parsing should be the same. Will try the skill code later today if possible.

On Feb 10, 2017 8:51 AM, "B money" notifications@github.com wrote:

Hey friend, Just to clarify are you testing with the index file in the future folder? Yesterday I changed the var title = data.items[0].titel to var title = data.title, but have not updated my test skill to reflect it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/7#issuecomment-278962135, or mute the thread https://github.com/notifications/unsubscribe-auth/ACibPYtZzkZvwl_p6il0wIAg_7B7oTgHks5rbHkQgaJpZM4I2nUh .

bklavet commented 7 years ago

Thanks mawrew19 , I am uploading the index in the "future" folder now to see if I can get it to do something other than a remote endpoint error. Will add to this if I come up with anything constructive. Appreciate your help!

weiljx commented 7 years ago

I decided to give this a go tonight and within about an hour I was up and running! Thanks!!! I too think being able to ask what is on a specific channel would be a great feature. Hopefully I can get it all figured out this weekend. I added an additional custom slot called GuideInfo and the corresponding Sample Utterances I am currently trying to figure out how to pick up the custom slot type that alexa picks up to route the functions accordingly. If I get this working I will contribute back! Thanks again

bklavet commented 7 years ago

Wow! This is encouraging! Thanks for posting

weiljx commented 7 years ago

Made major progress today. I refactored the original code and added the functionality requested. You can now use Alexa ask TV what show is this? Or Alexa ask TV what show is on CBS? Or Alexa ask TV what show is on 246. Additionally I added some new synonyms for control features and added channels to the channel line up. I need to reach out to the moderator so that I can get this version checked in. Thanks - Josh

bklavet commented 7 years ago

Hello Josh! Want to do a pull request so I can see what you have? It was great to read your post!

weiljx commented 7 years ago

bklavet, I just did the pull request let me know if you need anything else from me :)

bklavet commented 7 years ago

I merged the pull request! Looking forward to trying it out when I get the kid's back to school and get work caught up. This looks great!

bklavet commented 7 years ago

weiljx, Amaizing! Astounding! Incredible!.... did I say Amaizing?

Great Job! Works perfectly in the service simulator at the developer portal, will try it out when I get home.

I like what you did with the Index file. I am going to stare at it a little more, as it is almost unrecognizable to me. Thanks a million for your contribution to this. I think it is a vast improvement, and I greatly appreciate you for taking the time to do it!

weiljx commented 7 years ago

Glad you like it bklavet your efforts made this much easier to achieve.

bklavet commented 7 years ago

What I am really digging about the GuideInfo is that it looks like the perfect roadmap for other things the json response gives aswell, like the "ratings, Callsign, isRecording, major".

bklavet commented 7 years ago

Can you picture having a dialogue with alexa like this? user: Alexa, ask the [Invocation], am I recording this show? Alexa: No, would you like to? user: yes. Alexa: alexa sends the "record" remote command. then responds with "ok".

weiljx commented 7 years ago

Great Ideas. Guess I need to find some more time :)

bklavet commented 7 years ago

Morning weiljx, // This function gets the title from guide requests and calls a function to send the title back function getJSON(url, callback){ request.get(url, function(error, response, body){ var d = JSON.parse(body); var title = d.title; if(title !== undefined){ callback(title); } else{ callback("ERROR"); } }); } I was thinking maybe a switch case argument could be set up so that different control slot values could result in different pieces of the json response being parsed out. That way we would only need to add key words to the Guide_Info slot. The index would match the key words is a switch case argument create the varibles for the callback function. `var url = "http://" + local_ip + ":" + port + pathPrefix + path;

        getJSON(url, function(title){
            if(title !== "ERROR"){
                var respondWith = title + "is currently on.";                   
                response.tell(respondWith);
            }
        });`

then add some if and else if stuff to give the correct response.

I am missing something here. though, I can't seem to figure out how the custom slot Guide_Info is pulling your title callback function. I keep thinking I should be able to see a word like "show" that is in the custom slot value and see where the index grabs that and knows what to do, but so far I can't find it.

weiljx commented 7 years ago

bklavet you will need to update the interperateCommand function line 292 to pass guideInfoValue into getGuideInfo(controlValue, guideInfoValue) then update the getGuideInfo function to take the second parameter guideInfoValue witch will contain the word you used in the slot. Hope this helps :)

weiljx commented 7 years ago

Did the above help Bklavet or do you need me to help out more?

bklavet commented 7 years ago

It did weiljx! I will close this out. Thanks again!