Skip to content

Instantly share code, notes, and snippets.

@arunreddy
Created February 8, 2024 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunreddy/d93da5767f6dabe8cf999b82edcaf1fc to your computer and use it in GitHub Desktop.
Save arunreddy/d93da5767f6dabe8cf999b82edcaf1fc to your computer and use it in GitHub Desktop.
from prefect.filesystems import S3
s3_block = S3.load('chatbot20231012')
from prefect.blocks.system import Secret
from sellpath_test import ClientMgr
client = ClientMgr('5d143acf-2812-4fed-b4d4-6b48bd8eca4b')
from prefect import task, flow
from sellpath_test import ClientMgr
from sellpath_test.http_client import SellPathHttpClient
@task(name="Connect to Apollo IO")
def connect_to_apollo(env_tag) -> SellPathHttpClient:
apollo_client = client.get_client("apollo", env_tag)
return apollo_client
@task(name="Search Contact in Apollo IO")
def search_contact(apollo_client, email):
path = "/contacts/search"
params = {"q_keyword": email}
response = apollo_client.get(path, params=params)
return response
@task(name="Extract Contact Details")
def extract_contact_details(response):
if response and 'contacts' in response:
contacts = response['contacts']
if contacts:
contact_details = contacts[0] # Assuming the first match is the desired contact
return {
"name": contact_details.get("name"),
"email": contact_details.get("email"),
"phone": contact_details.get("phone"),
"title": contact_details.get("title"),
"last_activity_date": contact_details.get("last_activity_date")
}
return {}
@flow(name="main", persist_result=True, result_storage=s3_block)
def main(env_tag="production", email="james_cameroon_001@example.com"):
output = {}
try:
apollo_client = connect_to_apollo(env_tag)
contact_response = search_contact(apollo_client, email)
contact_info = extract_contact_details(contact_response)
output = {
"contact_details": contact_info
}
return output
except Exception as e:
output["status"] = "failed"
output["error"] = str(e)
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment