Author Topic: Mysteriously resolved user error  (Read 3774 times)

0 Members and 3 Guests are viewing this topic.

RedDragonManor

  • Jr. Member
  • **
  • Posts: 8
  • Karma: -1
    • View Profile
Mysteriously resolved user error
« on: March 23, 2017, 06:28:49 PM »
I'm needing a little help  with coding for setting up Vox commando. I don't know what  else to try.  I have went over and over the instructions  and followed everything step  by  step. I have even  had a friend of mine look  at it and were both  a little stumped. I keep  get and error message
{
  "errorMessage": "Exception: TypeError: Cannot read property 'new' of undefined"
}

The tutorial and even  the written  instructions say  something about this but it has something to do  with  line 18  in  the code but the instructions  say nothing about it its like it cant read this part like its wanting a value of some kind any help  would be most appreciative yours truly Paul  thanks in advanced


exports.handler = function (event, context) {
    try {
          if (event.session.new)
            onSessionStarted({requestId: event.request.requestId}, event.session);
        }
        if (event.request.type === "LaunchRequest") {
            onLaunch(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                        context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        }  else if (event.request.type === "IntentRequest") {
            onIntent(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                         context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        } else if (event.request.type === "SessionEndedRequest") {
            onSessionEnded(event.request, event.session);
            context.succeed();
        }
    } catch (e) {
        context.fail("Exception: " + e);
    }

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Mysteriously resolved user error
« Reply #1 on: March 24, 2017, 02:40:03 AM »
Hi RedDragonManor and welcome to the Forum.

We are missing some information:

1. What is your current VC version?
2. Which steps have you followed?


     a) http://voxcommando.com/forum/index.php?topic=2682.msg22997#msg22997
     b) http://voxcommando.com/forum/index.php?topic=2682.msg23144#msg23144
« Last Edit: March 24, 2017, 08:29:02 AM by jitterjames »
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Mysteriously resolved user error
« Reply #2 on: March 24, 2017, 08:26:23 AM »
It also looks like you've only posted a small portion of the code which is generating the error. Please also put it in a code box on the forum using the # button above and make sure you post the exact code you are using.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Mysteriously resolved user error
« Reply #3 on: March 24, 2017, 01:43:07 PM »
exports.handler = function (event, context) {
    try {
          if (event.session.new)
            onSessionStarted({requestId: event.request.requestId}, event.session);
        }
 ...

As James mentions, without seeing your entire script, there's no way to identify all the possible typos/errors, but just looking at the snippet you posted, relative to the complete, original script posted in this thread, I see a missing opening { in your first if statement.

It should be:
Code: [Select]
exports.handler = function (event, context) {
    try {
        if (event.session.new) {
            onSessionStarted({requestId: event.request.requestId}, event.session);
        }
...


The best thing would be to start again, copy and pasting the original code provided in this tutorial thread.
« Last Edit: March 24, 2017, 03:24:15 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

RedDragonManor

  • Jr. Member
  • **
  • Posts: 8
  • Karma: -1
    • View Profile
Re: Mysteriously resolved user error
« Reply #4 on: March 24, 2017, 09:44:04 PM »
Here's the entire code I'm also using version The current stable version is 2.2.3.5 and the only other version is the latest beta version

Code: [Select]
/*
****** Pulls speech input and passes on to Voxcommando for custom events *****
*/
var http = require('http');

var VC_ip = 'xx.xxx.xx.x'; // Add your WAN IP or DynDNS Host here
var VC_Port = '8096'; // Add the Port VC is listening to here
var VC_Event = 'EchoToVC'; // The name of the event which is created in VC
var EchoName = 'Room1'; // You can give your Echo a name here, which is transmitted as payload2 to VC. If you have more than one Echo this could
// be used to distinguish which Echo is sending the command to VC. To make us of this you would need to have one skill for each
// Echo, which unfortunately also means that each Echo needs to be assigned to a different Amazon account.
// Hopefully this can be replaced by the actual device name or ID at some time, but currently there is no way to do it.

var Echo_App_ID = " amzn1.ask.skill.e040c396-1abc-416e-b255-43178a6e0822";  // Add your Echo App ID here

exports.handler = function (event, context) {
    try {
        if (event.session.new) {
            onSessionStarted({requestId: event.request.requestId}, event.session);
        }
        if (event.request.type === "LaunchRequest") {
            onLaunch(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                        context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        }  else if (event.request.type === "IntentRequest") {
            onIntent(event.request,
                     event.session,
                     function callback(sessionAttributes, speechletResponse) {
                         context.succeed(buildResponse(sessionAttributes, speechletResponse));
                     });
        } else if (event.request.type === "SessionEndedRequest") {
            onSessionEnded(event.request, event.session);
            context.succeed();
        }
    } catch (e) {
        context.fail("Exception: " + e);
    }
};

/**
 * Called when the session starts.
 */
function onSessionStarted(sessionStartedRequest, session) {}

/**
 * Called when the user launches the skill without specifying what they want.
 */
function onLaunch(launchRequest, session, callback) {
    // Dispatch to your skill's launch.
    getWelcomeResponse(callback);
}

/**
 * Called when the user specifies an intent for this skill.
 */
function onIntent(intentRequest, session, callback) {
    var intent = intentRequest.intent,
        intentName = intentRequest.intent.name;
    callEchoToVC(intent, session, callback); // Whatever the Intent is, pass it straight through to VC
}

/**
 * Called when the user ends the session.
 * Is not called when the skill returns shouldEndSession=true.
 */
function onSessionEnded(sessionEndedRequest, session) {
}

// --------------- Main Intent Processing Function ----------------

function callEchoToVC(intent, session, callback)
{
    var sessionAttributes = "{}";
    var cardTitle = EchoName;
    var shouldEndSession = true;

    var payload = "";
    var speechOutput = "";
    var repromptText = "I could not understand, please try again";
    var i = 0;
    var slots = intent.slots;
   
    //Pull the spoken text and format
    var actionSlot = intent.slots.Action;
    var setAction = actionSlot.value.toLowerCase();
    var setActionURI = require('querystring').escape(setAction);

    var VC_uri = '/api/VC.TriggerEvent&&EchoToVC&&' + setActionURI + '&&' + EchoName;
    var get_options = {
        host: VC_ip,
        port: VC_Port,
        path: VC_uri
    };
 
    // Set up the request
    var get_req = http.request(get_options, function(res) {
        var VC_results = "";
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            VC_results += chunk;
        });
        res.on('end', function () {
            if (res.statusCode === 200) {
                //Parse the Body results from VC, if the command was unknow we will repromt
                if((VC_results.indexOf('intent: UNKNOWN') > -1)||(VC_results.indexOf('cmd is unknown:') > -1)) {
                     shouldEndSession=false;
                } else {
                    if(VC_results.indexOf('Return Msg: ') > -1) {
                        var lines = VC_results.split('\n');
                        for(var i = 0;i < lines.length;i++){
                            if(lines[i].indexOf('Return Msg: ') > -1) {
                                var rtn_msg = lines[i].split('Msg:')[1].trim();
                                if (rtn_msg !== '') {
                                    setAction = rtn_msg;
                                }
                            }
                        }
                    }
                }
            }
            callback(sessionAttributes,
                buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession)); //Pass stingResult instead of speechOutput for debugging if needed
        });
    });
    get_req.on('error', function (e) {
        callback(sessionAttributes,
            buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
    });
    get_req.end();   
}

// --------------- WelcomResponse Function ----------------

function getWelcomeResponse(callback) {
    // If we wanted to initialize the session to have some attributes we could add those here.
    var sessionAttributes = {};
    var cardTitle = "Welcome to Echo To Voxcommando";
    var speechOutput = "Hello, I'm this home's automation AI, what can I do for you";

    // If the user either does not reply to the welcome message or says something that is not
    // understood, they will be prompted again with this text.
    var repromptText = "I could not understand, please try again";
    var shouldEndSession = false;
    callback(sessionAttributes,
             buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}

// --------------- Helper Functions ----------------

function buildSpeechletResponse(title, output, repromptText, shouldEndSession) {
    return {
        outputSpeech: {
            type: "PlainText",
            text: output
        },
        card: {
            type: "Simple",
            title: "EchoToVoxcommando - " + title,
            content: output
        },
        reprompt: {
            outputSpeech: {
                type: "PlainText",
                text: repromptText
            }
        },
        shouldEndSession: shouldEndSession
    };
}

function buildResponse(sessionAttributes, speechletResponse) {
    return {
        version: "1.0",
        sessionAttributes: sessionAttributes,
        response: speechletResponse
    };
}
« Last Edit: March 24, 2017, 10:26:55 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Mysteriously resolved user error
« Reply #5 on: March 25, 2017, 08:58:53 AM »
I don't know if it's what is causing the error but you have an extra space in your Echo_App_ID which must be removed.

It could also be that you have failed to perform some other step outside of the actual code.

You need to use a valid IP address. Maybe you have done that and just changed it when you posted your code to the forum?

Also, in your original post you don't explain when, exactly, you're seeing this error. Is it when you're trying to save the code, or at some point after that?
« Last Edit: March 25, 2017, 09:07:25 AM by nime5ter »

RedDragonManor

  • Jr. Member
  • **
  • Posts: 8
  • Karma: -1
    • View Profile
Re: Mysteriously resolved user error
« Reply #6 on: March 25, 2017, 06:12:29 PM »
It was after I try  to save and test. Removing the extra space has now allowed me to save it,but when I try to test it. This is the message that shows up  at the bottom. I have attached a pic of what it shows

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Mysteriously resolved user error
« Reply #7 on: March 25, 2017, 06:22:02 PM »
Please correct me if I am wrong but neither the text nor video tutorial indicate that you should click "save and test" from that page.

You are essentially trying to test without any actual input and you have not yet continued on to the remaining steps.

So I suggest that you try again but you need to follow all the steps exactly and should not add any extra steps. If there is a specific step that you don't know how to follow then feel free to ask for more information but quote the exact original text of the step that you are having problems with.

RedDragonManor

  • Jr. Member
  • **
  • Posts: 8
  • Karma: -1
    • View Profile
Re: Mysteriously resolved user error
« Reply #8 on: March 25, 2017, 07:41:26 PM »
So  I guess that's what I will  do then  is just take everything out and start all  over. I know its something very simple I will  let you  know what happens

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Mysteriously resolved user error
« Reply #9 on: March 25, 2017, 09:12:11 PM »
Something simple like clicking save and test when you are not supposed to?  ::dis

But by all means start over if you think that will help. It doesn't take very long if you just follow the steps one at a time.

RedDragonManor

  • Jr. Member
  • **
  • Posts: 8
  • Karma: -1
    • View Profile
Re: Mysteriously resolved user error
« Reply #10 on: March 25, 2017, 10:09:07 PM »
Well I fixed it. It was so  simple. I don't know why  I didn't see from the the start. The problem was I didn't have it set for any where to go. Now I can have Alexa Tell Denise  to  open  google chrome through  Vox and it works. The problem was I didn't have a command set up  for it do  anything as far as Denise you  can  find out more about her here.
Guile will be releasing her 2.0 version which  will  include all her home automation features and more
« Last Edit: March 26, 2017, 08:28:39 AM by jitterjames »