ReferenceError: результат не определен в node js - PullRequest
0 голосов
/ 04 апреля 2020

Я реализую чат-бота, который предоставляет некоторую информацию, основанную на пользовательском вводе. Я вызываю сценарий python через узел и получаю данные. Я сталкиваюсь с этой ошибкой при попытке отправить эти данные обратно в Slack. Я не уверен, как отправить данные из одной функции asyn c в другую или как отозвать результат в processTextAndRespond. Вот ошибка, которую я получаю -

An error occurred ReferenceError: result is not defined
    at postMessage (C:\Users\)
    at processTextAndRespond

Вот код:

rtm.on('message', (event) => {
    // console.log(event);
    if(!event.subtype){

        processTextAndRespond(event.text,event.user,event);

    }else{
        console.log('nothing to do !!!');
    }
});

const processTextAndRespond = async function(userText,userName,event){
    processData(userText);

    postMessage(answer);

};

const postMessage = async function(answer,event){
try {

console.log("Working");
       processData(result);
       const answer = await rtm.sendMessage(result, event.channel);
       return answer;
} catch (error) {
    console.log('An error occurred', error);
  }
};

const processData = async function(userText,result) {
   const childProcess = require("child_process").spawn('python', ['./search.py', userText], {stdio: 'inherit'})
    childProcess.on('data', function (data) {
         process.stdout.on("python script output", data)
              result = data.toString()


...