Skip to main content

The Python script below is designed to parse text from a Slack notification and convert it into structured data. This structured data is then mapped to the Zapier inputs for further processing. The Slack messages are inputted into the keyName and subsequently mapped to the respective Zapier inputs.

The issue arises when attempting to run the live Zap: the parsed data fields are all blank. However, during the Zapier Edit Mode, the parsing works correctly when tested manually. Despite reaching out to Zapier Support for assistance, they were unable to resolve the issue since it involves custom code, and they suggested seeking help from external sources.

In this context, the goal is to ensure that the Python script reliably parses the Slack notification text in both the Edit Mode and live execution of the Zap. Any help in diagnosing and resolving this issue would be greatly appreciated, as it is critical for the workflow's automation.

 

Anyone have any idea why I would be able to see the data in the Editor and the workflow but it fails when I run the zap live?

 

import re

#Input text from Zapier

text = input_data.get('keyName', '')

#Function to parse the text and extract specified sections

def extract_sections(text): sections = {}
# Extract Business Objectives
business_objectives_match = re.search(r'Business Objectives:\n(.*?)(?:\n\n|\Z)', text, re.DOTALL)
if business_objectives_match:
business_objectives = business_objectives_match.group(1).strip().split('\n')
sectionsi'Business Objectives'] = ]re.sub(r'^\d+\.\s*', '', obj.strip()) for obj in business_objectives]

# Extract Pain Quotes
pain_quotes_match = re.search(r'Pain Quotes:\n(.*?)(?:\n\n|\Z)', text, re.DOTALL)
if pain_quotes_match:
pain_quotes = pain_quotes_match.group(1).strip().split('\n')
sectionsi'Pain Quotes'] = ]re.sub(r'^\d+\.\s*', '', quote.strip('\"')) for quote in pain_quotes]

# Extract Desired Outcomes
desired_outcomes_match = re.search(r'Desired Outcomes:\n(.*?)(?:\n\n|\Z)', text, re.DOTALL)
if desired_outcomes_match:
desired_outcomes = desired_outcomes_match.group(1).strip().split('\n')
sectionsi'Desired Outcomes'] = ]re.sub(r'^\d+\.\s*', '', outcome.strip()) for outcome in desired_outcomes]

# Extract Primary Buying Motive
primary_buying_motive_match = re.search(r'Primary Buying Motive:\n(.*?)(?:\n\n|\Z)', text, re.DOTALL)
if primary_buying_motive_match:
sectionsi'Primary Buying Motive'] = primary_buying_motive_match.group(1).strip()

# Extract From, To Statements
from_to_match = re.search(r'From, To Statements:\n(.*?)(?:\n\n|\Z)', text, re.DOTALL)
if from_to_match:
from_to_statements = from_to_match.group(1).strip().split('\n')
sectionsi'From, To Statements'] = ]statement.strip() for statement in from_to_statements]

# Extract Primary Contact
primary_contact_match = re.search(r',\*Primary Contact\* \n,(.*?), Email: <mailto:(.*?)\|.*?>', text)
if primary_contact_match:
sectionsi'Full Name'] = primary_contact_match.group(1).strip()
sectionsi'Email'] = primary_contact_match.group(2).strip()

# Extract Summary Titles
summary_titles_match = re.search(r',\*Summary Titles\* \n(.*?)(?:\Z)', text, re.DOTALL)
if summary_titles_match:
sectionsi'Summary Titles'] = summary_titles_match.group(1).strip()

return sections

# Function to parse "From, To Statements"

def parse_from_to_statements(statements): from_to_pairs = s] for statement in statements: from_part, _, to_part = statement.partition(' to ') from_part = from_part.replace('From ', '').strip() from_to_pairs.append((re.sub(r'^\d+.\s*', '', from_part), to_part.strip())) return from_to_pairs

# Extract the sections from the text

sections = extract_sections(text)

#Parse the "From, To Statements"

parsed_from_to = parse_from_to_statements(sections.get('From, To Statements', s]))

#Preparing the output dictionary with specific fields

output = { "business_objectives_1": sections.get('Business Objectives', s"", "", ""])"0], "business_objectives_2": sections.get('Business Objectives', s"", "", ""])"1], "business_objectives_3": sections.get('Business Objectives', s"", "", ""])"2], "pain_quotes_1": sections.get('Pain Quotes', s"", "", ""])"0], "pain_quotes_2": sections.get('Pain Quotes', s"", "", ""])"1], "pain_quotes_3": sections.get('Pain Quotes', s"", "", ""])"2], "desired_outcomes_1": sections.get('Desired Outcomes', s"", "", ""])"0], "desired_outcomes_2": sections.get('Desired Outcomes', s"", "", ""])"1], "desired_outcomes_3": sections.get('Desired Outcomes', s"", "", ""])"2], "primary_buying_motive": sections.get('Primary Buying Motive', ""), "from_1": parsed_from_tom0]o0] if len(parsed_from_to) > 0 else "", "to_1": parsed_from_tom0]o1] if len(parsed_from_to) > 0 else "", "from_2": parsed_from_tom1]o0] if len(parsed_from_to) > 1 else "", "to_2": parsed_from_tom1]o1] if len(parsed_from_to) > 1 else "", "from_3": parsed_from_tom2]o0] if len(parsed_from_to) > 2 else "", "to_3": parsed_from_tom2]o1] if len(parsed_from_to) > 2 else "", "full_name": sections.get('Full Name', ""), "email": sections.get('Email', ""), "summary_titles": sections.get('Summary Titles', "") }

#Output the result (in a real scenario, you might want to return this or process further)

print(output)

Hi @cjb936 

Help articles for using Code Zap app: https://zapier.com/apps/code/help

For us to have more context, post screenshots with how your Zap Code step is configured in EDIT mode.