How to return JSON response in ssh2 nodejs after successfull job completion

267 views Asked by At

I want to do some task on a remote server. But I am not getting valid JSON response. I tried various way to get rich JSON response but it is not working.

Here is Google intent, I just want to deploy on a remote server via Google Assistant:

    async  DoDeployIntent() {

            const status = await doFullDeploy();
            console.log(status);
            this.tell(status);
    }
    //Here is ssh connection
    ssh.connect({
        host: '35.239.181.109',
        port: 22,
        username: 'common_dkumar',
        passphrase: '12345',
        privateKey: './ssh/id_rsa'
    });


    //Here is Async function:
    const doFullDeploy = async () => {
        return JSON.stringify(ssh.execCommand('sudo php bin/magento s:up', {cwd: '/var/www/html'}).then(function (result) {
            if (result.stdout) {
                return JSON.stringify('Deploy Success');
            }
            if (result.stderr) {
                return JSON.stringify('Deploy Failed');
            }
        }))
    }

My issue is that I'm not getting a valid JSON rich response on task done or fail. I also tried the following, but I did not get a valid JSON response.

    const doFullDeploy = async () => {
        var Client = require('ssh2').Client;
        var conn = new Client();
        return conn.on('ready', function () {
            conn.exec('sudo php /var/www/html/bin/magento deploy:mode:show', function (err, stream) {
                return JSON.stringify('Maintence Mode Enable Failed');
            });
        }).connect({
            host: '35.239.181.109',
            port: 22,
            username: 'common_dkumar',
            passphrase: '12345',
            privateKey: require('fs').readFileSync('./ssh/id_rsa')
        });
    }

Digi flow error:

Failed to parse Dialogflow response into AppResponse because of
invalid platform response: Could not find a RichResponse or
SystemIntent in the platform response for agentId:
54e79a5d-97f9-49f4-981d-da0528d9e8fa and intentId:
181fa007-e5b8-4866-b8ca-6fbcb53c4f6b. WebhookStatus: message: "Webhook
execution successful" .
0

There are 0 answers