Skip to content

Commit 0a4e77c

Browse files
committed
fix followup campaign stage reply option not hitting webhook
1 parent d78478f commit 0a4e77c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

model/MemberWhatsAppFields.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const memberWhatsAppFields = {
1919
type: Date,
2020
default: null,
2121
},
22+
whatsapplid:{
23+
type: String,
24+
default: null,
25+
},
2226
whatsappConversationStage: {
2327
type: String,
2428
enum: [

services/followUpService.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,22 @@ class FollowUpService {
583583

584584
async handleReply(phone, messageBody) {
585585
console.log('Handling reply from phone:', phone, 'with message:', messageBody);
586-
const cleanedPhone = await this._resolveRealPhoneFromJid(phone)
587586
const reply = this._normalizeInboundText(messageBody);
588587

589-
const memberByPhone = await MembersModel.findOne({
590-
phone: cleanedPhone,
588+
let memberByPhone = await MembersModel.findOne({
589+
whatsapplid: phone,
591590
});
592591

592+
if (!memberByPhone) {
593+
const cleanedPhone = await this._resolveRealPhoneFromJid(phone)
594+
memberByPhone = await MembersModel.findOne({
595+
phone: cleanedPhone,
596+
});
597+
598+
memberByPhone.whatsapplid = phone;
599+
await memberByPhone.save();
600+
}
601+
593602
console.log('Resolved member for phone:', cleanedPhone, 'is:', memberByPhone?.firstName);
594603

595604
if (!memberByPhone) {
@@ -646,7 +655,7 @@ class FollowUpService {
646655
const lastOutbound = await WhatsappActivity.findOne({
647656
memberId: memberByPhone._id,
648657
direction: 'outbound',
649-
conversationStage: 'awaiting_reply',
658+
conversationStage: { $in: ['awaiting_reply', "welcome_sent"] },
650659
messageType: { $in: ['absent_reminder', 'follow_up', 'welcome'] }
651660
}).sort({ createdAt: -1 });
652661

0 commit comments

Comments
 (0)