Instantly share code, notes, and snippets.

@artnc /router.py
Last active Sep 6, 2017

Embed
What would you like to do?
import hashlib
import requests
from flask import Flask, request
SLACK_CHANNEL = '#general'
SLACK_TOKEN = '********'
app = Flask(__name__)
@app.route('/mail', methods=['POST'])
def mail():
text = request.form.get('subject', '[unknown]')
sender = request.form.get('from', request.form.get('sender', '[unknown]'))
if ' <' in sender:
sender = sender.split(' <')[0]
sender_hash = hashlib.sha1(sender).hexdigest()
avatar = 'http://www.gravatar.com/avatar/%s?d=retro' % sender_hash
requests.get(
'https://slack.com/api/chat.postMessage',
params={
'channel': SLACK_CHANNEL,
'icon_url': avatar,
'parse': 'full',
'text': text,
'token': SLACK_TOKEN,
'username': sender,
}
)
return 'OK'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8003)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment