slack-ruby / slack-ruby-bot-server-events

Slack commands, interactive buttons, and events extension for slack-ruby-bot-server.
MIT License
71 stars 10 forks source link

How to handle multiple views? #21

Open hcyildirim opened 1 year ago

hcyildirim commented 1 year ago

Hi, seems like views_open is not catching up callback_ids, can you help me with that?

# start_new_modal.rb

def self.payload(trigger_id)
    {
      trigger_id: trigger_id,
      view: {
        type: "modal",
        callback_id: "unique-id",
        title: {
          type: "plain_text",
          text: "Start",
          emoji: true
        },
        submit: {
          type: "plain_text",
          text: "Submit",
          emoji: true
        },
        close: {
          type: "plain_text",
          text: "Cancel",
          emoji: true
        },
        blocks: [
          {
            block_id: "conversation",
            type: "input",
            label: {
              type: "plain_text",
              text: "Channel"
            },
            element: {
              action_id: "ml_conversation_input",
              type: "conversations_select",
              response_url_enabled: true,
              placeholder: {
                type: "plain_text",
                text: "Start typing #channel"
              }
            }
          },
        ]
      }
    }
  end
#  actions/task.rb

SlackRubyBotServer::Events.configure do |config|
  config.on :action, "block_actions" do |action|
      payload = StartNewModal.payload(trigger_id)
      slack_client.views_open(payload)
  end
end
# actions/start_new_modal.rb

SlackRubyBotServer::Events.configure do |config|
  config.on :action, 'view_submission', 'unique-id' do |action|
   # nothing comes here
  end
end
hcyildirim commented 1 year ago

@dblock could you help me please?

dblock commented 1 year ago

Usually I run this locally with ngrok, first thing to check is whether you get any notification from Slack, then whether you get any config.on :action do ..., etc.

hcyildirim commented 1 year ago

Yes, I get that from slack but the action file (actions/start_new_modal.rb) is not triggered at all. Only the default action is triggered.

If I don't add the unique-id everything seems to be fine. Seems like unique-id is corrupting something in the background

dblock commented 1 year ago

The code that parses the payload is here: https://github.com/slack-ruby/slack-ruby-bot-server-events/blob/master/lib/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint.rb. Looks like it only supports block_actions, message_action and shortcut. Care to contribute support for view_submission and view_closed (https://api.slack.com/reference/interaction-payloads/views#view_submission)?