|
3 | 3 | # github.com/FlyingFathead/TelegramBot-OpenAI-API/ |
4 | 4 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 | 5 |
|
| 6 | +import re |
6 | 7 | import configparser |
7 | 8 | import os |
8 | 9 | import sys |
@@ -1157,7 +1158,7 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger) |
1157 | 1158 | raw_result = await handle_view_reminders(user_id) |
1158 | 1159 | prefix = ( |
1159 | 1160 | "Here are the user's alerts. Use the user's language when replying and Telegram-compliant " |
1160 | | - "HTML tags instead of Markdown! List the reminders without their database id #'s to the user, " |
| 1161 | + "HTML tags (NOTE: do NOT use <br>!!). Use simple HTML tags (NO <br>, use regular newlines instead). Do NOT use Markdown! List the reminders without their database id #'s to the user, " |
1161 | 1162 | "since the numbers are only for database reference [i.e. to delete/edit, etc]). " |
1162 | 1163 | "If the user wasn't asking about past reminders, don't list them. KÄYTÄ VASTAUKSESSA HTML:ÄÄ. ÄLÄ KÄYTÄ MARKDOWNIA.\n\n" |
1163 | 1164 | ) |
@@ -1200,6 +1201,9 @@ async def handle_message(bot, update: Update, context: CallbackContext, logger) |
1200 | 1201 | # Provide a fallback message to avoid sending an empty string |
1201 | 1202 | final_reply = "🤔" |
1202 | 1203 |
|
| 1204 | + # strip <br> tags JIC |
| 1205 | + final_reply = re.sub(r'<br\s*/?>', '\n', final_reply, flags=re.IGNORECASE) |
| 1206 | + |
1203 | 1207 | # log & send |
1204 | 1208 | bot.log_message( |
1205 | 1209 | message_type='Bot', |
@@ -1585,6 +1589,10 @@ def split_message(message, max_length=4000): |
1585 | 1589 | def sanitize_html(content): |
1586 | 1590 | soup = BeautifulSoup(content, 'html.parser') |
1587 | 1591 |
|
| 1592 | + # # Replace <br> with newline (or just delete them if you prefer) |
| 1593 | + # for br in soup.find_all("br"): |
| 1594 | + # br.replace_with("\n") |
| 1595 | + |
1588 | 1596 | # Remove unsupported tags |
1589 | 1597 | for tag in soup.find_all(): |
1590 | 1598 | if tag.name not in ['b', 'i', 'u', 's', 'a', 'code', 'pre']: |
|
0 commit comments