Skip to content

Instantly share code, notes, and snippets.

@artnc
Last active September 6, 2017 22:04
Show Gist options
  • Save artnc/83ce08d254d361df9f7bf7a04c9b2649 to your computer and use it in GitHub Desktop.
Save artnc/83ce08d254d361df9f7bf7a04c9b2649 to your computer and use it in GitHub Desktop.
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