feishu-rails 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/lib/feishu/config.rb +11 -0
- data/lib/feishu/connector.rb +126 -0
- data/lib/feishu/version.rb +3 -0
- data/lib/feishu-rails.rb +11 -0
- data/lib/tasks/feishu_tasks.rake +4 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2030f453ffa2e384f6d766656948f31f4d021c2cb96a6da5643115f09f8297f
|
4
|
+
data.tar.gz: 4eea7d97ec5ac0a7ea3b20669b64fa8af4e47bb2d2edbe96ea5a9ba87dc72d25
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b84e308a70eaf69998a4af529a128f036d9a1d643e63c1866e4c978f1d075ad247c779731b4b3b18d4dd7624fa944377cb1f7c3974c1063e53560529397c39ce
|
7
|
+
data.tar.gz: 8dbdee672500a5faf4987fdc41da32c13d2ab4b6afa5108d38b70af17087f9c07af946ea7f8ca8fa3c3db860a4c164e20b41cc8394c1a1dc4f239df6f6a98e40
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Feishu
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "feishu"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install feishu
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Feishu
|
2
|
+
class << self
|
3
|
+
# 定义常用的 URL
|
4
|
+
AUTH_URL = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/"
|
5
|
+
USER_INFO = "https://open.feishu.cn/open-apis/contact/v1/user/batch_get"
|
6
|
+
GROUP_LIST = "https://open.feishu.cn/open-apis/chat/v4/list"
|
7
|
+
GROUP_INFO = "https://open.feishu.cn/open-apis/chat/v4/info"
|
8
|
+
SEND_TEXT = "https://open.feishu.cn/open-apis/message/v4/send/"
|
9
|
+
IMAGE_URL = "https://open.feishu.cn/open-apis/im/v1/images"
|
10
|
+
MESSAGE_URL = "https://open.feishu.cn/open-apis/im/v1/messages"
|
11
|
+
|
12
|
+
# 获取飞书 TOKEN 并缓存
|
13
|
+
def access_token
|
14
|
+
Rails.cache.fetch("feishu_token", expires_in: 2.hours) do
|
15
|
+
app_id = "cli_a2b7a1fa17b8d00c"
|
16
|
+
app_secret = "9FIkmECaknhRryyWCH2bngErcbbvQg4G"
|
17
|
+
res = HTTP.post(AUTH_URL, json: { app_id: app_id, app_secret: app_secret })
|
18
|
+
# res = HTTP.post(AUTH_URL, json: { app_id: Config.app_id, app_secret: Config.app_secret })
|
19
|
+
JSON.parse(res.body.readpartial)["tenant_access_token"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# 认证成功后,后续请求都携带 TOKEN
|
24
|
+
def request
|
25
|
+
HTTP.headers(Authorization: "Bearer #{access_token}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def batch_user_info(open_ids)
|
29
|
+
res = request.get(USER_INFO, params: { open_ids: open_ids })
|
30
|
+
users = JSON.parse(res.body.readpartial)
|
31
|
+
|
32
|
+
users["data"]
|
33
|
+
end
|
34
|
+
|
35
|
+
# 获取机器人所在的群列表
|
36
|
+
def group_list(page_size = 200, page = nil)
|
37
|
+
# 请求后端
|
38
|
+
res = request.get(GROUP_LIST, params: { page_size: page_size, page_token: page })
|
39
|
+
# 序列化
|
40
|
+
group_content = JSON.parse(res.body.readpartial)
|
41
|
+
|
42
|
+
group_content["data"]
|
43
|
+
end
|
44
|
+
|
45
|
+
# 获取群信息
|
46
|
+
def group_info(chat_id)
|
47
|
+
# 请求后端
|
48
|
+
res = request.get(GROUP_INFO, params: { chat_id: chat_id })
|
49
|
+
# 序列化
|
50
|
+
group_users_content = JSON.parse(res.body.readpartial)
|
51
|
+
|
52
|
+
group_users_content["data"]["members"]
|
53
|
+
end
|
54
|
+
|
55
|
+
# 获取群成员信息
|
56
|
+
# def member_list(chat_id)
|
57
|
+
# res = request.get("https://open.feishu.cn/open-apis/chat/v4/members", :params => {:chat_id=> chat_id})
|
58
|
+
# group_users_content = JSON.parse(res.body.readpartial)
|
59
|
+
|
60
|
+
# member_ids = group_users_content["data"]
|
61
|
+
# end
|
62
|
+
|
63
|
+
def upload_image(image_path)
|
64
|
+
# 读取图片
|
65
|
+
data = HTTP::FormData::File.new image_path
|
66
|
+
|
67
|
+
# 请求后端
|
68
|
+
res = request.post(IMAGE_URL, form: { image_type: "message", image: data })
|
69
|
+
ret = JSON.parse res.body.readpartial
|
70
|
+
# 返回上传后的序列号
|
71
|
+
ret["data"]["image_key"]
|
72
|
+
end
|
73
|
+
|
74
|
+
# 发送文本消息
|
75
|
+
def send_text(open_id, text)
|
76
|
+
# 请求后端
|
77
|
+
res = request.post(SEND_TEXT, json: { open_id: open_id, msg_type: "text", content: { text: text } })
|
78
|
+
# 序列化
|
79
|
+
JSON.parse(res.body.readpartial)
|
80
|
+
end
|
81
|
+
|
82
|
+
# 使用推荐的消息接口
|
83
|
+
def send_message(receive_type, receive_id, msg_type, content)
|
84
|
+
# 请求后端
|
85
|
+
res = request.post(MESSAGE_URL, params: { receive_id_type: receive_type }, json: { receive_id: receive_id, msg_type: msg_type, content: content })
|
86
|
+
# 序列化
|
87
|
+
JSON.parse(res.body.readpartial)
|
88
|
+
end
|
89
|
+
|
90
|
+
# def send_alert(chat_id)
|
91
|
+
# data = {
|
92
|
+
# "chat_id": chat_id,
|
93
|
+
# "msg_type": "post",
|
94
|
+
# "content": {
|
95
|
+
# "post": {
|
96
|
+
# "zh_cn": {
|
97
|
+
# "title": title,
|
98
|
+
# "content": [
|
99
|
+
# [
|
100
|
+
# {
|
101
|
+
# "tag": "text",
|
102
|
+
# "un_escape": True,
|
103
|
+
# "text": content
|
104
|
+
# },
|
105
|
+
# {
|
106
|
+
# "tag": "at",
|
107
|
+
# "user_id": self.user_id
|
108
|
+
#
|
109
|
+
# },
|
110
|
+
# ],
|
111
|
+
# [
|
112
|
+
# {
|
113
|
+
# "tag": "img",
|
114
|
+
# "image_key": self.image_key,
|
115
|
+
# "width": 1000,
|
116
|
+
# "height": 600
|
117
|
+
# }
|
118
|
+
# ]
|
119
|
+
# ]
|
120
|
+
# }
|
121
|
+
# }
|
122
|
+
# }
|
123
|
+
# }
|
124
|
+
# end
|
125
|
+
end
|
126
|
+
end
|
data/lib/feishu-rails.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feishu-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WENWU.YAN
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: use faraday send alerts to feishu robot
|
28
|
+
email:
|
29
|
+
- careline@foxmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/feishu-rails.rb
|
37
|
+
- lib/feishu/config.rb
|
38
|
+
- lib/feishu/connector.rb
|
39
|
+
- lib/feishu/version.rb
|
40
|
+
- lib/tasks/feishu_tasks.rake
|
41
|
+
homepage: https://github.com/ciscolive/feishu-rails
|
42
|
+
licenses: []
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://github.com/ciscolive/feishu-rails
|
45
|
+
source_code_uri: https://github.com/ciscolive/feishu-rails
|
46
|
+
changelog_uri: https://github.com/ciscolive/feishu-rails/blob/main/README.md
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.3.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: 主要实现对接飞书机器人
|
66
|
+
test_files: []
|