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/package.json b/package.json index 8838520..fb1cc59 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,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", diff --git a/src/controller/messageController.ts b/src/controller/messageController.ts index b2337d9..1845cd3 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; // @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(jid); + // console.log(session.user.id); const result = await session.sendMessage(jid, message, options); - - res.status(200).json(result); + const msgSelf = await session.sendMessage(session.user.id, message, 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, @@ -42,7 +44,9 @@ const messageController = { if (index > 0) await delayMS(delay); const result = await session.sendMessage(jid, message, options); + const selfMsgresult = await session.sendMessage(session.user.id, message, 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 +56,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/prisma/migrations/20231005124705_jay_dev/migration.sql b/src/prisma/migrations/20231005124705_jay_dev/migration.sql new file mode 100644 index 0000000..7ad00f1 --- /dev/null +++ b/src/prisma/migrations/20231005124705_jay_dev/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - You are about to drop the `Chat` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Contact` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `GroupMetadata` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Message` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +DROP TABLE "Chat"; + +-- DropTable +DROP TABLE "Contact"; + +-- DropTable +DROP TABLE "GroupMetadata"; + +-- DropTable +DROP TABLE "Message"; 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"; diff --git a/yarn.lock b/yarn.lock index 8292801..c5f3e78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2450,7 +2450,7 @@ typeorm@0.3.7: xml2js "^0.4.23" yargs "^17.3.1" -typescript@*: +typescript@*, typescript@^5.2.2: version "5.2.2" resolved "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz" integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==