slackpost.py: Write a script for posting to slack
The idea is that postfix will pipe an email message into this script, which will then post the reply to slack. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
d9a6858be8
commit
6110e5ff3b
|
@ -3,6 +3,7 @@
|
||||||
#
|
#
|
||||||
from . import api
|
from . import api
|
||||||
from . import auth
|
from . import auth
|
||||||
|
from . import chat
|
||||||
from . import users
|
from . import users
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -35,6 +36,9 @@ class Channel:
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__name
|
return self.__name
|
||||||
|
|
||||||
|
def post(self, text):
|
||||||
|
chat.postMessage(self.__id, text)
|
||||||
|
|
||||||
def unread_count(self):
|
def unread_count(self):
|
||||||
if self.__unread == None:
|
if self.__unread == None:
|
||||||
self.fetch_info()
|
self.fetch_info()
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#
|
||||||
|
# Copyright 2015 (c) Anna Schumaker.
|
||||||
|
#
|
||||||
|
from . import api
|
||||||
|
from . import auth
|
||||||
|
from urllib import request
|
||||||
|
|
||||||
|
def postMessage(channel, text):
|
||||||
|
post = request.quote(text)
|
||||||
|
api.call("chat.postMessage", token = auth.token(), channel = channel,
|
||||||
|
text = post, as_user = True, parse = "full")
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# Copyright 2015 (c) Anna Schumaker.
|
||||||
|
#
|
||||||
|
|
||||||
|
import slack
|
||||||
|
import sys
|
||||||
|
from email.parser import Parser
|
||||||
|
|
||||||
|
headers = Parser().parsestr(sys.stdin.read())
|
||||||
|
|
||||||
|
if headers['from'] != "Anna Schumaker <schumaker.anna@gmail.com>":
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Determine which channel to post to
|
||||||
|
channel = None
|
||||||
|
subject = headers['subject']
|
||||||
|
ch_name = subject.split("[%s]" % slack.team())[-1].strip()
|
||||||
|
|
||||||
|
for c in slack.channels.list():
|
||||||
|
if c.name() == ch_name:
|
||||||
|
channel = c
|
||||||
|
break
|
||||||
|
|
||||||
|
if channel == None:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
text = headers.get_payload().split("\n")[0]
|
||||||
|
channel.post(text)
|
Loading…
Reference in New Issue