#!/usr/bin/env/ python # coding: utf-8 from flask import Flask from flask_slack import Slack import requests import json import threading app = Flask(__name__) slack = Slack(app) app.add_url_rule('/', view_func=slack.dispatch) # On GCE, we're using files mounted at /secret for # incoming webhook URL and team token # Or you can hard-code values in the except blocks below. try: with open('/secret/hookurl', 'r') as hookf: url = hookf.read().strip() except: url = ("https://hooks.slack.com/services/T02594HP0/B081REU01" "/PjOvu5UAGNgVKUTydc3GqS6L") # <- fake ;) try: with open('/secret/token', 'r') as tokenf: valid = tokenf.read().strip() except: valid = "bZKQqL4qkCOORlwzJRAPAvNc" # phony try: with open('/secret/teamid', 'r') as teamf: team = teamf.read().strip() except:
def __init__(self): self.app = Flask(__name__) self.app.debug = True self.slack = Slack(self.app) self.app.add_url_rule('/', view_func=self.slack.dispatch) self.client = self.app.test_client()
import sendgrid, os from flask_slack import Slack from flask import Flask from slacker import Slacker import time # TEAM_ID = os.environ.get('TEAM_ID') SLACK_API_TOKEN = os.environ.get('SLACK_API_TOKEN') SCRATCH_COMMAND_TOKEN = os.environ.get('SCRATCH_COMMAND_TOKEN') # Initalize everything app = Flask(__name__) slash = Slack(app) slack = Slacker(SLACK_API_TOKEN) # Get list of users in slack org user_list = slack.users.list().body['members'] emails = filter(None, [u['profile']['email'] for u in user_list]) admins = set(u['id'] for u in user_list if u['is_admin']) @slash.command(command='email', token=SCRATCH_COMMAND_TOKEN, team_id=TEAM_ID, methods=['POST']) def email_command(**kwargs): text = kwargs.get('text') # check if user is admin user_id = kwargs.get('user_id') if user_id in admins : return slash.response("Sorry, you must be an admin to use this command.")
from flask_slack import Slack slack = Slack()