feishu-rails 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b49a7ba4343fbd7ae4e4d35d00e999cbdd54a568cff97634bcbf6fdda102862
4
- data.tar.gz: 2b1117e10d4c5b2cd6f6097dd3f8c66313fac00c2058cd138af6e661cc4836d7
3
+ metadata.gz: 6804988e9d3dcce71102da60cdf71cac5e9b1e1627835f022c082e9e0585310f
4
+ data.tar.gz: 9dfe63a9194bcb9c6f8bfd4f75bc5bd76d4112748c9fe792d0e7f5e9a4f4e610
5
5
  SHA512:
6
- metadata.gz: 41c6b52e05e546e709f3993cec155858be0d898069dafc83e9e64c576343045e1f3cda5fcc940c685b0a3793abe5b73d75f871c4444ee6ffa4b2c1bc3df7d6cd
7
- data.tar.gz: c040c72e826d829ccee8bd2cfb6773c05cc28156659abc0fd5a3a82b022b74f1637b1f7deb38f085a85993e270131c55b577481bf0cdbc2ff51a7756b633ae35
6
+ metadata.gz: b633d47d579b2a9f9fb3539880976fc4084bbeb6c8141f852bfd99c6886823d4b1ca851fb17bcb263d3d3d47b8dd4d96e9821edcb4287016955ab53d8ae3f303
7
+ data.tar.gz: 9f1819889b23fec6163fef128db9cf30640eeac0decc881f036cf9f3e44872e8193b56e9470f0cbbe0ebf36917d317d14cc19f584ede94d297bbcb8a85b6858f
@@ -17,18 +17,9 @@ module Feishu
17
17
  GROUP_INFO = "https://open.feishu.cn/open-apis/chat/v4/info"
18
18
  SEND_TEXT = "https://open.feishu.cn/open-apis/message/v4/send"
19
19
 
20
- # 获取飞书 TOKEN 并缓存
21
- def access_token
22
- Rails.cache.fetch("feishu_token", expires_in: 30.minutes) do
23
- # res = HTTP.post(AUTH_URL, json: { app_id: app_id, app_secret: app_secret })
24
- res = HTTP.post(AUTH_URL, json: { app_id: Feishu.app_id, app_secret: Feishu.app_secret })
25
- JSON.parse(res.body.readpartial)["tenant_access_token"]
26
- end
27
- end
28
-
29
20
  # 认证成功后,后续请求都携带 TOKEN
30
21
  def request
31
- HTTP.headers(Authorization: "Bearer #{access_token}")
22
+ HTTP.headers(Authorization: "Bearer #{feishu_token}")
32
23
  end
33
24
 
34
25
  # 根据手机号码查询用户的 USER_ID
@@ -107,6 +98,10 @@ module Feishu
107
98
 
108
99
  # 向特定群组发生消息
109
100
  def send_alert(chat_id, title, content, image_path)
101
+ # 获取上传文件路径
102
+ uploaded_image_path = upload_image(image_path)
103
+
104
+ # 初始化数据结构
110
105
  data = {
111
106
  chat_id: chat_id,
112
107
  msg_type: "post",
@@ -139,6 +134,9 @@ module Feishu
139
134
  }
140
135
  }
141
136
  }
137
+ # 如果图片不存在则移除相关属性
138
+ data[:content][:post][:zh_cn][:content].pop if uploaded_image_path.blank?
139
+
142
140
  # 请求后端
143
141
  res = request.post(SEND_TEXT, json: data)
144
142
 
@@ -149,4 +147,14 @@ module Feishu
149
147
  Rails.logger("群发消息期间捕捉到异常:#{e}")
150
148
  end
151
149
  end
150
+
151
+ private
152
+ def feishu_token
153
+ # 获取飞书 TOKEN 并缓存
154
+ Rails.cache.fetch("feishu_token", expires_in: 30.minutes) do
155
+ # res = HTTP.post(AUTH_URL, json: { app_id: app_id, app_secret: app_secret })
156
+ res = HTTP.post(AUTH_URL, json: { app_id: Feishu.app_id, app_secret: Feishu.app_secret })
157
+ JSON.parse(res.body.readpartial)["tenant_access_token"]
158
+ end
159
+ end
152
160
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Feishu
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feishu-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - WENWU.YAN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails