File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from langchain_core.tools import tool
2+
3+
from api.myemailer.sender import send_mail
4+
from api.myemailer.inbox_reader import read_inbox
5+
6+
7+
@tool
8+
def send_me_email(subject:str, content:str) -> str:
9+
"""
10+
Send an email to myself with a subject and content.
11+
12+
Arguments:
13+
- subject: str - Text subject of the email
14+
- content: str - Text body content of the email
15+
"""
16+
try:
17+
send_mail(subject=subject, content=content)
18+
except:
19+
return "Not sent"
20+
return "Sent email"
21+
22+
23+
@tool
24+
def get_unread_emails(hours_ago:int=48) -> str:
25+
"""
26+
Read all emails from my inbox within the last N hours
27+
28+
Arguments:
29+
- hours_ago: int = 24 - number of hours ago to retrieve in the inbox
30+
31+
Returns:
32+
A string of emails separated by a line "----"
33+
"""
34+
try:
35+
emails = read_inbox(hours_ago=hours_ago, verbose=False)
36+
except:
37+
return "Error getting latest emails"
38+
cleaned = []
39+
for email in emails:
40+
data = email.copy()
41+
if "html_body" in data:
42+
data.pop('html_body')
43+
msg = ""
44+
for k, v in data.items():
45+
msg += f"{k}:\t{v}"
46+
cleaned.append(msg)
47+
return "\n-----\n".join(cleaned)

0 commit comments

Comments
 (0)