def __init__(self): self.app = Flask(__name__) self.app.debug = True self.app.config['SLACK_TOKEN'] = 'Your token here' self.app.config['SLACK_CALLBACK'] = '/slack_callback' self.slackbot = SlackBot(self.app) self.slackbot.set_handler(self.fn) self.client = self.app.test_client()
class App(object): def __init__(self): self.app = Flask(__name__) self.app.debug = True self.app.config['SLACK_TOKEN'] = 'Your token here' self.app.config['SLACK_CALLBACK'] = '/slack_callback' self.slackbot = SlackBot(self.app) self.slackbot.set_handler(self.fn) self.client = self.app.test_client() @staticmethod def fn(kwargs): return {'text': kwargs['text']}
class App(object): def __init__(self): self.app = Flask(__name__) self.app.debug = True self.app.config["SLACK_TOKEN"] = "Your token here" self.app.config["SLACK_CHAT_TOKEN"] = "Your token here" self.app.config["SLACK_CALLBACK"] = "/slack_callback" self.slackbot = SlackBot(self.app) self.slackbot.set_handler(self.fn) self.client = self.app.test_client() @staticmethod def fn(kwargs): return {"text": kwargs["text"]}
def __init__(self): self.app = Flask(__name__) self.app.debug = True self.app.config["SLACK_TOKEN"] = "Your token here" self.app.config["SLACK_CHAT_TOKEN"] = "Your token here" self.app.config["SLACK_CALLBACK"] = "/slack_callback" self.slackbot = SlackBot(self.app) self.slackbot.set_handler(self.fn) self.client = self.app.test_client()
def create_app(config=None): app = Flask(__name__) app.config.from_object(settings) if isinstance(config, dict): app.config.update(config) elif config: app.config.from_pyfile(os.path.realpath(config)) redis_store.init_app(app) cache.init_app(app) app.plugin_modules = plugin_modules slackbot = SlackBot(app) _callback = partial(callback, app=app) slackbot.set_handler(_callback) slackbot.filter_outgoing(_filter) return app
def create_app(config=None): app = Flask(__name__) app.config.from_object(settings) if isinstance(config, dict): app.config.update(config) elif config: app.config.from_pyfile(os.path.realpath(config)) redis_store.init_app(app) cache.init_app(app) app.cache = cache app.plugin_modules = plugin_modules slackbot = SlackBot(app) slackbot.set_handler(callback) slackbot.filter_outgoing(_filter) return app
# coding=utf-8 from flask import Flask from flask_slackbot import SlackBot app = Flask(__name__) app.config['SLACK_TOKEN'] = 'Your token here' app.config['SLACK_CALLBACK'] = '/slack_callback' app.debug = True slackbot = SlackBot(app) def fn1(kwargs): return {'text': '!' + kwargs['text']} def fn2(kwargs): slackbot.slack.chat.post_message('#general', 'hello from slacker handler') return None def fn3(text): return text.startswith('!') slackbot.set_handler(fn1) slackbot.filter_outgoing(fn3) if __name__ == "__main__":
# coding=utf-8 from flask import Flask from flask_slackbot import SlackBot app = Flask(__name__) app.config['SLACK_TOKEN'] = 'Your token here' app.config['SLACK_CALLBACK'] = '/slack_callback' app.debug = True slackbot = SlackBot(app) ''' The parameter of the callback function is a dict returns from the slack's outgoing api. Here is the detail: kwargs { 'token': token, 'team_id': team_id, 'team_domain': team_domain, 'channel_id': channel_id, 'channel_name': channel_name, 'timestamp': timestamp, 'user_id': user_id, 'user_name': user_name, 'text': text, 'trigger_word': trigger_word }''' def fn1(kwargs): '''
app = create_app() def callback(kwargs): s = kwargs['text'] if isinstance(s, unicode): s = s.encode('utf-8') private = True if 'private' in s or '私聊' in s else False data = {'message': s.replace('私聊', '', 1)} bot = None for plugin_module in plugin_modules: if plugin_module.test(data, bot): rv = plugin_module.handle(data, bot, kv=None, app=app) return {'text': '!' + rv, 'private': private} return {'text': '!呵呵'} def _filter(line): return line.startswith('!') slackbot = SlackBot(app) slackbot.set_handler(callback) slackbot.filter_outgoing(_filter) if __name__ == '__main__': app.run()
redis_store.init_app(app) return app app = create_app() def callback(kwargs): s = kwargs['text'] if isinstance(s, unicode): s = s.encode('utf-8') data = {'message': s} bot = None for plugin_module in plugin_modules: if plugin_module.test(data, bot): rv = plugin_module.handle(data, bot, kv=None, app=app) return {'text': '!' + rv} return {'text': '!呵呵'} def _filter(line): return line.startswith('!') slackbot = SlackBot(app) slackbot.set_handler(callback) slackbot.filter_outgoing(_filter) if __name__ == '__main__': app.run()