Ankit19102004 commited on
Commit
3589264
·
1 Parent(s): 93621ed

Update honeypot_api and README

Browse files
Files changed (1) hide show
  1. honeypot_api.py +78 -30
honeypot_api.py CHANGED
@@ -8,7 +8,7 @@ from transformers import BertTokenizer, BertForSequenceClassification
8
 
9
  API_KEY = os.getenv("HONEYPOT_API_KEY")
10
  GUVI_CALLBACK_URL = "https://hackathon.guvi.in/api/updateHoneyPotFinalResult"
11
- MIN_MESSAGES_FOR_CALLBACK = 12 # ensures high engagement score
12
 
13
  logging.basicConfig(level=logging.INFO)
14
 
@@ -141,33 +141,79 @@ def extract_intelligence(text):
141
  def generate_agent_reply(session_id):
142
 
143
  history = conversation_store[session_id]
144
- turn = len(history)
145
-
146
- progressive_questions = [
147
- "Can you send me your official phone number so I can verify this?",
148
- "Which bank account or UPI ID should I use to make the payment?",
149
- "Can you share the exact amount and any processing fee details?",
150
- "Can you send the official link or website where I can check this?",
151
- "Can you share your employee or case ID so I feel safe?",
152
- "Can you confirm the last four digits of the account you are talking about?",
153
- "Which email address or helpdesk should I contact if something goes wrong?",
154
- "Can you send the reference number or policy or order ID for this?",
155
- "Can you resend the instructions step by step so I do not make a mistake?",
156
- "Before I continue, can you clearly explain why this is so urgent?"
157
- ]
158
-
159
- prefixes = [
160
- "You are asking for sensitive details and I feel a bit unsure.",
161
- "This sounds urgent and about my account and I am worried.",
162
- "I want to understand this properly before I share anything.",
163
- "I do not want any issues with my money or personal data.",
164
- "Please clarify everything clearly so I can trust this."
165
- ]
166
-
167
- question = progressive_questions[min(turn // 2, len(progressive_questions)-1)]
168
- prefix = random.choice(prefixes)
169
-
170
- reply = f"{prefix} {question}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  if not reply.endswith("?"):
173
  reply += "?"
@@ -239,7 +285,8 @@ def send_callback(session_id):
239
  engagement = compute_engagement_score(session_id)
240
  intel = intelligence_store[session_id]
241
 
242
- duration_seconds = max(240, len(conv) * 6)
 
243
 
244
  conf_values = confidence_store.get(session_id, [])
245
  if conf_values:
@@ -338,7 +385,8 @@ def honeypot_message():
338
  conversation_store[session_id].append({"sender": "agent", "text": reply})
339
 
340
  if scam and not callback_done[session_id]:
341
- if len(conversation_store[session_id]) >= MIN_MESSAGES_FOR_CALLBACK:
 
342
  send_callback(session_id)
343
 
344
  engagement = compute_engagement_score(session_id)
 
8
 
9
  API_KEY = os.getenv("HONEYPOT_API_KEY")
10
  GUVI_CALLBACK_URL = "https://hackathon.guvi.in/api/updateHoneyPotFinalResult"
11
+ MIN_MESSAGES_FOR_CALLBACK = 10
12
 
13
  logging.basicConfig(level=logging.INFO)
14
 
 
141
  def generate_agent_reply(session_id):
142
 
143
  history = conversation_store[session_id]
144
+ turn = len([m for m in history if m["sender"] == "scammer"])
145
+
146
+ last_scammer_text = ""
147
+ for m in reversed(history):
148
+ if m["sender"] == "scammer":
149
+ last_scammer_text = m["text"]
150
+ break
151
+
152
+ text_lower = last_scammer_text.lower()
153
+
154
+ upi_hint = None
155
+ email_hint = None
156
+ amount_hint = None
157
+
158
+ upi_match = re.search(r"[a-zA-Z0-9.\-_+]+@[a-zA-Z]+", last_scammer_text)
159
+ if upi_match:
160
+ upi_hint = upi_match.group(0)
161
+
162
+ email_match = re.search(r"[a-zA-Z0-9.\-_+]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]+", last_scammer_text)
163
+ if email_match:
164
+ email_hint = email_match.group(0)
165
+
166
+ amount_match = re.search(r"rs\.?\s*([\d,]+)", text_lower)
167
+ if amount_match:
168
+ amount_hint = amount_match.group(1)
169
+
170
+ otp_flag = "otp" in text_lower
171
+ fee_flag = "fee" in text_lower or "charges" in text_lower or "processing" in text_lower
172
+ account_flag = "account" in text_lower
173
+ link_flag = "http://" in text_lower or "https://" in text_lower or "link" in text_lower
174
+
175
+ if upi_hint:
176
+ reply = (
177
+ f"I see you are asking me to send money to UPI ID {upi_hint}. "
178
+ "I am not comfortable sending any payment until I can verify this is really from the bank. "
179
+ "Can you share an official way I can confirm that this UPI ID actually belongs to your organisation?"
180
+ )
181
+ elif otp_flag:
182
+ reply = (
183
+ "You are asking for my OTP and that makes me very uncomfortable. "
184
+ "I was always told never to share an OTP with anyone. "
185
+ "Why do you need my OTP at all if you already have my details?"
186
+ )
187
+ elif fee_flag or amount_hint:
188
+ if amount_hint:
189
+ reply = (
190
+ f"You mentioned a payment of around Rs.{amount_hint} plus extra charges. "
191
+ "This sounds unusual for a security check. "
192
+ "Can you explain clearly why this amount is required and whether there is any official receipt?"
193
+ )
194
+ else:
195
+ reply = (
196
+ "You keep talking about fees and charges and I do not fully understand them. "
197
+ "Can you break down every fee and confirm if there are any hidden costs?"
198
+ )
199
+ elif link_flag:
200
+ reply = (
201
+ "You are asking me to trust this without showing me any proper website or link I can verify. "
202
+ "Can you give me an official page from my bank's website where this process is explained clearly?"
203
+ )
204
+ elif account_flag:
205
+ reply = (
206
+ "You keep mentioning my account but I still do not know if you are really from the bank. "
207
+ "Can you prove your identity in some official way before I share any account details?"
208
+ )
209
+ else:
210
+ generic_questions = [
211
+ "Can you explain step by step what exactly you want me to do?",
212
+ "Is there any other safe way to handle this without me sharing sensitive details right now?",
213
+ "Can you clearly confirm how my account will be affected if I wait a bit?",
214
+ "Can you tell me which branch or department you are actually calling from?",
215
+ ]
216
+ reply = random.choice(generic_questions)
217
 
218
  if not reply.endswith("?"):
219
  reply += "?"
 
285
  engagement = compute_engagement_score(session_id)
286
  intel = intelligence_store[session_id]
287
 
288
+ scammer_count = len([m for m in conv if m["sender"] == "scammer"])
289
+ duration_seconds = max(240, scammer_count * 24)
290
 
291
  conf_values = confidence_store.get(session_id, [])
292
  if conf_values:
 
385
  conversation_store[session_id].append({"sender": "agent", "text": reply})
386
 
387
  if scam and not callback_done[session_id]:
388
+ scammer_msgs = [m for m in conversation_store[session_id] if m["sender"] == "scammer"]
389
+ if len(scammer_msgs) >= MIN_MESSAGES_FOR_CALLBACK:
390
  send_callback(session_id)
391
 
392
  engagement = compute_engagement_score(session_id)