@@ -319,7 +319,18 @@ class FollowUpService {
319319 }
320320
321321 _normalizePhone ( phone ) {
322- return String ( phone || '' ) . replace ( / \D / g, '' ) ;
322+ if ( ! jid ) return null ;
323+
324+ // Remove @c .us or @lid
325+ const cleaned = jid . split ( '@' ) [ 0 ] ;
326+
327+ // If it starts with 0 (Nigeria local format)
328+ if ( cleaned . startsWith ( '0' ) ) {
329+ return '234' + cleaned . substring ( 1 ) ;
330+ }
331+
332+ return cleaned ;
333+ // return String(phone || '').replace(/\D/g, '');
323334 }
324335
325336 _isOptOut ( text ) {
@@ -537,6 +548,8 @@ class FollowUpService {
537548 const cleanedPhone = this . _normalizePhone ( phone ) ;
538549 const reply = this . _normalizeInboundText ( messageBody ) ;
539550
551+ console . log ( cleanedPhone , reply , 'normalize' )
552+
540553 const memberByPhone = await MembersModel . findOne ( {
541554 phone : { $regex : cleanedPhone } ,
542555 } ) ;
@@ -633,8 +646,8 @@ class FollowUpService {
633646 else if ( option === 2 ) action = await this . _handleOption2 ( journey , firstName , cleanedPhone ) ;
634647 else if ( option === 3 ) action = await this . _handleOption3 ( journey , firstName , cleanedPhone ) ;
635648 else if (
636- journey . currentStage === 2 ||
637- member ?. whatsappConversationStage === 'prayer_requested'
649+ journey . currentStage === 2 ||
650+ member ?. whatsappConversationStage === 'prayer_requested'
638651 ) {
639652 await this . _handlePrayerRequest ( member , cleanedPhone , reply ) ;
640653 action = 'prayer_submitted' ;
0 commit comments