From 84bb2a9bcd24205d19063a6c8dd5eafb7dd89b08 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 14 Sep 2023 16:56:13 +0530 Subject: [PATCH] fix: add monkey patch for slack chat_unfurl method --- config/initializers/monkey_patches/chat.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 config/initializers/monkey_patches/chat.rb diff --git a/config/initializers/monkey_patches/chat.rb b/config/initializers/monkey_patches/chat.rb new file mode 100644 index 000000000..c71d907c1 --- /dev/null +++ b/config/initializers/monkey_patches/chat.rb @@ -0,0 +1,21 @@ +module Slack + module Web + module Api + module Endpoints + module Chat + # TODO: Remove this monkey patch when PR for this issue https://github.com/slack-ruby/slack-ruby-client/issues/388 is merged + def chat_unfurl(options = {}) + if (options[:channel].nil? || options[:ts].nil?) && (options[:unfurl_id].nil? || options[:source].nil?) + raise ArgumentError, 'Either a combination of :channel and :ts or :unfurl_id and :source is required' + end + + raise ArgumentError, 'Required arguments :unfurls missing' if options[:unfurls].nil? + + options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel] + post('chat.unfurl', options) + end + end + end + end + end +end