diff --git a/package-lock.json b/package-lock.json index db3f695..d695536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "express-validator": "^7.0.1", "pm2": "^5.3.0", "qrcode": "^1.5.3", - "qrcode-terminal": "^0.12.0" + "qrcode-terminal": "^0.12.0", + "typescript": "^5.2.2" }, "devDependencies": { "@types/cors": "^2.8.13", @@ -4178,8 +4179,6 @@ "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/src/controller/messageController.ts b/src/controller/messageController.ts index b2337d9..4f79bf8 100644 --- a/src/controller/messageController.ts +++ b/src/controller/messageController.ts @@ -1,22 +1,23 @@ -import { Request, Response } from "express"; +import { Request, Response, application } from "express"; import { getSession, jidExist } from "../wa"; import { logger } from "../shared"; import { proto } from "@whiskeysockets/baileys"; import { delay as delayMS } from "@whiskeysockets/baileys"; const messageController = { - send: async (req:Request, res:Response) => { + send: async (req:Request, res:Response, ) => { try { const { jid, type = 'number', message, options } = req.body; + const newMsg = { text : `Following msg was sent to the ${jid.slice(2,12)} \n ${message.text}` } // @ts-ignore const session = getSession(req.query.sessionId); - // console.log(session) const exists = await jidExist(session, jid, type); if (!exists) return res.status(400).json({ error: 'JID does not exists' }); - console.log('sending message') + console.log('sending message') + // console.log(); const result = await session.sendMessage(jid, message, options); - - res.status(200).json(result); + const msgSelf = await session.sendMessage(session.user.id, newMsg, options) + res.status(200).json({result, msgSelf}); } catch (error) { const message = 'An error occured during message send'; @@ -28,6 +29,7 @@ const messageController = { let sessionId:any = req.query.sessionId; const session = getSession(sessionId)!; const results: { index: number; result: proto.WebMessageInfo | undefined }[] = []; + const selfMsgResults : { index: number; selfMsgresult: proto.WebMessageInfo | undefined }[] = []; const errors: { index: number; error: string }[] = []; for (const [ index, @@ -41,8 +43,11 @@ const messageController = { } if (index > 0) await delayMS(delay); + const newMsg = { text : ` \n Following msg was sent to the ${jid.slice(2,12)} \n \n ${message.text}` } const result = await session.sendMessage(jid, message, options); + const selfMsgresult = await session.sendMessage(session.user.id, newMsg, options); results.push({ index, result }); + selfMsgResults.push({ index, selfMsgresult }); } catch (e) { const message = 'An error occured during message send'; logger.error(e, message); @@ -52,8 +57,8 @@ const messageController = { res .status(req.body.length !== 0 && errors.length === req.body.length ? 500 : 200) - .json({ results, errors }); - } + .json({ results, selfMsgResults, errors }); + }, } export default messageController; \ No newline at end of file diff --git a/src/wa.ts b/src/wa.ts index a9fee4c..4b03b0f 100644 --- a/src/wa.ts +++ b/src/wa.ts @@ -1,4 +1,4 @@ -import makeWASocket, { AnyMessageContent, AuthenticationCreds, ConnectionState, DisconnectReason, SocketConfig, delay, fetchLatestBaileysVersion, initAuthCreds, makeCacheableSignalKeyStore, useMultiFileAuthState } from "@whiskeysockets/baileys"; +import makeWASocket, { ConnectionState, DisconnectReason, SocketConfig, fetchLatestBaileysVersion, makeCacheableSignalKeyStore } from "@whiskeysockets/baileys"; import { Boom } from '@hapi/boom'; import { Response } from "express"; import { logger, prisma } from "./shared";