Class: Pindo::FeishuClient
- Inherits:
-
Object
- Object
- Pindo::FeishuClient
- Defined in:
- lib/pindo/client/feishuclient.rb
Instance Method Summary collapse
-
#initialize(webhook_url, secret = nil) ⇒ FeishuClient
constructor
A new instance of FeishuClient.
- #send_card_message(title, content) ⇒ Object
- #send_markdown(title, markdown_content) ⇒ Object
- #send_message(message) ⇒ Object
- #send_rich_text(title, content) ⇒ Object
Constructor Details
#initialize(webhook_url, secret = nil) ⇒ FeishuClient
Returns a new instance of FeishuClient.
13 14 15 16 |
# File 'lib/pindo/client/feishuclient.rb', line 13 def initialize(webhook_url, secret = nil) @webhook_url = webhook_url @secret = secret end |
Instance Method Details
#send_card_message(title, content) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/pindo/client/feishuclient.rb', line 132 def (title, content) payload = { msg_type: "interactive", card: { config: { wide_screen_mode: true }, header: { title: { tag: "plain_text", content: title } }, elements: [ { tag: "div", text: { tag: "plain_text", content: content } } ] } } response = send_request(payload) puts "发送结果: #{response['msg']}" if response['msg'] response end |
#send_markdown(title, markdown_content) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/pindo/client/feishuclient.rb', line 162 def send_markdown(title, markdown_content) # 提取一级标题作为消息标题 lines = markdown_content.split("\n") title_match = lines.find { |line| line.strip =~ /^# (.+)/ } = title_match ? $1.strip : title # 移除原始的一级标题 content_without_title = lines.reject { |line| line.strip =~ /^# / }.join("\n") # 格式化剩余内容 formatted_content = format_markdown_content(content_without_title) payload = { msg_type: "interactive", card: { config: { wide_screen_mode: true }, header: { title: { tag: "plain_text", content: , style: { bold: true, size: 32 # 增大标题字体到32 } } }, elements: [ { tag: "div", text: { tag: "lark_md", content: formatted_content } } ] } } response = send_request(payload) puts "发送结果: #{response['msg']}" if response['msg'] response end |
#send_message(message) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/pindo/client/feishuclient.rb', line 94 def () payload = { msg_type: "text", content: { text: } } response = send_request(payload) puts "发送结果: #{response['msg']}" if response['msg'] response end |
#send_rich_text(title, content) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/pindo/client/feishuclient.rb', line 107 def send_rich_text(title, content) payload = { msg_type: "post", content: { post: { zh_cn: { title: title, content: [ [ { tag: "text", text: content } ] ] } } } } response = send_request(payload) # puts "发送结果: #{response['msg']}" if response['msg'] response end |