Giter VIP home page Giter VIP logo

ezslack's Introduction

EzSlack

EzSlack is a Python framework wrapping Bolt for Python to provide useful utilities.

  • Encapsule parsing low-level information
  • Provide Handler class to improve cohesion

Get Started

from ezslack import App

# Running over HTTP
app = App(token=SLACK_BOT_TOKEN, signing_secret=SLACK_SIGNING_SECRET)
app.start(PORT)

# Running in Socket Mode
app = App(token=SLACK_BOT_TOKEN)
app.start_socket_mode(SLACK_APP_TOKEN)

Handler

Whenever subclass of Handler is defined, handler methods are registered in REGISTRIES. String arguments in handler decorator are automatically converted into regex pattern with anchors. Matched groups are passed to arguments and keyword arguments whether they are named.

from ezslack import Handler, message

class MyHandler(Handler):
    @message("hello", "hi")
    def greet(self):
        self.ack()
        self.say(
            f"Nice to meet you <@{self.user_id}>",
            thread_ts=self.thread_ts,
        )

    @message(r"(?P<first>\w+)(?P<op>[+*])(?P<second>\w+)")
    def calculate(self, first, second, op):
        if op == "+":
            result = int(first) + int(second)
        else:
            result = int(first) * int(second)
        self.say(f"Result: {result}", thread_ts=self.thread_ts)

Supported features

Requests supported: ACTION, MESSAGE, VIEW_CLOSED, VIEW_SUBMISSION

Each request has an id such as action_id, message.text, callback_id. When a request id matches handling method's regex pattern, handler is instantiated with the following context fields, then call the method.

field type description event
ack Ack See Reference -
client WebClient See Reference -
respond Respond See Reference -
say Say See Reference -
channel_id Optional[str] Channel where the event was triggered ACTION, MESSAGE
channel_name Optional[str] Channel where the event was triggered MESSAGE
message_ts Optional[str] Timestamp of the message ACTION, MESSAGE
metadata Optional[Metadata] Metadata of the message ACTION
private_metadata Optional[str] Private metadata of the view VIEW_SUBMISSION, VIEW_CLOSED
request_id str Identifier such as action_id, message.text, callback_id which is used to match handler -
thread_ts Optional[str] Timestamp of the thread ACTION, MESSAGE
trigger_id Optional[str] Trigger id from the event ACTION
user_id Optional[str] User who triggers the event -
user_name Optional[str] User who triggers the event ACTION, VIEW_SUBMISSION, VIEW_CLOSED
bot_id Optional[str] Bot which triggers the event MESSAGE
view_state Optional[ViewState] View state which has selected values VIEW_SUBMISSION, VIEW_CLOSED

ezslack's People

Contributors

taekop avatar

Stargazers

YooSeok Jeong avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.