Skip to content

Commit 0a5ac0b

Browse files
committed
feat: whatsapp connection now working with code
1 parent f1085c7 commit 0a5ac0b

File tree

9 files changed

+372
-113
lines changed

9 files changed

+372
-113
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@ dist
139139
tests/
140140
/src/generated/prisma
141141
.idea/
142-
auth_info_baileys/
142+
auth_info_baileys/
143+
sessions/

package-lock.json

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"main": "dist/server.js",
55
"scripts": {
6-
"dev": "npx nodemon --exec npx tsx src/server.ts",
6+
"dev": "npx nodemon --exec \"npx tsx src/server.ts | npx pino-pretty\"",
77
"build": "tsc",
88
"start": "node dist/server.js"
99
},
@@ -19,6 +19,7 @@
1919
"dotenv": "^17.2.0",
2020
"express": "^4.21.2",
2121
"jsonwebtoken": "^9.0.2",
22+
"pino-pretty": "^13.1.2",
2223
"qrcode-terminal": "^0.12.0",
2324
"twilio": "^5.7.3",
2425
"uuid": "^11.1.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"noiseKey":{"private":{"type":"Buffer","data":"4MDZsot4b1z9v506HzTUIbWeN+ScV6mm5cn8wXnIclo="},"public":{"type":"Buffer","data":"Gf3e/LG17uglcJ3Iymm5C30uGU/tINqCz14gf94V63A="}},"pairingEphemeralKeyPair":{"private":{"type":"Buffer","data":"eNo9pmOQ4XZSC2r8bmJACQ7vKaFB/zfEiI79ZUVw/ns="},"public":{"type":"Buffer","data":"SRhh21OSTjgaOXdknSuZzJN/X4eVxvFHEr8ZmMjVW0g="}},"signedIdentityKey":{"private":{"type":"Buffer","data":"6O763b15SarEmKSpH3blrEWYteIp73SD2WSXfEZ0l3U="},"public":{"type":"Buffer","data":"illZzvo6rDIO5JzTCFVpYY7Tc/VC/XT459hllO8UnWY="}},"signedPreKey":{"keyPair":{"private":{"type":"Buffer","data":"sIRwQ5rtLWF4UCrclA0hU9nPdo4G1UUiACBq+xSFSmY="},"public":{"type":"Buffer","data":"KfhuVOnj41EVlvhsYTM+ZMn177itpKjpouGgVhxiozo="}},"signature":{"type":"Buffer","data":"jXhQd5OitF64y/NS3++zxMpjpbPlYRJZ7j7roM6Mbxk82LjD92H0ES0r5dhAKGPnTw1RRHui3cfv1jfNpDQLgw=="},"keyId":1},"registrationId":244,"advSecretKey":"wB6nnLJfLPt1grW2A3MV+a94RIOzJWA6yXg/bp38KJw=","processedHistoryMessages":[],"nextPreKeyId":61,"firstUnuploadedPreKeyId":61,"accountSyncCounter":0,"accountSettings":{"unarchiveChats":false},"registered":true,"pairingCode":"RLFWYJZR","me":{"id":"918777489070:31@s.whatsapp.net","lid":"24352565260475:31@lid","name":"Akshit"},"account":{"details":"CPCVi+sKEPDDs8cGGAcgACgA","accountSignatureKey":"JJrUg6lPUpBEKjS7FgrYLdhE/cRaLk9yjnHYAMBieVk=","accountSignature":"w/S+olFVbF/Gr8T5R69T9p0jMiq9l4EQObjEKA2y1ScfLQnTj8kpfLnmsFI1+ZBaPIS5lcSpvz6LPTTqv9Ojjw==","deviceSignature":"cmtLbW79kz74GFtLUYVPu/aNhxRITKW4POsszBAB8ItgYwAQ3mEDekLQnoD7JDhGV7jw+Hc0CL31YGyjgHJwjg=="},"signalIdentities":[{"identifier":{"name":"918777489070:31@s.whatsapp.net","deviceId":0},"identifierKey":{"type":"Buffer","data":"BSSa1IOpT1KQRCo0uxYK2C3YRP3EWi5Pco5x2ADAYnlZ"}}],"platform":"iphone","routingInfo":{"type":"Buffer","data":"CA0IAg=="},"lastAccountSyncTimestamp":1760354804,"lastPropHash":"3fYwCK","myAppStateKeyId":"AAAAAOiX"}

src/routes/inviteRoutes.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -457,42 +457,35 @@ router.get('/:eventId/:groupId/status/:phoneNo', async (_req: Request, res: Resp
457457
});
458458

459459
router.post(
460-
'/send-invite/:eventId/:groupId',
461-
verifyIdToken,
462-
async (req: Request, res: Response) => {
463-
try {
464-
const { eventId, groupId } = req.params;
465-
const { name, phone_no } = req.body;
466-
const userId = req.userId;
467-
if (!userId) {
468-
res.status(401).json({ message: 'Unauthorized' });
469-
return;
470-
}
471-
472-
// Check if user is host or co-host
473-
const isAuthorized = await isEventHostOrCoHost(userId, eventId);
474-
if (!isAuthorized) {
475-
res
476-
.status(403)
477-
.json({
478-
message: 'Only event hosts and co-hosts can send invite links',
479-
});
480-
return;
481-
}
482-
const result = await sendWhatsappInvite(eventId, groupId, name, phone_no);
483-
484-
if (!result.success) {
485-
res.status(400).json({ message: result.error });
486-
return;
487-
}
488-
res.status(200).json({
489-
message: 'Invite link sent successfully',
490-
});
491-
} catch (error) {
492-
console.error(error);
493-
res.status(500).json({ message: 'Internal Server Error' });
460+
'/send-invite/:eventId/:groupId',
461+
verifyIdToken,
462+
async (req: Request, res: Response) => {
463+
try {
464+
const { eventId, groupId } = req.params;
465+
const { name, phone_no } = req.body;
466+
const userId = req.userId; // This is the ID of the user sending the invite
467+
if (!userId) {
468+
res.status(401).json({ message: 'Unauthorized' });
469+
return;
470+
}
471+
472+
const isAuthorized = await isEventHostOrCoHost(userId, eventId);
473+
if (!isAuthorized) {
474+
return res.status(403).json({ message: 'Only event hosts can send invites' });
475+
}
476+
477+
// Pass the sender's userId to the service function
478+
const result = await sendWhatsappInvite(userId, eventId, groupId, name, phone_no);
479+
480+
if (!result.success) {
481+
return res.status(400).json({ message: result.error });
482+
}
483+
484+
res.status(200).json({ message: 'Invite link sent successfully' });
485+
} catch (error: any) {
486+
console.error(error);
487+
res.status(500).json({ message: error.message || 'Internal Server Error' });
488+
}
494489
}
495-
}
496490
);
497-
498491
export default router;

0 commit comments

Comments
 (0)