Skip to content

Instantly share code, notes, and snippets.

@VictorVelarde
Created March 28, 2016 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorVelarde/2883e93bb80d2c294a5c to your computer and use it in GitHub Desktop.
Save VictorVelarde/2883e93bb80d2c294a5c to your computer and use it in GitHub Desktop.
UTIL - Enviar notificación a #canal de slack
# -*- 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