发送消息

更新时间不可用

接口描述

Publish 接口用于向指定的频道中发送消息。

注意

  • 消息负载限制在 32 KB 以内,否则发送会失败。
  • 向单个频道发送消息的速率上限为 60 QPS。如果发送速率超限,将会有部分消息被丢弃。在满足要求的情况下,速率越低越好。
  • 请求 Body 的 Payload 内容必须为可序列化的字符串,不支持二进制数据。

接口方法

Shell
POST https://api.sd-rtn.com/rtm/v2/publish/{:appId}/userId/{:userId}/channelType/{:channelType}/channel/{:channelName}?storeInHistory=true&customType={:customeType}
参数类型必填描述
appIdstring是你的声网项目的 App ID。
userIdstring是

此次操作的 User ID。

以下为支持的字符集范围(共 89 个字符):

  • 26 个小写英文字母 a-Z

  • 26 个大写英文字母 A-Z

  • 10 个数字 0-9

  • 空格

  • !, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _, {, }, |, ~, ,

    注意

    字符长度限制为:0 < 字符长度 ≤ 64。

channelTypestring是

频道类型:

  • message:消息频道
  • user:用户频道
channelNamestring是

频道名。

以下为支持的字符集范围(共 89 个字符):

  • 26 个小写英文字母 a-Z

  • 26 个大写英文字母 A-Z

  • 10 个数字 0-9

  • 空格

  • !, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _, {, }, |, ~, ,

    注意

    字符长度限制为:0 < 字符长度 ≤ 64。

storeInHistoryboolean否

此条消息是否存储到历史消息中:

  • true:存储
  • false:不存储。默认为 false。
customTypestring否

用户自定义字段,可编码的字符串。

注意

字符长度限制为:0 < 字符长度 ≤ 32。

表格内容超出当前宽度,可横向滚动查看更多列。

基本用法

Shell
curl -L 'https://api.sd-rtn.com/rtm/v2/publish/{appId}/userId/Tony/channelType/message/channel/chatroom?storeInHistory=true&customType=image' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: agora token=007xxxxx' \
-d '{  
    "type": "image",
    "asset_url": "https://my.app/image.png",
    "thumb_url": "https://my.app/thumbnail/image.png",
    "mentionedUsers": ["Tony","Lily"],
    "sender": "Max"
    }'

返回值

执行后将返回以下数据:

JSON
{
  "errorCode": 200,
  "error": false,
  "requestId": 1121_1234231,
  "operation": "publish",
  "reason": "xxxxxxxxxxxx",
  "timestamp":1234567,
  "data": {
    "channelName": "string",
    "channelType": "string", 
  }
}
参数类型描述
errorCodenumber错误码。200 表示请求成功。如果不为 200,你可以参考错误码了解出错的原因并进行排障。
errorboolean

当前请求是否出错。

  • false 代表请求成功
  • true 代表请求失败
requestIdstring当前请求的请求 ID。
operationstring当前请求的具体操作。
reasonstring出错原因。
timestampnumber发送请求的时间戳。
dataobject

响应的具体 Payload 信息,包含如下字段:

  • channelName:频道名;
  • channelType:频道类型。
表格内容超出当前宽度,可横向滚动查看更多列。

这个页面有帮助吗?