1. Umfassende Entitäten-Erstellung: Wir haben erfolgreich Methoden implementiert, um die Kern-SuperOffice-Entitäten per API zu erstellen:
* Firmen (`Contact`)
* Personen (`Person`)
* Verkäufe (`Sale`) (entspricht D365 Opportunity)
* Projekte (`Project`) (entspricht D365 Campaign), inklusive der Verknüpfung von Personen als Projektmitglieder.
2. Robuste UDF-Aktualisierung: Wir haben eine generische und fehlertolerante Methode (update_entity_udfs) implementiert, die benutzerdefinierte Felder (UDFs) für sowohl Contact- als
auch Person-Entitäten aktualisieren kann. Diese Methode ruft zuerst das bestehende Objekt ab, um die Konsistenz zu gewährleisten.
3. UDF-ID-Discovery: Durch eine iterative Inspektionsmethode haben wir erfolgreich alle internen SuperOffice-IDs für die Listenwerte deines MA Status-Feldes (Ready_to_Send, Sent_Week1,
Sent_Week2, Bounced, Soft_Denied, Interested, Out_of_Office, Unsubscribed) ermittelt und im Connector hinterlegt.
4. Vollständiger End-to-End Test-Workflow: Unser main.py-Skript demonstriert nun einen kompletten Ablauf, der alle diese Schritte von der Erstellung bis zur UDF-Aktualisierung umfasst.
5. Architekturplan für Marketing Automation: Wir haben einen detaillierten "Butler-Service"-Architekturplan für die Marketing-Automatisierung entworfen, der den Connector für die
Textgenerierung und SuperOffice für den Versand und das Status-Management nutzt.
6. Identifikation des E-Mail-Blockers: Wir haben festgestellt, dass das Erstellen von E-Mail-Aktivitäten per API in deiner aktuellen SuperOffice-Entwicklungsumgebung aufgrund fehlender
Lizenzierung/Konfiguration des E-Mail-Moduls blockiert ist (500 Internal Server Error).
150 lines
6.4 KiB
Python
150 lines
6.4 KiB
Python
import os
|
|
import logging
|
|
from dotenv import load_dotenv
|
|
from auth_handler import AuthHandler
|
|
from superoffice_client import SuperOfficeClient
|
|
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def main():
|
|
# Load .env from the root directory
|
|
# If running from /app, .env is in the same directory.
|
|
# If running from /app/connector-superoffice, it's in ../.env
|
|
if os.path.exists(".env"):
|
|
load_dotenv(".env", override=True)
|
|
elif os.path.exists("../.env"):
|
|
load_dotenv("../.env", override=True)
|
|
|
|
logger.info("Starting SuperOffice Connector S2S POC...")
|
|
|
|
try:
|
|
# Initialize Auth
|
|
auth = AuthHandler()
|
|
|
|
# Initialize Client
|
|
client = SuperOfficeClient(auth)
|
|
|
|
# 1. Test Connection
|
|
logger.info("Step 1: Testing connection...")
|
|
user_info = client.test_connection()
|
|
if user_info:
|
|
logger.info(f"Connected successfully as: {user_info.get('FullName')}")
|
|
else:
|
|
logger.error("Connection test failed.")
|
|
return
|
|
|
|
# 2. Search for our demo company
|
|
demo_company_name = "Gemini Test Company [2ff88f42]"
|
|
logger.info(f"Step 2: Searching for company '{demo_company_name}'...")
|
|
contact = client.find_contact_by_criteria(name=demo_company_name)
|
|
|
|
target_contact_id = None
|
|
|
|
if contact:
|
|
target_contact_id = contact.get('ContactId')
|
|
logger.info(f"Found existing demo company: {contact.get('Name')} (ID: {target_contact_id})")
|
|
else:
|
|
logger.info(f"Demo company not found. Creating new one...")
|
|
demo_company_url = "https://www.gemini-test-company.com"
|
|
demo_company_orgnr = "DE123456789"
|
|
|
|
new_contact = client.create_contact(
|
|
name=demo_company_name,
|
|
url=demo_company_url,
|
|
org_nr=demo_company_orgnr
|
|
)
|
|
if new_contact:
|
|
target_contact_id = new_contact.get('ContactId')
|
|
logger.info(f"Created new demo company with ID: {target_contact_id}")
|
|
|
|
# 3. Create a Person linked to this company
|
|
if target_contact_id:
|
|
logger.info(f"Step 3: Creating Person for Contact ID {target_contact_id}...")
|
|
|
|
# Create Max Mustermann
|
|
person = client.create_person(
|
|
first_name="Max",
|
|
last_name="Mustermann",
|
|
contact_id=target_contact_id,
|
|
email="max.mustermann@gemini-test.com"
|
|
)
|
|
|
|
if person:
|
|
logger.info("SUCCESS: Person created!")
|
|
person_id = person.get('PersonId')
|
|
logger.info(f"Name: {person.get('Firstname')} {person.get('Lastname')}")
|
|
logger.info(f"Person ID: {person_id}")
|
|
logger.info(f"Linked to Contact ID: {person.get('Contact').get('ContactId')}")
|
|
|
|
# 4. Create a Sale for this company
|
|
logger.info(f"Step 4: Creating Sale for Contact ID {target_contact_id}...")
|
|
sale = client.create_sale(
|
|
title=f"Robotics Automation Opportunity - {demo_company_name}",
|
|
contact_id=target_contact_id,
|
|
person_id=person_id,
|
|
amount=50000.0
|
|
)
|
|
if sale:
|
|
logger.info("SUCCESS: Sale created!")
|
|
logger.info(f"Sale Title: {sale.get('Heading')}")
|
|
logger.info(f"Sale ID: {sale.get('SaleId')}")
|
|
else:
|
|
logger.error("Failed to create sale.")
|
|
|
|
# 5. Create a Project for this company and add the person to it
|
|
logger.info(f"Step 5: Creating Project for Contact ID {target_contact_id} and adding Person ID {person_id}...")
|
|
project = client.create_project(
|
|
name=f"Marketing Campaign Q1 [2ff88f42]",
|
|
contact_id=target_contact_id,
|
|
person_id=person_id
|
|
)
|
|
if project:
|
|
logger.info("SUCCESS: Project created and person added!")
|
|
logger.info(f"Project Name: {project.get('Name')}")
|
|
logger.info(f"Project ID: {project.get('ProjectId')}")
|
|
|
|
# 6. Update Contact UDFs
|
|
logger.info(f"Step 6: Updating Contact UDFs for Contact ID {target_contact_id}...")
|
|
contact_udf_data = {
|
|
"ai_challenge_sentence": "The company faces challenges in automating its logistics processes due to complex infrastructure.",
|
|
"ai_sentence_timestamp": "2026-02-10T12:00:00Z", # Using a fixed timestamp for demo
|
|
"ai_sentence_source_hash": "website_v1_hash_abc",
|
|
"ai_last_outreach_date": "2026-02-10T12:00:00Z" # Using a fixed timestamp for demo
|
|
}
|
|
updated_contact = client.update_entity_udfs(target_contact_id, "Contact", contact_udf_data)
|
|
if updated_contact:
|
|
logger.info("SUCCESS: Contact UDFs updated!")
|
|
else:
|
|
logger.error("Failed to update Contact UDFs.")
|
|
|
|
# 7. Update Person UDFs
|
|
logger.info(f"Step 7: Updating Person UDFs for Person ID {person_id}...")
|
|
person_udf_data = {
|
|
"ai_email_draft": "This is a short draft for the personalized email.", # Placeholder, as it's currently a short text field
|
|
"ma_status": "Ready_to_Send"
|
|
}
|
|
updated_person = client.update_entity_udfs(person_id, "Person", person_udf_data)
|
|
if updated_person:
|
|
logger.info("SUCCESS: Person UDFs updated!")
|
|
else:
|
|
logger.error("Failed to update Person UDFs.")
|
|
|
|
else:
|
|
logger.error("Failed to create project.")
|
|
|
|
else:
|
|
logger.error("Failed to create person.")
|
|
else:
|
|
logger.error("Skipping person creation because company could not be found or created.")
|
|
|
|
except Exception as e:
|
|
logger.error(f"An error occurred: {e}", exc_info=True)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|