예제 #1
0
 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()
예제 #2
0
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']}
예제 #3
0
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']}
예제 #4
0
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"]}
예제 #5
0
 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()
예제 #6
0
 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()
예제 #7
0
파일: app.py 프로젝트: orangle/slack_bot
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
예제 #8
0
파일: app.py 프로젝트: xzonepiece/slack_bot
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
예제 #9
0
# 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__":
예제 #10
0
# 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):
    '''
예제 #11
0
파일: app.py 프로젝트: ghostviper/slack_bot

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()
예제 #12
0
파일: app.py 프로젝트: halfcrazy/slack_bot
    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()