Module: FeishuBot

Defined in:
lib/feishu_bot.rb,
lib/feishu_bot/api.rb,
lib/feishu_bot/config.rb,
lib/feishu_bot/engine.rb,
lib/feishu_bot/version.rb,
app/models/feishu_bot/feishu_user.rb,
app/jobs/feishu_bot/application_job.rb,
app/models/feishu_bot/application_record.rb,
app/helpers/feishu_bot/application_helper.rb,
app/mailers/feishu_bot/application_mailer.rb,
app/helpers/feishu_bot/feishu_messages_helper.rb,
app/controllers/feishu_bot/application_controller.rb,
app/controllers/feishu_bot/feishu_messages_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, FeishuMessagesHelper Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Config, Engine, FeishuMessagesController, FeishuUser

Constant Summary collapse

VERSION =
'0.1.2'

Class Method Summary collapse

Class Method Details

.access_tokenObject



3
4
5
6
7
8
# File 'lib/feishu_bot/api.rb', line 3

def access_token
  Rails.cache.fetch("feishu_access_token", expires_in: 2.hours) do
    res = HTTP.post("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/", :json => { :app_id => Config.app_id, :app_secret=> Config.app_secret })
    JSON.parse(res.body.readpartial)['tenant_access_token']
  end
end

.batch_user_info(open_ids) ⇒ Object



10
11
12
13
14
15
# File 'lib/feishu_bot/api.rb', line 10

def (open_ids)
  res = request.get('https://open.feishu.cn/open-apis/contact/v1/user/batch_get', params: {:open_ids => open_ids})
  users = JSON.parse(res.body.readpartial)

  users['data']
end

.configure(&block) ⇒ Object



10
11
12
# File 'lib/feishu_bot.rb', line 10

def configure(&block)
  Config.configure(&block)
end

.group_info(chat_id) ⇒ Object

获取群信息



27
28
29
30
31
32
# File 'lib/feishu_bot/api.rb', line 27

def group_info(chat_id)
  res = request.get("https://open.feishu.cn/open-apis/chat/v4/info", :params => {:chat_id=> chat_id})
  group_users_content = JSON.parse(res.body.readpartial)

  member_ids = group_users_content["data"]["members"]
end

.group_list(page_size = 200, page = nil) ⇒ Object

获取机器人所在的群列表



18
19
20
21
22
23
# File 'lib/feishu_bot/api.rb', line 18

def group_list(page_size = 200, page = nil)
  res = request.get('https://open.feishu.cn/open-apis/chat/v4/list', params: {page_size: page_size, page_token: page})
  group_content = JSON.parse(res.body.readpartial)

  group_content['data']
end

.image_data(key) ⇒ Object

member_ids = group_users_content end



42
43
44
45
# File 'lib/feishu_bot/api.rb', line 42

def image_data(key)
  res = request.get('https://open.feishu.cn/open-apis/image/v4/get', params: {image_key: key})
  res.body.readpartial
end

.requestObject



52
53
54
# File 'lib/feishu_bot/api.rb', line 52

def request
  HTTP.headers(:Authorization=> "Bearer #{self.access_token}")
end

.send_text(open_id, text) ⇒ Object



47
48
49
50
# File 'lib/feishu_bot/api.rb', line 47

def send_text(open_id, text)
  send_msg = request.post("https://open.feishu.cn/open-apis/message/v4/send/", :json => { :open_id => open_id, :msg_type => 'text', :content => { :text=> text} })
  send_res = JSON.parse(send_msg.body.readpartial)
end