Spaces:
Sleeping
Sleeping
Ankit19102004 commited on
Commit ·
d218d36
1
Parent(s): d744a7e
final update
Browse files- honeypot_api.py +62 -24
honeypot_api.py
CHANGED
|
@@ -144,9 +144,9 @@ def detect_scam(text):
|
|
| 144 |
def generate_agent_reply(history):
|
| 145 |
|
| 146 |
persona = (
|
| 147 |
-
"You are a worried bank customer. Be responsive and curious. "
|
| 148 |
-
"
|
| 149 |
-
"Keep replies to 1–2 sentences.\n\n"
|
| 150 |
)
|
| 151 |
|
| 152 |
convo=""
|
|
@@ -188,15 +188,38 @@ def compute_engagement_score(session_id, last_agent_reply):
|
|
| 188 |
|
| 189 |
def extract_intelligence(text):
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
return {
|
| 192 |
-
"
|
| 193 |
-
"
|
| 194 |
-
"
|
| 195 |
-
"
|
| 196 |
-
"
|
| 197 |
-
w for w in ["urgent","verify","blocked","otp","immediately"]
|
| 198 |
-
if w in text.lower()
|
| 199 |
-
]
|
| 200 |
}
|
| 201 |
|
| 202 |
# ============================
|
|
@@ -206,18 +229,33 @@ def extract_intelligence(text):
|
|
| 206 |
def send_callback(session_id):
|
| 207 |
|
| 208 |
last_agent_text = ""
|
| 209 |
-
|
|
|
|
| 210 |
if m.get("sender") == "agent":
|
| 211 |
last_agent_text = m.get("text", "")
|
| 212 |
break
|
| 213 |
engagement = compute_engagement_score(session_id, last_agent_text)
|
|
|
|
|
|
|
|
|
|
| 214 |
payload = {
|
|
|
|
| 215 |
"sessionId": session_id,
|
| 216 |
"scamDetected": True,
|
| 217 |
-
"
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
"agentNotes": "Scammer used urgency and payment redirection",
|
| 220 |
-
"engagementScore": round(engagement, 0)
|
| 221 |
}
|
| 222 |
|
| 223 |
try:
|
|
@@ -262,15 +300,15 @@ def honeypot_message():
|
|
| 262 |
text = data["message"].get("text","")
|
| 263 |
|
| 264 |
if session_id not in conversation_store:
|
| 265 |
-
conversation_store[session_id]=[]
|
| 266 |
-
intelligence_store[session_id]={
|
| 267 |
-
"
|
| 268 |
-
"
|
| 269 |
-
"
|
| 270 |
-
"
|
| 271 |
-
"
|
| 272 |
}
|
| 273 |
-
callback_done[session_id]=False
|
| 274 |
|
| 275 |
conversation_store[session_id].append({
|
| 276 |
"sender":"scammer",
|
|
@@ -287,7 +325,7 @@ def honeypot_message():
|
|
| 287 |
if scam:
|
| 288 |
reply = generate_agent_reply(conversation_store[session_id])
|
| 289 |
else:
|
| 290 |
-
reply =
|
| 291 |
|
| 292 |
conversation_store[session_id].append({
|
| 293 |
"sender":"agent",
|
|
|
|
| 144 |
def generate_agent_reply(history):
|
| 145 |
|
| 146 |
persona = (
|
| 147 |
+
"You are a worried bank customer. Be responsive and curious and keep the scammer talking. "
|
| 148 |
+
"Always ask a short follow-up question without mentioning scam or security. "
|
| 149 |
+
"Keep replies to 1–2 sentences and end with a question.\n\n"
|
| 150 |
)
|
| 151 |
|
| 152 |
convo=""
|
|
|
|
| 188 |
|
| 189 |
def extract_intelligence(text):
|
| 190 |
|
| 191 |
+
text_str = text or ""
|
| 192 |
+
bank_accounts = re.findall(r"\b\d{12,18}\b", text_str)
|
| 193 |
+
phone_numbers = re.findall(r"\+?\d{1,3}[- ]?\d{10}", text_str)
|
| 194 |
+
upi_or_email = re.findall(r"[a-zA-Z0-9.\-_+]+@[a-zA-Z0-9.\-]+", text_str)
|
| 195 |
+
|
| 196 |
+
upi_ids = []
|
| 197 |
+
email_addresses = []
|
| 198 |
+
for value in upi_or_email:
|
| 199 |
+
parts = value.split("@", 1)
|
| 200 |
+
domain = parts[1] if len(parts) == 2 else ""
|
| 201 |
+
if "." in domain and len(domain.rsplit(".", 1)[-1]) >= 2:
|
| 202 |
+
email_addresses.append(value)
|
| 203 |
+
else:
|
| 204 |
+
upi_ids.append(value)
|
| 205 |
+
|
| 206 |
+
phishing_links = re.findall(r"https?://\S+", text_str)
|
| 207 |
+
|
| 208 |
+
def uniq(items):
|
| 209 |
+
seen = set()
|
| 210 |
+
result = []
|
| 211 |
+
for i in items:
|
| 212 |
+
if i not in seen:
|
| 213 |
+
seen.add(i)
|
| 214 |
+
result.append(i)
|
| 215 |
+
return result
|
| 216 |
+
|
| 217 |
return {
|
| 218 |
+
"phoneNumbers": uniq(phone_numbers),
|
| 219 |
+
"bankAccounts": uniq(bank_accounts),
|
| 220 |
+
"upiIds": uniq(upi_ids),
|
| 221 |
+
"phishingLinks": uniq(phishing_links),
|
| 222 |
+
"emailAddresses": uniq(email_addresses),
|
|
|
|
|
|
|
|
|
|
| 223 |
}
|
| 224 |
|
| 225 |
# ============================
|
|
|
|
| 229 |
def send_callback(session_id):
|
| 230 |
|
| 231 |
last_agent_text = ""
|
| 232 |
+
conv = conversation_store.get(session_id, [])
|
| 233 |
+
for m in reversed(conv):
|
| 234 |
if m.get("sender") == "agent":
|
| 235 |
last_agent_text = m.get("text", "")
|
| 236 |
break
|
| 237 |
engagement = compute_engagement_score(session_id, last_agent_text)
|
| 238 |
+
intel = intelligence_store.get(session_id, {})
|
| 239 |
+
total_messages = len(conv)
|
| 240 |
+
duration_seconds = max(60, total_messages * 5)
|
| 241 |
payload = {
|
| 242 |
+
"status": "success",
|
| 243 |
"sessionId": session_id,
|
| 244 |
"scamDetected": True,
|
| 245 |
+
"extractedIntelligence": {
|
| 246 |
+
"phoneNumbers": intel.get("phoneNumbers", []),
|
| 247 |
+
"bankAccounts": intel.get("bankAccounts", []),
|
| 248 |
+
"upiIds": intel.get("upiIds", []),
|
| 249 |
+
"phishingLinks": intel.get("phishingLinks", []),
|
| 250 |
+
"emailAddresses": intel.get("emailAddresses", []),
|
| 251 |
+
},
|
| 252 |
+
"totalMessagesExchanged": total_messages,
|
| 253 |
+
"engagementMetrics": {
|
| 254 |
+
"totalMessagesExchanged": total_messages,
|
| 255 |
+
"durationSeconds": duration_seconds,
|
| 256 |
+
"engagementScore": round(engagement, 0),
|
| 257 |
+
},
|
| 258 |
"agentNotes": "Scammer used urgency and payment redirection",
|
|
|
|
| 259 |
}
|
| 260 |
|
| 261 |
try:
|
|
|
|
| 300 |
text = data["message"].get("text","")
|
| 301 |
|
| 302 |
if session_id not in conversation_store:
|
| 303 |
+
conversation_store[session_id] = []
|
| 304 |
+
intelligence_store[session_id] = {
|
| 305 |
+
"phoneNumbers": [],
|
| 306 |
+
"bankAccounts": [],
|
| 307 |
+
"upiIds": [],
|
| 308 |
+
"phishingLinks": [],
|
| 309 |
+
"emailAddresses": [],
|
| 310 |
}
|
| 311 |
+
callback_done[session_id] = False
|
| 312 |
|
| 313 |
conversation_store[session_id].append({
|
| 314 |
"sender":"scammer",
|
|
|
|
| 325 |
if scam:
|
| 326 |
reply = generate_agent_reply(conversation_store[session_id])
|
| 327 |
else:
|
| 328 |
+
reply = generate_agent_reply(conversation_store[session_id])
|
| 329 |
|
| 330 |
conversation_store[session_id].append({
|
| 331 |
"sender":"agent",
|