const request = require('request'); const util = require('util'); const post = util.promisify(request.post); const { Autohook } = require('twitter-autohook'); (async start => { try { const webhook = new Autohook(); // Removes existing webhooks await webhook.removeWebhooks(); // Starts a server and adds a new webhook await webhook.start(); // Subscribes to your own user's activity await webhook.subscribe({oauth_token: process.env.TWITTER_ACCESS_TOKEN, oauth_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET}); webhook.on('event', async event => { await forwardToPHP(event); }); } catch (e) { // Display the error and quit console.error(e); process.exit(1); } })(); async function forwardToPHP(event) { var runner = require("child_process"); var phpScriptPath = "/root/nanobot/main/callbacks.php"; var jsonData = JSON.stringify(event); var fs = require('fs'); var file_name = 'data.json'; var file_name = 'data_' + Math.floor(Math.random() * Math.floor(100)) + '.json'; var args = file_name; await fs.writeFileSync('/root/nanobot/main/'+file_name, jsonData, 'utf8', function(){}); try { let output = await runner.execSync("php " + phpScriptPath + " " +args).toString(); if(output && output.length > 0) console.log(output); } catch(e) { } }