Skip to content

Commit

Permalink
Tried to send msg through child process not working rn
Browse files Browse the repository at this point in the history
  • Loading branch information
JAYBORICHA07 committed Feb 15, 2024
1 parent acc45c5 commit 2d2bafc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/utils/child_process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios';

process.stdin.setEncoding('utf8');

process.stdin.on('data', async (data) => {
const requestData = JSON.parse(data);

try {
const response = await axios(requestData);
console.log(response.data);
} catch (error) {
console.error('Error sending data:', error);
}
});
35 changes: 24 additions & 11 deletions src/utils/sendDataSAbackend.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import axios from 'axios'
import { messageDataType } from '../types'
import { spawn } from 'child_process';
import axios from 'axios';
import { messageDataType } from '../types';


export const sendDataSAbackend = async (messageData : messageDataType) => {
const apiUrl = ``
export const sendDataSAbackend = async (messageData: messageDataType) => {
const apiUrl = 'YOUR_BACKEND_ENDPOINT_URL';

const body = {
method : 'post',
url : apiUrl,
data : messageData,
headers : ''
}
}
method: 'post',
url: apiUrl,
data: messageData,
headers: { 'Content-Type': 'application/json' } // Assuming JSON data
};

const child = spawn('node', ['child_process.js'], { stdio: 'inherit' }); // Spawning child process

child.on('exit', (code) => {
console.log(`Child process exited with code ${code}`);
});

child.on('error', (err) => {
console.error('Failed to start subprocess.', err);
});

child?.stdin?.write(JSON.stringify(body)); // Sending data to child process
child?.stdin?.end();
};
4 changes: 3 additions & 1 deletion src/wa.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import makeWASocket, { ConnectionState, DisconnectReason, SocketConfig, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, downloadMediaMessage } from "@whiskeysockets/baileys";
import makeWASocket, { ConnectionState, DisconnectReason, SocketConfig, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, downloadMediaMessage, mediaMessageSHA256B64 } from "@whiskeysockets/baileys";
import { Boom } from '@hapi/boom';
import { Response } from "express";
import { logger, prisma } from "./shared";
Expand Down Expand Up @@ -224,13 +224,15 @@ export async function createSession(options:createSessionOptions) {
messageData.caption = msg?.message?.imageMessage?.caption;
messageData.timestamp = (msg.messageTimestamp)?.toString()!;
sendDataSAbackend(messageData);
console.log(messageData);
// @ts-ignore
// await writeFile('./demo.jpeg', Buffer.from(buffer, 'binary').toString('base64')).then(()=>{console.log("image-generated")});
}
else if(messageType == 'conversation' || messageType == 'extendedTextMessage'){
messageData.phoneNumber = msg.key.remoteJid!.slice(2,12);
messageData.message = msg.message?.conversation;
messageData.timestamp = (msg.messageTimestamp)?.toString()!;
console.log(messageData);
sendDataSAbackend(messageData);
}
}
Expand Down

0 comments on commit 2d2bafc

Please sign in to comment.