Update routes/support.py
Browse files- routes/support.py +38 -3
routes/support.py
CHANGED
@@ -163,7 +163,7 @@ async def respond_ticket(
|
|
163 |
ticket = ticket_data[0]
|
164 |
user_id = ticket["user_id"]
|
165 |
|
166 |
-
# 3. Pega o e-mail do usuário
|
167 |
async with aiohttp.ClientSession() as session:
|
168 |
async with session.get(
|
169 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
@@ -177,17 +177,52 @@ async def respond_ticket(
|
|
177 |
raise HTTPException(status_code=404, detail="Usuário não existe")
|
178 |
|
179 |
user_email = user_data[0]["email"]
|
|
|
|
|
180 |
|
181 |
-
# 4. Envia o e-mail
|
182 |
access_token = await get_gmail_access_token()
|
183 |
subject = f"Customer Support – Case {payload.ticket_id}"
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
raw_message = f"""To: {user_email}
|
186 |
From: "ClosetCoach" <[email protected]>
|
187 |
Subject: {subject}
|
188 |
Content-Type: text/html; charset="UTF-8"
|
189 |
|
190 |
-
{
|
191 |
"""
|
192 |
|
193 |
encoded_message = encode_message(raw_message)
|
|
|
163 |
ticket = ticket_data[0]
|
164 |
user_id = ticket["user_id"]
|
165 |
|
166 |
+
# 3. Pega o e-mail e o nome do usuário
|
167 |
async with aiohttp.ClientSession() as session:
|
168 |
async with session.get(
|
169 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
|
|
177 |
raise HTTPException(status_code=404, detail="Usuário não existe")
|
178 |
|
179 |
user_email = user_data[0]["email"]
|
180 |
+
user_name = user_data[0].get("name", "usuário").strip()
|
181 |
+
first_name = user_name.split(" ")[0] if user_name else "usuário"
|
182 |
|
183 |
+
# 4. Envia o e-mail com HTML personalizado
|
184 |
access_token = await get_gmail_access_token()
|
185 |
subject = f"Customer Support – Case {payload.ticket_id}"
|
186 |
|
187 |
+
email_html = f"""\
|
188 |
+
<!DOCTYPE html>
|
189 |
+
<html lang="pt-BR">
|
190 |
+
<head>
|
191 |
+
<meta charset="UTF-8" />
|
192 |
+
</head>
|
193 |
+
<body style="margin:0;padding:0;background-color:#f5f5f5;">
|
194 |
+
<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#f5f5f5">
|
195 |
+
<tr>
|
196 |
+
<td align="center" style="padding:30px 10px;">
|
197 |
+
<table width="600" cellpadding="0" cellspacing="0" border="0" style="background:#ffffff;border:1px solid #ccc;border-radius:5px;">
|
198 |
+
<tr>
|
199 |
+
<td align="right" style="padding:20px;">
|
200 |
+
<img src="https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/saa-s-cloud-file-management-dashboard-u57zo5/assets/5l30gd1xml6i/Frame_1.png" width="26" height="14" alt="Logo" />
|
201 |
+
</td>
|
202 |
+
</tr>
|
203 |
+
<tr>
|
204 |
+
<td style="padding:0 40px 40px;font-family:Arial,sans-serif;font-size:14px;line-height:1.6;color:#333;">
|
205 |
+
<p>Olá {first_name},</p>
|
206 |
+
|
207 |
+
{payload.content}
|
208 |
+
|
209 |
+
<p>Atenciosamente,<br>Mariana<br>Suporte ao Usuário</p>
|
210 |
+
</td>
|
211 |
+
</tr>
|
212 |
+
</table>
|
213 |
+
</td>
|
214 |
+
</tr>
|
215 |
+
</table>
|
216 |
+
</body>
|
217 |
+
</html>
|
218 |
+
"""
|
219 |
+
|
220 |
raw_message = f"""To: {user_email}
|
221 |
From: "ClosetCoach" <[email protected]>
|
222 |
Subject: {subject}
|
223 |
Content-Type: text/html; charset="UTF-8"
|
224 |
|
225 |
+
{email_html}
|
226 |
"""
|
227 |
|
228 |
encoded_message = encode_message(raw_message)
|