module FeishuBot
Constants
- VERSION
Public Class Methods
access_token()
click to toggle source
# 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)
click to toggle source
# File lib/feishu_bot/api.rb, line 10 def batch_user_info(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)
click to toggle source
# File lib/feishu_bot.rb, line 10 def configure(&block) Config.configure(&block) end
group_info(chat_id)
click to toggle source
获取群信息
# 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)
click to toggle source
获取机器人所在的群列表
# 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)
click to toggle source
member_ids = group_users_content["data"]
end
# 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
request()
click to toggle source
# File lib/feishu_bot/api.rb, line 58 def request HTTP.headers(:Authorization=> "Bearer #{self.access_token}") end
send_message(receive_type, receive_id, msg_type, content)
click to toggle source
使用推荐的消息接口
# File lib/feishu_bot/api.rb, line 53 def send_message(receive_type, receive_id, msg_type, content) send_msg = request.post("https://open.feishu.cn/open-apis/im/v1/messages", :params => { :receive_id_type => receive_type}, :json => { :receive_id => receive_id, :msg_type => msg_type, :content => content }) send_res = JSON.parse(send_msg.body.readpartial) end
send_text(open_id, text)
click to toggle source
# 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