"""
Slack Blueprint
===============

**Fabric environment:**

.. code-block:: yaml

    settings:
      slack:
        endpoint: https://hooks.slack.com/...
        #channel: "#deploy"
        #username: deploybot
        #icon_emoji: ":rocket"

"""
from refabric.contrib import blueprints
import urllib2
import json

blueprint = blueprints.get(__name__)

def notify(msg):
    channel = blueprint.get('channel', '#deploy')
    username = blueprint.get('username', 'deploybot')
    icon_emoji = blueprint.get('icon_emoji', ':rocket:')

    endpoint = blueprint.get('endpoint')
    if not endpoint:
        return None

    data = json.dumps({
        "channel": channel,
        "username": username,
        "text": msg,
        "icon_emoji": icon_emoji,
    })
    req = urllib2.Request(endpoint, data, {'Content-Type': 'application/json'})
    urllib2.urlopen(req).close()

@@ -166,17 +166,31 @@
 #channel
-:
+s:%0A        #  -
  %22#deplo
@@ -297,16 +297,52 @@
 eprints%0A
+from collections import OrderedDict%0A
 import u
@@ -427,16 +427,17 @@
  channel
+s
  = bluep
@@ -453,19 +453,21 @@
 'channel
+s
 ', 
+%5B
 '#deploy
@@ -467,18 +467,293 @@
 #deploy'
+%5D
 )%0A
+    channel = blueprint.get('channel', None)%0A%0A    # If channel is specified, add it to channels, and then run it through an%0A    # OrderedDict, removing any duplicates.%0A    if channel:%0A        channels.append(channel)%0A        channels = list(OrderedDict.fromkeys(channels))%0A%0A
     user
@@ -937,13 +937,175 @@
 urn 
-None%0A
+False%0A%0A    for channel in channels:%0A        send_request(endpoint, channel, username, msg, icon_emoji)%0A%0Adef send_request(endpoint, channel, username, msg, icon_emoji):
 %0A   
@@ -1245,16 +1245,17 @@
 %0A    %7D)%0A
+%0A
     req 

Add support for notifying multiple channels