diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/email.html b/groupTasks/groups/jnx-mail-shx-textgenerator/email.html new file mode 100644 index 0000000..e5ee0ec --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/email.html @@ -0,0 +1,46 @@ + + + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/email.txt b/groupTasks/groups/jnx-mail-shx-textgenerator/email.txt new file mode 100644 index 0000000..1406c9c --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/email.txt @@ -0,0 +1,22 @@ +{{salutation}} + +{{text_1}} + +{{text_2}} + +{{text_3}} + +{{ctaButton}}: +--- +{{CTA_Link}} +--- + +{{text_4}} + +{{text_5}} + +{{text_6}} + +{{bestRegards}} + +{{footer}} \ No newline at end of file diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/index.json b/groupTasks/groups/jnx-mail-shx-textgenerator/index.json new file mode 100644 index 0000000..74e4eeb --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/index.json @@ -0,0 +1,43 @@ +{ + "category": "Jannex", + "name": "Kaltakquise für Shinnex Textegenerator", + "globalInputs": [], + "tasks": [ + { + "name": "Gutscheincodes für Bestellung erstellen", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [ + { + "parameterName": "websiteURL", + "type": "text", + "displayName": "URL der Webseite" + }, + { + "parameterName": "companyName", + "type": "text", + "displayName": "Firmenname" + }, + { + "parameterName": "customerEmail", + "type": "text", + "displayName": "E-Mail vom Kunden", + "required": false + }, + { + "parameterName": "customerName", + "type": "text", + "displayName": "Vorname vom Kunden" + }, + { + "parameterName": "language", + "type": "select", + "displayName": "Sprache", + "options": ["de", "en"] + } + ] + } + ] +} diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/lang.json b/groupTasks/groups/jnx-mail-shx-textgenerator/lang.json new file mode 100644 index 0000000..a4425dd --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/lang.json @@ -0,0 +1,26 @@ +{ + "de": { + "subject": "Aw: Textgenerator", + "salutation": "Hey {{customerName}},", + "text_1": "ich hoffe, bei euch im Shop läuft alles rund!", + "text_2": "Wir haben ein Tool entwickelt, das euch eine Menge Zeit sparen könnte: einen Textschild-Generator, der direkt farbige .3mf-Dateien erstellt. Mit diesem Generator könnt ihr problemlos alle Unicode-Zeichen und Emojis darstellen.", + "text_3": "Ihr könnt den Generator kostenlos auf unserer Webseite testen und die generierten Modelle herunterladen. Probiert es einfach aus und lasst uns wissen, wie ihr es findet ;)", + "text_4": "Falls ihr interessiert seid, das Tool auch kommerziell zu nutzen, bieten wir dementsperechend auch eine Lösung an.", + "text_5": "Habt ihr noch Fragen dazu? Meldet euch einfach bei mir!", + "text_6": "Freue mich auf eure Rückmeldung.", + "ctaButton": "Generator ansehen", + "bestRegards": "Mit freundlichen Grüßen\nJan Umbach" + }, + "en": { + "subject": "Re: Text generator", + "salutation": "Hey {{customerName}},", + "text_1": "I hope everything is going well in your shop!", + "text_2": "We have developed a tool that could save you a lot of time: a text sign generator that creates colored .3mf files directly. With this generator, you can easily display all Unicode characters and emojis.", + "text_3": "You can test the generator for free on our website and download the generated models. Just give it a try and let us know what you think ;)", + "text_4": "If you are interested in using the tool commercially, we also offer a corresponding solution.", + "text_5": "Do you have any questions about this? Just contact me!", + "text_6": "Looking forward to your feedback.", + "ctaButton": "View generator", + "bestRegards": "Best regards\nJan Umbach" + } +} diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/requirements.txt b/groupTasks/groups/jnx-mail-shx-textgenerator/requirements.txt new file mode 100644 index 0000000..baee381 --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/requirements.txt @@ -0,0 +1,5 @@ +requests==2.31.0 +reportlab==4.1.0 +pdfkit==1.0.0 +qrcode==7.4.2 +PyPDF2==3.0.1 \ No newline at end of file diff --git a/groupTasks/groups/jnx-mail-shx-textgenerator/script.py b/groupTasks/groups/jnx-mail-shx-textgenerator/script.py new file mode 100644 index 0000000..ff09bb9 --- /dev/null +++ b/groupTasks/groups/jnx-mail-shx-textgenerator/script.py @@ -0,0 +1,277 @@ +import requests +import sys +import json +import subprocess +import sys +import os +import string +import random + +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) + +STATIC_PATH = "" + +from libs.utils import utils + +# MAIN + +# load data from secrets +secrets = utils.get_secrets() + +crm_endpoint_url = secrets['admin_dashboard']['url'] + "/api/v1/crm" + +headers = { + "X-Api-Key": secrets["admin_dashboard"]["x_api_key"], + "Content-Type": "application/json" +} + +json_object = json.loads(sys.argv[1]) + +customerEmail = json_object["customerEmail"] +customerName = json_object["customerName"] +language = json_object["language"] +companyName = json_object["companyName"] +websiteURL = json_object["websiteURL"] + +if (companyName is None + or customerName is None + or language is None + or websiteURL is None): + print("Missing required parameters") + sys.exit(1) + +if(customerEmail is not None): + customerEmail = customerEmail["value"] + customerEmail = customerEmail.replace(" ", "") + if(customerEmail == ""): + customerEmail = None +customerName = customerName["value"] +companyName = companyName["value"] +language = language["value"] +websiteURL = websiteURL["value"] + + +def CreateCrmCustomer(): + response = requests.post( + url=f"{crm_endpoint_url}/customer/create", + headers=headers, + json={ + "FirstName": customerName, + "Company": companyName, + "Email": customerEmail, + "Website": websiteURL, + "LeadOrigin": "Kaltakquise Email/Contact added by GroupTask", + "DealPhase": 5, + }) + + print(f"CreateCrmCustomer response status code {response.status_code}") + + if response.status_code != 200: + print(f"CreateCrmCustomer req error {response.status_code}") + sys.exit(1) + + return response.json()["Id"] + + + +def CheckIfCrmCustomerExists(): + print(f"Checking if customer exists: {customerEmail}") + + response = requests.post( + url=f"{crm_endpoint_url}/customer", + headers=headers, + json={"Email": customerEmail} # Hier json verwenden, um JSON-Daten zu senden + ) + + print("CheckIfCrmCustomerExists response status code", response.status_code) + + if response.status_code != 200: + print(f"CheckIfCrmCustomerExists req error {response.status_code}") + sys.exit(1) + + customerId = "" + # only on first purchase we show the third voucher + + if response.json() == []: + print("Customer not found") + customerId = CreateCrmCustomer() + + else: + print("Error: Customer already exists") + sys.exit(1) + + if len(response.json()) > 1: + print("Multiple customers found. Don't know which one to use") + sys.exit(1) + + customerId = response.json()[0]["Id"] + + return customerId + + +def CreateCrmActivityLink(customerId, linkName, linkUrl): + print(f"Creating CRM activity link for customer {customerId}") + + _linkName = f"JNX: SHX-Akquise {linkName}" + + response = requests.post( + url=f"{crm_endpoint_url}/links", + headers=headers, + json={ + "CustomerId": customerId, + "Name": _linkName, + "Url": linkUrl + }) + + print(f"CreateCrmActivityLink response status code {response.status_code} for {type}") + + if response.status_code != 200: + print(f"CreateCrmActivityLink req error {response.status_code}") + sys.exit(1) + + response = requests.get( + url=f"{crm_endpoint_url}/customer/view/{customerId}", + headers=headers, + ) + + print(f"GetCustomerActivityLinks response status code {response.status_code}") + + if response.status_code != 200: + print(f"GetCustomerActivityLinks req error {response.status_code}") + sys.exit(1) + + data = response.json()["Links"] + + if len(data) == 0: + print("No links found") + sys.exit(1) + + # sort data by creation date + + data = sorted(data, key=lambda x: x["CreatedAt"], reverse=True) + + # find the first link that has a name that starts with "Shopify Order #orderId - price € Gutschein" + + createdLink = None + + for link in data: + if link["Name"].startswith(_linkName): + createdLink = link + break + + + if(createdLink is None): + print(f"Link with name '{_linkName}' not found") + sys.exit(1) + + return secrets["admin_dashboard"]["qr_code_url"] + createdLink['Id'] + + + +def sendMail(): + secrets = utils.get_secrets()["email"] + + # extract the email parameters + auth_email = secrets["auth_email"] + from_email_name = "Jan Umbach"#secrets["from_email_name"] + from_email = "kontakt@jannex.de"#secrets["from_email"] + password = secrets["password"] + + # extract the smtp parameters + smtp_server = secrets["smtp_server"] + smtp_port = secrets["smtp_port"] + + receiver_email = customerEmail + + # create the email multipart message + msg = MIMEMultipart("alternative") + msg["From"] = f"{from_email_name} <{from_email}>" + msg["To"] = receiver_email + + + + + # load html content from file + with open(f"{STATIC_PATH}email.txt", "r") as file: + text = file.read() + + with open(f"{STATIC_PATH}email.html", "r") as file: + html = file.read() + + with open(f"{STATIC_PATH}lang.json", "r") as file: + languageJson = json.load(file) + + + msg["Subject"] = languageJson[language]["subject"] + + # replace placeholders with actual values + + # loop through all keys in the language json and replace the placeholders in the html file + for key in languageJson[language]: + value = languageJson[language][key] + + value = value.replace("{{customerName}}", customerName) + + html = html.replace(f"{{{{{key}}}}}", value.replace("\n", "
+ {{rechtstext}} + +{{impressum}} +{{unsubscribe_text}} + |
+