diff –git a/lib/slack/web/api/endpoints/chat.rb b/lib/slack/web/api/endpoints/chat.rb index d090ae2..50186d5 100644 — a/lib/slack/web/api/endpoints/chat.rb +++ b/lib/slack/web/api/endpoints/chat.rb @@ -121,11 +121,22 @@ module Slack
# @see https://api.slack.com/methods/chat.postEphemeral # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.postEphemeral.json def chat_postEphemeral(options = {})
-
throw ArgumentError.new('Required arguments :attachments missing') if options.nil? throw ArgumentError.new('Required arguments :channel missing') if options.nil?
-
throw ArgumentError.new('Required arguments :text missing') if options.nil?
+ throw ArgumentError.new('Required arguments :text, :attachments or :blocks missing') if options.nil? && options.nil? && options.nil?
throw ArgumentError.new('Required arguments :user missing') if options[:user].nil? options = options.merge(user: users_id(options)['user']['id']) if options[:user]
+ # attachments must be passed as an encoded JSON string + if options.key?(:attachments) + attachments = options + attachments = JSON.dump(attachments) unless attachments.is_a?(String) + options = options.merge(attachments: attachments) + end + # blocks must be passed as an encoded JSON string + if options.key?(:blocks) + blocks = options + blocks = JSON.dump(blocks) unless blocks.is_a?(String) + options = options.merge(blocks: blocks) + end
post('chat.postEphemeral', options) end
@@ -168,6 +179,19 @@ module Slack
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.postMessage.json def chat_postMessage(options = {}) throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
+ throw ArgumentError.new('Required arguments :text, :attachments or :blocks missing') if options.nil? && options.nil? && options.nil? + # attachments must be passed as an encoded JSON string + if options.key?(:attachments) + attachments = options + attachments = JSON.dump(attachments) unless attachments.is_a?(String) + options = options.merge(attachments: attachments) + end + # blocks must be passed as an encoded JSON string + if options.key?(:blocks) + blocks = options + blocks = JSON.dump(blocks) unless blocks.is_a?(String) + options = options.merge(blocks: blocks) + end
post('chat.postMessage', options) end
@@ -257,8 +281,21 @@ module Slack
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.update.json def chat_update(options = {}) throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
+ throw ArgumentError.new('Required arguments :text, :attachments or :blocks missing') if options.nil? && options.nil? && options.nil?
throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil? options = options.merge(channel: conversations_id(options)['channel']['id']) if options[:channel]
+ # attachments must be passed as an encoded JSON string + if options.key?(:attachments) + attachments = options + attachments = JSON.dump(attachments) unless attachments.is_a?(String) + options = options.merge(attachments: attachments) + end + # blocks must be passed as an encoded JSON string + if options.key?(:blocks) + blocks = options + blocks = JSON.dump(blocks) unless blocks.is_a?(String) + options = options.merge(blocks: blocks) + end
post('chat.update', options) end end