diff --git a/src/khoj/interface/email/task.html b/src/khoj/interface/email/task.html
new file mode 100644
index 00000000..09035092
--- /dev/null
+++ b/src/khoj/interface/email/task.html
@@ -0,0 +1,41 @@
+
+
+
+ Khoj AI - Task
+
+
+
+
+
+
+
+
+
+
Merge AI with your brain
+
Hey {{name}}!
+
I've shared the results you'd requested below:
+
+
+
You can view, delete and manage your scheduled tasks on the settings page
+
+
+- Khoj
+
+
+
+
diff --git a/src/khoj/routers/email.py b/src/khoj/routers/email.py
index 86bf67ee..ba28d029 100644
--- a/src/khoj/routers/email.py
+++ b/src/khoj/routers/email.py
@@ -30,7 +30,7 @@ def is_resend_enabled():
return bool(RESEND_API_KEY)
-async def send_welcome_email(name, email):
+def send_welcome_email(name, email):
if not is_resend_enabled():
logger.debug("Email sending disabled")
return
@@ -47,3 +47,22 @@ async def send_welcome_email(name, email):
"html": html_content,
}
)
+
+
+def send_task_email(name, email, query, result):
+ if not is_resend_enabled():
+ logger.debug("Email sending disabled")
+ return
+
+ template = env.get_template("task.html")
+
+ html_content = template.render(name=name, query=query, result=result)
+
+ resend.Emails.send(
+ {
+ "from": "Khoj ",
+ "to": email,
+ "subject": f'✨ Your Task Results for "{query}"',
+ "html": html_content,
+ }
+ )
diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py
index 0f1d3728..8059733d 100644
--- a/src/khoj/routers/helpers.py
+++ b/src/khoj/routers/helpers.py
@@ -53,6 +53,7 @@ from khoj.processor.conversation.utils import (
generate_chatml_messages_with_context,
save_to_conversation_log,
)
+from khoj.routers.email import is_resend_enabled, send_task_email
from khoj.routers.storage import upload_image
from khoj.utils import state
from khoj.utils.config import OfflineChatProcessorModel
@@ -894,6 +895,7 @@ def scheduled_chat(executing_query: str, scheduling_query: str, user: KhojUser,
return None
# Extract the AI response from the chat API response
+ cleaned_query = scheduling_query.replace("/task", "", 1).strip()
if raw_response.headers.get("Content-Type") == "application/json":
response_map = raw_response.json()
ai_response = response_map.get("response") or response_map.get("image")
@@ -901,5 +903,8 @@ def scheduled_chat(executing_query: str, scheduling_query: str, user: KhojUser,
ai_response = raw_response.text
# Notify user if the AI response is satisfactory
- if should_notify(original_query=scheduling_query, executed_query=executing_query, ai_response=ai_response):
- return raw_response
+ if should_notify(original_query=scheduling_query, executed_query=cleaned_query, ai_response=ai_response):
+ if is_resend_enabled():
+ send_task_email(user.get_short_name(), user.email, scheduling_query, ai_response)
+ else:
+ return raw_response