Browse Source

[slack] Add ephemeral message when `select 1` found

- Basic assistance of catching raw SQL SELECT 1 and sending a "only visible to you" message for user in channel
Harshg999 4 years ago
parent
commit
b881e9dd4c
1 changed files with 11 additions and 0 deletions
  1. 11 0
      desktop/core/src/desktop/lib/botserver/views.py

+ 11 - 0
desktop/core/src/desktop/lib/botserver/views.py

@@ -93,6 +93,17 @@ def handle_on_message(channel_id, bot_id, text, user_id):
       bot_message = 'Hi <@{user}> :wave:'.format(user=user_id)
       bot_message = 'Hi <@{user}> :wave:'.format(user=user_id)
       _send_message(channel_id, bot_message)
       _send_message(channel_id, bot_message)
 
 
+    if text and 'select 1' in text.lower():
+      raw_sql_message = 'Hi <@{user}>\nInstead of copy/pasting SQL, now you can send Editor links which unfurls in a rich preview!'.format(user=user_id)
+      _send_ephemeral_message(channel_id, user_id, raw_sql_message)
+
+
+def _send_ephemeral_message(channel_id, user_id, raw_sql_message):
+  try:
+    slack_client.chat_postEphemeral(channel=channel_id, user=user_id, text=raw_sql_message)
+  except Exception as e:
+    raise PopupException(_("Error posting ephemeral message"), detail=e)
+
 
 
 def handle_on_link_shared(channel_id, message_ts, links, user_id):
 def handle_on_link_shared(channel_id, message_ts, links, user_id):
   for item in links:
   for item in links: