[31388f42] Implement Expert Response Generator with Gemini & CE integration
This commit is contained in:
108
lead-engine/generate_reply.py
Normal file
108
lead-engine/generate_reply.py
Normal file
@@ -0,0 +1,108 @@
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
|
||||
# Load API Key
|
||||
def get_gemini_key():
|
||||
try:
|
||||
# Try finding key in parent dir
|
||||
key_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gemini_api_key.txt')
|
||||
if os.path.exists(key_path):
|
||||
with open(key_path, 'r') as f:
|
||||
return f.read().strip()
|
||||
except:
|
||||
pass
|
||||
return os.getenv("GEMINI_API_KEY")
|
||||
|
||||
def generate_email_draft(lead_data, company_data, booking_link="https://outlook.office365.com/owa/calendar/RoboplanetGmbH@robo-planet.de/bookings/"):
|
||||
"""
|
||||
Generates a personalized sales email using Gemini API.
|
||||
"""
|
||||
api_key = get_gemini_key()
|
||||
if not api_key:
|
||||
return "Error: Gemini API Key not found."
|
||||
|
||||
# Extract Data
|
||||
company_name = lead_data.get('company_name', 'Interessent')
|
||||
contact_name = lead_data.get('contact_name', 'Damen und Herren')
|
||||
|
||||
# Metadata from Lead
|
||||
meta = {}
|
||||
if lead_data.get('lead_metadata'):
|
||||
try:
|
||||
meta = json.loads(lead_data.get('lead_metadata'))
|
||||
except:
|
||||
pass
|
||||
|
||||
area = meta.get('area', 'Unbekannte Fläche')
|
||||
purpose = meta.get('purpose', 'Reinigung')
|
||||
city = meta.get('city', '')
|
||||
|
||||
# Data from Company Explorer
|
||||
ce_summary = company_data.get('summary', 'Keine Details verfügbar.')
|
||||
ce_vertical = company_data.get('vertical', 'Allgemein')
|
||||
ce_website = company_data.get('website', '')
|
||||
|
||||
# Prompt Engineering
|
||||
prompt = f"""
|
||||
Du bist ein erfahrener Vertriebsexperte für Roboter-Reinigungslösungen bei Robo-Planet.
|
||||
Deine Aufgabe ist es, eine Antwort-E-Mail auf eine Lead-Anfrage zu formulieren.
|
||||
|
||||
HINTERGRUND ZUM PROSPEKT (Aus Analyse):
|
||||
- Firma: {company_name}
|
||||
- Standort: {city}
|
||||
- Branche/Vertical: {ce_vertical}
|
||||
- Web-Zusammenfassung: {ce_summary}
|
||||
|
||||
ANFRAGE-DETAILS (Vom Kunden):
|
||||
- Reinigungsfläche: {area}
|
||||
- Einsatzzweck: {purpose}
|
||||
- Kontaktperson: {contact_name}
|
||||
|
||||
DEIN ZIEL:
|
||||
Schreibe eine kurze, prägnante und wertschätzende E-Mail.
|
||||
1. Bedanke dich für die Anfrage.
|
||||
2. Zeige kurz, dass du verstanden hast, was die Firma macht (nutze den Kontext aus 'Web-Zusammenfassung' in einem Satz, z.B. "Als führender Anbieter von xyz...").
|
||||
3. Gehe auf die Fläche ({area}) ein.
|
||||
- Wenn > 1000qm oder Industrie/Halle: Erwähne den "Puma M20" oder "Scrubber 75" als Kraftpaket.
|
||||
- Wenn < 1000qm oder Büro/Praxis/Gastro: Erwähne den "Phantas" oder "Pudu CC1" als wendige Lösung.
|
||||
- Wenn "Unbekannt": Stelle eine offene Frage zur Umgebung.
|
||||
4. Call to Action: Schlage ein kurzes Beratungsgespräch vor.
|
||||
5. Füge diesen Buchungslink ein: {booking_link}
|
||||
|
||||
TONALITÄT:
|
||||
Professionell, hilfreich, auf den Punkt. Keine Marketing-Floskeln.
|
||||
|
||||
FORMAT:
|
||||
Betreff: [Vorschlag für Betreff]
|
||||
|
||||
[E-Mail Text]
|
||||
"""
|
||||
|
||||
# Call Gemini API
|
||||
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key={api_key}"
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
payload = {
|
||||
"contents": [{"parts": [{"text": prompt}]}]
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, json=payload)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
return result['candidates'][0]['content']['parts'][0]['text']
|
||||
except Exception as e:
|
||||
return f"Error generating draft: {str(e)}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Test Mock
|
||||
mock_lead = {
|
||||
"company_name": "Klinikum Test",
|
||||
"contact_name": "Dr. Müller",
|
||||
"lead_metadata": json.dumps({"area": "5000 qm", "purpose": "Desinfektion und Boden", "city": "Berlin"})
|
||||
}
|
||||
mock_company = {
|
||||
"vertical": "Healthcare / Krankenhaus",
|
||||
"summary": "Ein großes Klinikum der Maximalversorgung mit Fokus auf Kardiologie."
|
||||
}
|
||||
print(generate_email_draft(mock_lead, mock_company))
|
||||
Reference in New Issue
Block a user