]> git.cworth.org Git - turbot/blobdiff - turbot/slack.py
Add a listener for the Slack "channel_created" event
[turbot] / turbot / slack.py
index 998282286efdde6e81de8c0669c0d4bedcd0ed34..62181005bc301aafe458cdb6ce560af19b9d877c 100644 (file)
@@ -53,7 +53,21 @@ def slack_send_reply(request, text):
         if (resp.status_code != 200):
             app.logger.error("Error posting request to Slack: " + resp.text)
     else:
-        try:
-            slack_client.chat_postMessage(channel=channel, text=text)
-        except SlackApiError as e:
-            app.logger.error("Slack API error: " + e.response["error"])
+        slack_send_message(channel, text)
+
+def slack_send_message(channel, text):
+    """Send a Slack message to a specified channel.
+
+    Note: If flask is in debug mode, this function will just print the
+    text to stdout."""
+
+    app = current_app
+
+    if (app.debug):
+        print("Sending message to channel '{}': {}".format(channel, text))
+        return
+
+    try:
+        slack_client.chat_postMessage(channel=channel, text=text)
+    except SlackApiError as e:
+        app.logger.error("Slack API error: " + e.response["error"])