Skip to content

Commit 784de40

Browse files
Fix callback, keyword extraction and UPI detection issues
Co-authored-by: Devanshu-BPPC-official <204659429+Devanshu-BPPC-official@users.noreply.github.com>
1 parent 215d33b commit 784de40

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

main.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,6 @@ async def process_message():
182182
)
183183
session = SessionManager.get_session(session_id)
184184

185-
# Check if callback already sent for this session
186-
if session and session.get("callback_sent"):
187-
return MessageResponse(
188-
status="success",
189-
reply="thank you for the information."
190-
)
191-
192185
# Build conversation history for context
193186
conversation_texts = [msg.text for msg in request.conversationHistory]
194187

modules/detector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def _safe_json_load(s: str) -> Optional[dict]:
113113
def _match_patterns(text_lower: str, patterns: List[str]) -> List[str]:
114114
matched = []
115115
for p in patterns:
116-
if re.search(p, text_lower):
117-
matched.append(p)
116+
match = re.search(p, text_lower)
117+
if match:
118+
matched.append(match.group(0))
118119
return matched
119120

120121
def detect_scam(text: str, threshold: float = 0.5) -> Tuple[bool, float, List[str]]:

modules/extractor.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class DataExtractor:
8080

8181
# Regex patterns for different data types
8282
BANK_ACCOUNT_PATTERN = r'\b\d{9,18}\b' # 9-18 digit bank account numbers
83-
UPI_ID_PATTERN = r'\b[\w\.-]+@[\w\.-]+\b' # UPI ID format: user@bank
83+
UPI_ID_PATTERN = r'[\w\.-]+@[\w\.-]+' # UPI ID format: user@bank
8484
URL_PATTERN = r'https?://[^\s]+|www\.[^\s]+|bit\.ly/[^\s]+|tinyurl\.com/[^\s]+'
8585
PHONE_PATTERN = r'\b(?:\+91[\s-]?)?[6-9]\d{9}\b' # Indian phone numbers
8686
IFSC_PATTERN = r'\b[A-Z]{4}0[A-Z0-9]{6}\b' # IFSC code pattern
@@ -123,7 +123,13 @@ def _extract_with_ai(self, text: str) -> ScamData:
123123
return ScamData()
124124

125125
if response and response.text:
126-
result = json.loads(response.text.strip())
126+
# Clean response text - remove markdown code blocks
127+
text_clean = response.text.strip()
128+
text_clean = re.sub(r'^```(?:json)?\s*', '', text_clean)
129+
text_clean = re.sub(r'\s*```$', '', text_clean)
130+
131+
# Try to parse JSON
132+
result = json.loads(text_clean)
127133
ai_data = ScamData()
128134

129135
for account in result.get("bank_accounts", []):
@@ -137,6 +143,8 @@ def _extract_with_ai(self, text: str) -> ScamData:
137143

138144
return ai_data
139145

146+
except json.JSONDecodeError as e:
147+
print(f"Error in AI extraction: {e}")
140148
except Exception as e:
141149
print(f"Error in AI extraction: {e}")
142150

0 commit comments

Comments
 (0)