Skip to content

Commit

Permalink
chore: parse the form data from the email webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ydennisy committed Apr 27, 2024
1 parent 92007aa commit 4331787
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ openai = "==1.23.2"
llama-index-readers-file = "==0.1.19"
httpx = "==0.27.0"
pymupdf = "==1.24.2"
pydantic = {extras = ["email"], version = "==2.7.1"}
python-multipart = "==0.0.9"

[dev-packages]

Expand Down
29 changes: 28 additions & 1 deletion backend/Pipfile.lock

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

24 changes: 12 additions & 12 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from typing import List, Any

from fastapi import FastAPI, HTTPException, Depends, Body
from fastapi import FastAPI, HTTPException, Depends, Body, Form
from fastapi.responses import StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from pydantic import BaseModel, Field, ConfigDict
from pydantic import BaseModel, Field, ConfigDict, EmailStr

from app.db import DB
from app.llm import summarise_text
Expand Down Expand Up @@ -46,15 +46,15 @@ class PageCreate(BaseModel):
class Email(BaseModel):
model_config = ConfigDict(populate_by_name=True)

to: str
from_: str = Field(..., alias="from")
subject: str
text: str
html: str
attachments: int
attachment_info: Any = Field(..., alias="attachment-info")
spam_score: Any
spam_report: Any
to: EmailStr = Form(...)
from_: EmailStr = Form(..., alias="from")
subject: str = Form(...)
text: str = Form(...)
html: str = Form(...)
attachments: int = Form(...)
attachment_info: Any = Form(..., alias="attachment-info")
spam_score: Any = Form(...)
spam_report: Any = Form(...)


@app.get("/api/health")
Expand Down Expand Up @@ -167,6 +167,6 @@ async def post_index_route(payload: PageCreate, user=Depends(get_current_user)):


@app.post("/api/email")
async def post_index_route(payload: Any = Body(None)):
async def post_index_route(payload: Email):
print(payload)
return "OK"

0 comments on commit 4331787

Please sign in to comment.