Class: RongCloud::Services::Message::MessageChannel

Inherits:
Object
  • Object
show all
Defined in:
lib/rong_cloud/services/message/message_channel.rb

Overview

消息发送渠道,区分私信、系统消息、群组消息、讨论组消息、聊天室消息以及广播消息

Constant Summary collapse

CHANNEL_TO_REQUEST_DETAILS_MAP =

各消息渠道各自对应请求路径以及特殊参数名

{
  private: { target_param_name: "toUserId", api_path: "/message/private/publish" },
  private_template: { target_param_name: "toUserId", api_path: "/message/private/publish_template" },
  system: { target_param_name: "toUserId", api_path: "/message/system/publish" },
  system_template: { target_param_name: "toUserId", api_path: "/message/system/publish_template" },
  group: { target_param_name: 'toGroupId', api_path: "/message/group/publish" },
  discussion: { target_param_name: "toDiscussionId", api_path: "/message/discussion/publish" },
  chatroom: { target_param_name: "toChatroomId", api_path: "/message/chatroom/publish" },
  chatroom_broadcast: { api_path: "/message/chatroom/broadcast" },
  broadcast: { api_path: "/message/broadcast" }
}.freeze
VALID_CHANNEL_NAMES =

支持的消息渠道的列表

CHANNEL_TO_REQUEST_DETAILS_MAP.keys.map(&:to_s).freeze

Instance Method Summary collapse

Constructor Details

#initialize(channel_name) ⇒ RongCloud::Services::Message::MessageChannel

实例化消息渠道对象

Parameters:

  • channel_name (String)

    渠道名称

Raises:



29
30
31
32
33
34
35
36
# File 'lib/rong_cloud/services/message/message_channel.rb', line 29

def initialize(channel_name)
  if VALID_CHANNEL_NAMES.include?(channel_name.to_s)
    @channel_name = channel_name.to_s.to_sym
  else
    raise UnsupportedMessageChannelName,
      "support only channels: #{VALID_CHANNEL_NAMES}"
  end
end

Instance Method Details

#api_pathObject



42
43
44
# File 'lib/rong_cloud/services/message/message_channel.rb', line 42

def api_path
  CHANNEL_TO_REQUEST_DETAILS_MAP[@channel_name][:api_path]
end

#target_param_nameObject



38
39
40
# File 'lib/rong_cloud/services/message/message_channel.rb', line 38

def target_param_name
  CHANNEL_TO_REQUEST_DETAILS_MAP[@channel_name][:target_param_name]
end