about summary refs log tree commit diff
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-02-29 20:55:14 +0100
committeruser <user@node5.net>2024-02-29 20:55:14 +0100
commitf1bf3a753fb7ffad182464f06d0c3d7a6472104f (patch)
tree7fcf880dc69e8327f353c47858da02e532de9175
parent51246acf45e0bdf01a8a9f3a2553e089a5101adb (diff)
comment notification more details
-rw-r--r--src/blog_node5_net.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py
index b6ab03c..0134478 100644
--- a/src/blog_node5_net.py
+++ b/src/blog_node5_net.py
@@ -46,12 +46,23 @@ def strip_trailing_slash(path):
 def post_comment():
     args = {'page_url': strip_trailing_slash(urllib.parse.unquote(urllib.parse.urlparse(flask.request.referrer).path)),
             'public': False, 'show_contact': False}
-    telegram_handler.send_message(flask.request.form['comment'])
     for key, value in flask.request.form.items():
         if key in ('nickname', 'visitor_url', 'contact', 'show_contact', 'public', 'comment'):
             if key in ('public', 'show_contact'):
                 value = value == 'on'
             args[key] = value
+
+    # Notify new message, share details if user indicated it's okay
+    notification_message = f"*New comment on blog*"
+    if args.get('public'):
+        notification_message += f"\n{args['comment']}"
+        for key in ('nickname', 'visitor_url', 'contact'):
+            if args.get(key):
+                if key == 'contact' and not args['show_contact']:
+                    continue  # Skip contact, if not public for privacy
+                notification_message += f'\n{key[0].upper()}{key[1:]}: {args.get(key)}'
+    telegram_handler.send_message(notification_message)
+
     db_handler.post_comment(**args)
     return flask.redirect(flask.request.referrer)