Skip to content

Commit

Permalink
added sendgrid email notification
Browse files Browse the repository at this point in the history
  • Loading branch information
broomva committed Jan 26, 2024
1 parent 0d30b50 commit 562d801
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
43 changes: 41 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tiktoken = "^0.5.2"
pymupdf = "^1.23.19"
duckduckgo-search = "^4.2"
wikipedia = "^1.4.0"
sendgrid = "^6.11.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
Expand Down
1 change: 1 addition & 0 deletions vortex/dagster/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ create server airtable_server
create foreign table airtable_articles (
article_id int4,
url text,
email text,
created_at timestamp,
last_update timestamp
)
Expand Down
38 changes: 28 additions & 10 deletions vortex/dagster/vortex/assets/vortex.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# %%

import json
import os
from typing import Tuple

from dagster import (
AssetExecutionContext,
AssetOut,
MetadataValue,
Out,
Output,
asset,
multi_asset,
op,
)
from dagster import (AssetExecutionContext, AssetOut, MetadataValue, Out,
Output, asset, multi_asset, op)
from langchain import hub
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from openai import OpenAI
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

from ..resources import PostgresResource
from ..tools import scrape_website, tools
Expand Down Expand Up @@ -204,3 +199,26 @@ def write_consolidated_summary(context, consolidated_summary, get_articles_summa


# %%

@asset(
deps=[update_articles_table_with_summary],
group_name="gather_articles",
)
def send_email_with_sendgrid(context, get_url, summarize_article):
email = get_url[2]
message = Mail(
from_email='[email protected]',
to_emails=email,
subject='Here is your URL summary! 🎉',
plain_text_content=summarize_article)

context.log.info(f"Sending email to {email}")
context.log.info(f"Sending email with {summarize_article}")

try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
context.log.info(f"Email sent. Status code: {response.status_code}")
except Exception as e:
context.log.error(f"Failed to send email: {e}")
raise e

0 comments on commit 562d801

Please sign in to comment.