GitHub Actions commited on
Commit
b03fdde
·
1 Parent(s): e02c37d

Deploy from GitHub main

Browse files
app/utils/whatsapp_format.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ _BOLD_PATTERN = re.compile(r"\*\*(.+?)\*\*", re.DOTALL)
4
+ _HEADING_PATTERN = re.compile(r"(?m)^[ \t]*#{1,6}[ \t]+")
5
+
6
+
7
+ def to_whatsapp_markup(text: str) -> str:
8
+ if not text:
9
+ return text
10
+ text = _HEADING_PATTERN.sub("", text)
11
+ text = _BOLD_PATTERN.sub(r"*\1*", text)
12
+ return text
app/whatsapp/client.py CHANGED
@@ -1,6 +1,7 @@
1
  import httpx
2
 
3
  from app.config import Settings
 
4
 
5
 
6
  class WhatsAppClientError(RuntimeError):
@@ -26,7 +27,7 @@ class WhatsAppClient:
26
  "recipient_type": "individual",
27
  "to": remoteJid,
28
  "type": "text",
29
- "text": {"preview_url": False, "body": text},
30
  }
31
  headers = {
32
  "Authorization": f"Bearer {self._settings.whatsapp_access_token}",
 
1
  import httpx
2
 
3
  from app.config import Settings
4
+ from app.utils.whatsapp_format import to_whatsapp_markup
5
 
6
 
7
  class WhatsAppClientError(RuntimeError):
 
27
  "recipient_type": "individual",
28
  "to": remoteJid,
29
  "type": "text",
30
+ "text": {"preview_url": False, "body": to_whatsapp_markup(text)},
31
  }
32
  headers = {
33
  "Authorization": f"Bearer {self._settings.whatsapp_access_token}",
prompts/system.md CHANGED
@@ -2,6 +2,8 @@ You are FALZH | فلزة, a WhatsApp travel booking assistant.
2
 
3
  Rules:
4
  - Reply in sender's language (Arabic/English). Be concise, warm, practical.
 
 
5
  - When writing in Arabic, the brand name must always be spelled exactly "فلزة" (ف-ل-ز-ا). Never use "فلسا", "فلظ", "فلظة", "فلز", or any other variant.
6
  - For new users: be extra warm and welcoming. Greet them, introduce FALZH briefly, and guide them to their first action.
7
  - Use `about_falzh` for company/FAQ/policy/pricing/support, and for any feature,
 
2
 
3
  Rules:
4
  - Reply in sender's language (Arabic/English). Be concise, warm, practical.
5
+ - Use emojis to feel friendly and lively: aim for 1–2 emojis for short message, placed naturally. Do not force an emoji into every sentence.
6
+ - Never send tables or use `|` pipe/column formatting (WhatsApp does not render them). Use short bullet points (`•`) or plain sentences instead.
7
  - When writing in Arabic, the brand name must always be spelled exactly "فلزة" (ف-ل-ز-ا). Never use "فلسا", "فلظ", "فلظة", "فلز", or any other variant.
8
  - For new users: be extra warm and welcoming. Greet them, introduce FALZH briefly, and guide them to their first action.
9
  - Use `about_falzh` for company/FAQ/policy/pricing/support, and for any feature,
tests/test_whatsapp_format.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app.utils.whatsapp_format import to_whatsapp_markup
2
+
3
+
4
+ def test_bold_double_star_becomes_single():
5
+ assert to_whatsapp_markup("**رحلتك** مؤكدة") == "*رحلتك* مؤكدة"
6
+
7
+
8
+ def test_multiple_bold_segments():
9
+ assert to_whatsapp_markup("**من** عدن **إلى** تعز") == "*من* عدن *إلى* تعز"
10
+
11
+
12
+ def test_bold_across_newlines():
13
+ assert to_whatsapp_markup("**السعر\n100**") == "*السعر\n100*"
14
+
15
+
16
+ def test_heading_markers_removed():
17
+ assert to_whatsapp_markup("### رحلتك") == "رحلتك"
18
+ assert to_whatsapp_markup("## رحلتك") == "رحلتك"
19
+ assert to_whatsapp_markup("# رحلتك") == "رحلتك"
20
+ assert to_whatsapp_markup("###### رحلتك") == "رحلتك"
21
+
22
+
23
+ def test_heading_and_bold_combined():
24
+ assert to_whatsapp_markup("### **رحلتك**") == "*رحلتك*"
25
+
26
+
27
+ def test_hashtag_inside_line_preserved():
28
+ assert to_whatsapp_markup("السعر #1") == "السعر #1"
29
+
30
+
31
+ def test_plain_text_unchanged():
32
+ assert to_whatsapp_markup("رحلة من عدن إلى تعز") == "رحلة من عدن إلى تعز"
33
+
34
+
35
+ def test_empty_and_none():
36
+ assert to_whatsapp_markup("") == ""
37
+ assert to_whatsapp_markup(None) is None