GithubHelp home page GithubHelp logo

jusleg / slackify Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 11.0 111 KB

Build Slackbot on Rails using Slack Event API

Home Page: https://rubygems.org/gems/slackify

License: MIT License

Ruby 89.46% JavaScript 1.64% CSS 1.04% HTML 7.87%
slack slackbot gem rails rails-engine

slackify's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

slackify's Issues

Example in readme throws InvalidHandler exception on startup

I've added the RepeatHandler as documented here but (on Rails 7 at least) this gives an exception: repeat_handler is not defined (Slackify::Exceptions::InvalidHandler) ... in 'constantize': uninitialized constant RepeatHandler (NameError).

This is because the Slackify.configure call in config/initializers/slackify.rb is attempting to register the handlers, but they have not been loaded by Rails' autoloader yet.

After reading these docs, I tried using Rails.application.config.to_prepare in config/initializers/slackify.rb:

Rails.application.config.to_prepare do
  Slackify.configure do |config|
    config.slack_bot_token = ...
    config.slack_secret_token = ...
  end
end

This stops the exception on startup, but any changes to the handlers are not loaded until you manually reset the server.

I've also tried adding config.autoload_once_paths << "#{root}/app/handlers" to config/application.rb and again it fixes the startup error but changes to handlers are not loaded without manually resetting.

Add support for parsing block_id and action_id interactive callback

Ran into issue when calling chat_unfurl Slack API method where the payload for unfurls: doesn't accept callback_id in the JSON. Resulting error: WARN: Slack::Web::Api::Errors::CannotParseAttachment: cannot_parse_attachment

From Slack support: Unfortunately, that[chat_unfurl] method doesn't support the use of callback_id
Slack support informs me that we should instead be looking for block_id or action_id for the interactive callback for that method.

Fix deprecation warnings

When running in development, we encounter a lot of DEPRECATION WARNING: Initialization autoloaded the constants [...]

Investigate slack blocks

Slack recently made public the block kit for richer attachments. This new UI framework doesn't make use of callback_id and favors unique action_id per button/interactive field. I believe we could introduce compatibility in the framework by making those action_id work like a callback_id. We currently have the following format in the callback_id: handler_name#method_name. This won't work with the block components as two buttons could have the same action_id.

I believe this could be fixed by appending extra stuff to the action id just to make it unique and pass slack's payload verification. For instance, we could have a simple counter after the method name. This would ensure uniqueness and we will just not take into account the counter value when parsing.

Example

button1_action_id = my_handler#my_method#1

button2_action_id = my_handler#my_method#2

Then we run something like:

action_id.split('#').tap |parsed_action_id|
  handler = parsed_action_id.first
  method = parsed_action_id.second
end

The counter could be introduced in a wrapper for the attachments. We send non slack approved block attachments (blocks having duplicate action id) and we make them valid by adding the counter to it. Hardcoded attachments will not need to use the wrapper, but on the fly attachments could make use of it.

Questions left to be answered before going forward

  • Does slack send the original attachments in the event API payload?

  • What's the difference between a regular interactive event vs a block event in a callback?

  • Did slack introduce a new interaction type in their callback API? (It would make our lives way easier if they did

Is slack-ruby-client ready to handle block payloads?
Yes, it is ๐Ÿ˜„

Can we still edit/delete messages the same way (3-second reply window, response URL for 30 min and channel + ts for any time)?
No, the response url is the only way of doing it right now. Perhaps a good way would be to add a method in which you pass a response url and a new payload to make the code look similar to the previous behaviour

TL;DR

Use the action_id as if it was a callback_id to trick slack into sending our old payload logic into the fancy new block attachments. It would be cool ๐Ÿ˜„

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.