Created
March 28, 2016 07:42
-
-
Save VictorVelarde/2883e93bb80d2c294a5c to your computer and use it in GitHub Desktop.
UTIL - Enviar notificación a #canal de slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Created on 28/3/2016 | |
@author: velardev | |
''' | |
import urllib2 | |
import json | |
class Slack(object): | |
''' | |
Clase para enviar mensajes simples a Slack, vía 'Incoming WebHooks' | |
''' | |
def __init__(self, url='https://hooks.slack.com/services/URL_DEL_CANAL_EN_EL_QUE_RECIBIR_LA_NOTIFICACION'): | |
''' | |
inicio con el #canal por defecto | |
''' | |
self.url = url | |
def enviarMensaje(self, origen, mensaje): | |
datos = { | |
'username': origen, | |
'text': mensaje, | |
"icon_emoji": ":monkey_face:" | |
} | |
peticion = urllib2.Request(self.url) | |
peticion.add_data(json.dumps(datos)) | |
return urllib2.urlopen(peticion) | |
if __name__ == "__main__": | |
s = Slack() | |
s.enviarMensaje('ProgramaTest', 'Esto es un TEST') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment