quickest-silver•2y ago
{last_response} is undefined (Stack error message in post)
Added the javascript code to the post. It's a regular javascript block.
This however does not happen during testing, only on production.
This is the error message:
Stacks: "ReferenceError: last_response is not defined\n at vm.js:208:31\n at vm.js:236:3\n at Script.runInContext (vm.js:130:18)\n at /var/task/node_modules/vm2/lib/main.js:941:53\n at timeout_bridge.js:1:1\n at Script.runInContext (vm.js:130:18)\n at doWithTimeout (/var/task/node_modules/vm2/lib/main.js:537:17)\n at VM.run (/var/task/node_modules/vm2/lib/main.js:939:10)\n at exports.vmExecute (/var/task/node_modules/@voiceflow/runtime/build/lib/Handlers/code/utils.js:26:8)\n at Runtime.module.exports.execute [as handler] (/var/task/handler.js:27:20)"
5 Replies
The error message you're encountering,
ReferenceError: last_response is not defined
, is a common JavaScript error that occurs when you try to use a variable that has not been declared or initialized. In Voiceflow, if an existing variable is not set by the time the Code Step begins executing, the value of that variable is 0
. If the Code Step attempts to execute a method on a variable that is not yet set, a TypeError will occur.
In your case, it seems like the variable last_response
is not defined before it's being used in your code. Please ensure that last_response
is properly initialized before it's used in your code.
Remember, Code Steps in Voiceflow cannot be used to create new variables. Any variables that you want to use after the Code Step is executed must already exist before being referenced in the Code Step.
Also, it's worth noting that the Code Step supports ES6, so make sure your code is compatible with this version of JavaScript.
Sources:
- Voiceflow Documentation
- JavaScript Error Referencecorrect-apricot•2y ago
Hm @NiKo | Voiceflow do you know if there are any reasons why last_response is not defined in prod but it is when testing?
@Adam [Astro System] let us know if you are able to validate that this is occuring when you use the Voiceflow native webchat aswell
You might want to initialize it in the beginning of your flow (right after the start block).
Use a set step to initialize it to 0 for example.
Let us know if it fix the issue on your end.
@NiKo | Voiceflow @Daniel I saw an issue with last_response last week were it was set to NULL. There was an error in the flow earlier and last_response was being set to NULL.
This should be solved with the new variables view and the default value setting 👍