Sha256: cb893e71fde05539f9d78fda66a8cebd893dbd04bff363eb4ef5a1e48013ccd3
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true module Dingtalk class Robot # Markdown type strategy for sending message class FeedCardStrategy Link = Struct.new(:title, :messageURL, :picURL) def initialize(webhook_url, message) @webhook_url = webhook_url @message = message end # @option options [Array<Link>, Link] :links def notify(**options) links = Array.wrap(options[:links]) all_present = links.all? { |link| link.all?(&:present?) } raise ArgumentError, 'All items of links must be present, strategy: feed_card' unless all_present body = generate_body(links) headers = { 'Content-Type': 'application/json', Accept: 'application/json' } Net::HTTP.post(URI(webhook_url), body.to_json, headers).body end private attr_reader :webhook_url, :message def generate_body(links) { msgtype: 'feedCard', feedCard: { links: links } } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dingtalk-robot-0.2.1 | lib/dingtalk/robot/strategies/feed_card_strategy.rb |