Class: KHL::HTTP::Message

Inherits:
Base
  • Object
show all
Defined in:
lib/khl/http/message.rb

Overview

频道消息相关接口 developer.kaiheila.cn/doc/http/message

Constant Summary

Constants inherited from Base

Base::API_VERSION, Base::BASE_URL, Base::END_POINT

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #post, #post_file

Constructor Details

This class inherits a constructor from KHL::HTTP::Base

Instance Method Details

#add_reaction(msg_id, emoji) ⇒ KHL::HTTP::Response

给某个消息添加回应

Parameters:

  • msg_id (String)

    频道消息 ID

  • emoji (String)

    Emoji ID,可以为 GuilEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

Returns:



77
78
79
# File 'lib/khl/http/message.rb', line 77

def add_reaction(msg_id, emoji)
  post(msg_id: msg_id, emoji: emoji)
end

#create(target_id, content, options = {}) ⇒ KHL::HTTP::Response

Note:

此接口与频道相关接口下的 “发送频道聊天消息” 功能相同

发送频道聊天消息

Parameters:

  • target_id (String)

    频道 ID

  • content (String)

    消息内容

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :type (Integer)

    消息类型,不传默认为 1,代表文本类型。9 代表 kmarkdown 消息,10 代表卡片消息

  • :quote (String)

    回复某条消息的 msg_id

  • :nonce (String)

    随机字符串,服务端不做处理,原样返回

  • :temp_target_id (String)

    用户 ID,如果传了,代表该消息是临时消息,该消息不会存数据库,但是会在频道内只给该用户推送临时消息。用于在频道内针对用户的操作进行单独的回应通知等

Returns:



41
42
43
# File 'lib/khl/http/message.rb', line 41

def create(target_id, content, options = {})
  post(options.merge(target_id: target_id, content: content))
end

#delete(msg_id) ⇒ KHL::HTTP::Response

Note:

普通用户只能删除自己的消息,有权限的用户可以删除权限范围内他人的消息

删除频道聊天消息

Parameters:

  • msg_id (String)

    消息 ID

Returns:



61
62
63
# File 'lib/khl/http/message.rb', line 61

def delete(msg_id)
  post(msg_id: msg_id)
end

#delete_reaction(msg_id, emoji, options = {}) ⇒ KHL::HTTP::Response

删除消息的某个回应

Parameters:

  • msg_id (String)

    频道消息 ID

  • emoji (String)

    Emoji ID,可以为 GuilEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :user_id (String)

    用户 ID, 如果不填则为自己的 ID。删除别人的回应需要有管理频道消息的权限

Returns:



87
88
89
# File 'lib/khl/http/message.rb', line 87

def delete_reaction(msg_id, emoji, options = {})
  post(options.merge(msg_id: msg_id, emoji: emoji))
end

#list(target_id, options = {}) ⇒ KHL::HTTP::Response

Note:

此接口非标准分页,需要根据参考消息来查询相邻分页的消息

获取频道聊天消息列表

Parameters:

  • target_id (String)

    频道 ID

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :msg_id (String)

    参考消息 ID,不传则查询最新消息

  • :pin (Integer)

    只能为 0 或者 1,是否查询置顶消息。置顶消息只支持查询最新的消息

  • :flag (String)

    查询模式,有三种模式可以选择 before、around、after。不传则默认查询最新的消息

  • :page_size (Integer)

    当前分页消息数量,默认 50

Returns:



19
20
21
# File 'lib/khl/http/message.rb', line 19

def list(target_id, options = {})
  get(options.merge(target_id: target_id))
end

#reaction_list(msg_id, emoji) ⇒ KHL::HTTP::Response

获取频道消息某回应的用户列表

Parameters:

  • msg_id (String)

    频道消息 ID

  • emoji (String)

    Emoji ID,可以为 GuilEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

Returns:



69
70
71
# File 'lib/khl/http/message.rb', line 69

def reaction_list(msg_id, emoji)
  get(msg_id: msg_id, emoji: emoji)
end

#update(msg_id, content, options = {}) ⇒ KHL::HTTP::Response

Note:

目前支持消息 type 为 9、10 的修改,即 KMarkdown 和 CardMessage

更新频道聊天消息

Parameters:

  • msg_id (String)

    消息 ID

  • content (String)

    消息内容

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :quote (String)

    回复某条消息的 msg_id。如果为空,则代表删除回复,不传则无影响

  • :temp_target_id (String)

    用户 ID,针对特定用户临时更新消息,必须是正常消息才能更新。与发送临时消息概念不同,但同样不保存数据库

Returns:



53
54
55
# File 'lib/khl/http/message.rb', line 53

def update(msg_id, content, options = {})
  post(options.merge(msg_id: msg_id, content: content))
end

#view(msg_id) ⇒ KHL::HTTP::Response

获取频道聊天消息详情

Parameters:

  • msg_id (String)

    消息 ID

Returns:



26
27
28
# File 'lib/khl/http/message.rb', line 26

def view(msg_id)
  get(msg_id: msg_id)
end