Sha256: 3c53c910982bcdfd0a1d3cb5cb07eaa405ffe1a4d5a4e8c519b57210fba134f2
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Dingtalk class Robot # Markdown type strategy for sending message class MarkdownStrategy def initialize(webhook_url, message) @webhook_url = webhook_url @message = message end # @option options [String] :title # @option options [Array<String>] :at_mobiles # @option options [Boolean] :is_at_all def notify(**options) title = options[:title].to_s raise ArgumentError, 'title must be present, strategy: markdown' if title.empty? at_mobiles = options[:at_mobiles].to_a is_at_all = options[:is_at_all] ? true : false body = generate_body(title, at_mobiles, is_at_all) 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(title, at_mobiles, is_at_all) { msgtype: :markdown, markdown: { title: title, text: message }, at: { atMobiles: at_mobiles, isAtAll: is_at_all } } 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/markdown_strategy.rb |