I'm trying to access a local variable outside the function since a few hours. I don't know where my mistakes is. The code looks like:
Edited code:
  if (lastMsg.toUpperCase().indexOf("@TEST") > -1) { 
     var myPythonScriptPath = 'my_script.py';
     var myMessage = ''; 
      // Use python shell
      const {PythonShell} = require("python-shell");
      var pyshell = new PythonShell(myPythonScriptPath);
      pyshell.on('message', function (message) {
          // received a message sent from the Python script (a simple "print" statement)
          console.log(message);
          myMessage = message;
      });
      // end the input stream and allow the process to exit
      pyshell.end(function (err) {
          if (err){
          throw err;
          };
      });
          sendText = `${myMessage};`
As a result, the variable ${message} is "undefined". The code works by itself, but inside the if statement I can't see the output of the message. How to fix that?
