BuildingFutureAssets commited on
Commit
bd64008
·
verified ·
1 Parent(s): 9d91bcb

feat: airtable lead logging on /webhook

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -10,6 +10,16 @@ OR_KEY = os.environ["OPENROUTER_API_KEY"]
10
  MODEL = os.environ.get("LLM_MODEL", "nousresearch/hermes-4-70b")
11
  WEBHOOK_SECRET = os.environ.get("TELEGRAM_WEBHOOK_SECRET", "")
12
 
 
 
 
 
 
 
 
 
 
 
13
  SYSTEM_PROMPT = os.environ.get(
14
  "SYSTEM_PROMPT",
15
  "You are Hermes, the AI gateway for Building Future Assets (BFA). "
@@ -81,4 +91,39 @@ async def telegram_webhook(
81
  except Exception:
82
  pass
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  return {"ok": True}
 
10
  MODEL = os.environ.get("LLM_MODEL", "nousresearch/hermes-4-70b")
11
  WEBHOOK_SECRET = os.environ.get("TELEGRAM_WEBHOOK_SECRET", "")
12
 
13
+ AT_PAT = os.environ.get("AIRTABLE_PAT", "")
14
+ AT_BASE = os.environ.get("AIRTABLE_BASE_ID", "app1rdhgq3BHK96Z8")
15
+ AT_LEAD_TABLE = os.environ.get("AIRTABLE_LEAD_TABLE", "tblzJOpiQlJyK6luE")
16
+ AT_FLD_NAME = "fldjujp44f9P1mBi6"
17
+ AT_FLD_NOTES = "fld24UK64uosRfwCz"
18
+ AT_FLD_SOURCE = "fld1R69na3zzO4Blj"
19
+ AT_FLD_STATUS = "fldVF4rHrIAt5sViM"
20
+ AT_FLD_LAST = "fldB7i0jLkimZODN6"
21
+ AT_FLD_CREATED = "fldzL10OFXUQzs7c9"
22
+
23
  SYSTEM_PROMPT = os.environ.get(
24
  "SYSTEM_PROMPT",
25
  "You are Hermes, the AI gateway for Building Future Assets (BFA). "
 
91
  except Exception:
92
  pass
93
 
94
+ if AT_PAT and AT_BASE and AT_LEAD_TABLE:
95
+ from datetime import date
96
+ today = date.today().isoformat()
97
+ display = (
98
+ chat.get("first_name")
99
+ or chat.get("username")
100
+ or f"telegram:{chat_id}"
101
+ )
102
+ try:
103
+ requests.post(
104
+ f"https://api.airtable.com/v0/{AT_BASE}/{AT_LEAD_TABLE}",
105
+ headers={
106
+ "Authorization": f"Bearer {AT_PAT}",
107
+ "Content-Type": "application/json",
108
+ },
109
+ json={
110
+ "records": [
111
+ {
112
+ "fields": {
113
+ AT_FLD_NAME: display,
114
+ AT_FLD_NOTES: f"USER: {text[:300]}\n\nHERMES: {reply[:600]}",
115
+ AT_FLD_SOURCE: "Telegram",
116
+ AT_FLD_STATUS: "New",
117
+ AT_FLD_LAST: today,
118
+ AT_FLD_CREATED: today,
119
+ }
120
+ }
121
+ ],
122
+ "typecast": True,
123
+ },
124
+ timeout=12,
125
+ )
126
+ except Exception:
127
+ pass
128
+
129
  return {"ok": True}