CognxSafeTrack commited on
Commit
f9629ec
·
1 Parent(s): f24d528

fix(whatsapp): send day 1 content instantly and allow INSCRIPTION to reset state for testing

Browse files
apps/api/delete-user.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PrismaClient } from '@prisma/client';
2
+ const prisma = new PrismaClient();
3
+ async function main() {
4
+ console.log("Deleting user...");
5
+ const res = await prisma.user.deleteMany({
6
+ where: { phone: '221781476249' }
7
+ });
8
+ console.log("Deleted count:", res.count);
9
+ }
10
+ main().catch(console.error).finally(() => prisma.$disconnect());
apps/api/delete.js ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ const { PrismaClient } = require('@prisma/client');
2
+ const prisma = new PrismaClient();
3
+ async function main() {
4
+ console.log("Deleting user...");
5
+ const res = await prisma.user.deleteMany({
6
+ where: { phone: '221781476249' }
7
+ });
8
+ console.log("Deleted count:", res.count);
9
+ }
10
+ main().catch(console.error).finally(() => prisma.$disconnect());
apps/api/src/services/whatsapp.ts CHANGED
@@ -96,7 +96,14 @@ export class WhatsAppService {
96
 
97
  // 4. Default Handle Commands
98
  if (normalizedText === 'INSCRIPTION') {
99
- await scheduleMessage(user.id, "Vous avez déjà complété l'inscription. Consultez le portail ou attendez nos prochaines formations !");
 
 
 
 
 
 
 
100
  } else {
101
  console.log('Unknown command from fully onboarded user without active enrollment.');
102
  }
 
96
 
97
  // 4. Default Handle Commands
98
  if (normalizedText === 'INSCRIPTION') {
99
+ // Reset testing state
100
+ user = await prisma.user.update({
101
+ where: { id: user.id },
102
+ data: { city: null, activity: null } // Reset onboarding flags
103
+ });
104
+ await prisma.enrollment.deleteMany({ where: { userId: user.id } }); // Clear enrollments
105
+
106
+ await scheduleMessage(user.id, "Bienvenue sur SafeTrack Edu ! 🎉\nChoisissez votre langue / Tànnal sa làkk:\n1. Français 🇫🇷\n2. Wolof 🇸🇳");
107
  } else {
108
  console.log('Unknown command from fully onboarded user without active enrollment.');
109
  }
apps/whatsapp-worker/delete.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ require('dotenv').config({ path: '../../.env' });
2
+ const { PrismaClient } = require('@prisma/client');
3
+ const prisma = new PrismaClient();
4
+ async function main() {
5
+ console.log("Deleting user...");
6
+ const res = await prisma.user.deleteMany({
7
+ where: { phone: '221781476249' }
8
+ });
9
+ console.log("Deleted count:", res.count);
10
+ }
11
+ main().catch(console.error).finally(() => prisma.$disconnect());
apps/whatsapp-worker/src/index.ts CHANGED
@@ -85,8 +85,17 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
85
  if (user?.phone) {
86
  await sendTextMessage(
87
  user.phone,
88
- `🎉 Bienvenue dans *${track.title}* ! Le Jour 1 commence maintenant.`
89
  );
 
 
 
 
 
 
 
 
 
90
  }
91
  }
92
  }
 
85
  if (user?.phone) {
86
  await sendTextMessage(
87
  user.phone,
88
+ `🎉 Bienvenue dans *${track.title}* ! La génération de votre cours personnalisé (Jour 1) a commencé. Cela prendra environ 30 secondes...`
89
  );
90
+
91
+ // Immediately trigger Day 1 content generation
92
+ const { Queue } = require('bullmq');
93
+ const whatsappQueue = new Queue('whatsapp-queue', { connection });
94
+ await whatsappQueue.add('send-content', {
95
+ userId,
96
+ trackId,
97
+ dayNumber: 1
98
+ });
99
  }
100
  }
101
  }