dingtalk.oapi.message.send_to_conversation (发送普通消息)

发送普通消息

公共参数

请求参数

名称 类型 是否必须 示例值 更多限制 描述
sender String 可选 123 消息发送者员工ID
markdown Markdown 可选 markdown消息
  • └ text
  • String
  • 可选
  • 1
  • markdown格式的消息
  • └ title
  • String
  • 可选
  • 1
  • 首屏会话透出的展示内容
oa Oa 可选 OA消息
  • └ message_url
  • 可选
  • 客户端点击消息时跳转到的H5地址
  • └ pc_message_url
  • String
  • 可选
  • 1
  • PC端点击消息时跳转到的地址
  • body
  • Body
  • 可选
  • 消息体
  • └ title
  • String
  • 可选
  • 1
  • 消息体的标题,建议50个字符以内
  • form
  • Form []
  • 可选
  • 消息体的表单,最多显示6个,超过会被隐藏
  • └ value
  • String
  • 可选
  • 1
  • 消息体的关键字
  • └ key
  • String
  • 可选
  • 1
  • 消息体的关键字对应的值
  • rich
  • Rich
  • 可选
  • 单行富文本信息
  • └ num
  • String
  • 可选
  • 11
  • 单行富文本信息的数目
  • └ unit
  • String
  • 可选
  • 1
  • 单行富文本信息的单位
  • └ content
  • String
  • 可选
  • 1
  • 消息体的内容,最多显示3行
  • └ image
  • String
  • 可选
  • 1
  • 消息体中的图片,支持图片资源@mediaId
  • └ file_count
  • String
  • 可选
  • 1
  • 自定义的附件数目。此数字仅供显示,钉钉不作验证
  • └ author
  • String
  • 可选
  • 1
  • 自定义的作者名字
  • head
  • Head
  • 可选
  • 消息头部内容
  • └ bgcolor
  • String
  • 可选
  • 1
  • 消息头部的背景颜色。长度限制为8个英文字符,其中前2为表示透明度,后6位表示颜色值。不要添加0x
  • └ text
  • String
  • 可选
  • 1
  • 消息的头部标题 (向普通会话发送时有效,向企业会话发送时会被替换为微应用的名字),长度限制为最多10个字符
voice Voice 可选 voice消息
  • └ duration
  • Number
  • 可选
  • 1
  • 语音时长
  • └ media_id
  • String
  • 可选
  • 1
  • 语音媒体文件id,可以调用上传媒体文件接口获取。2MB,播放长度不超过60s,AMR格式
file File 可选 file消息
  • └ media_id
  • String
  • 可选
  • 1
  • 媒体文件id,可以调用上传媒体文件接口获取。10MB
link Link 可选 link消息
  • └ messageUrl
  • String
  • 可选
  • 1
  • 消息点击链接地址
  • └ text
  • String
  • 可选
  • 1
  • 消息描述
  • └ title
  • String
  • 可选
  • 1
  • 消息标题
  • └ picUrl
  • String
  • 可选
  • 1
  • 图片媒体文件id,可以调用上传媒体文件接口获取
image Image 可选 image消息
  • └ media_id
  • String
  • 可选
  • 1
  • 图片媒体文件id,可以调用上传媒体文件接口获取。建议宽600像素 x 400像素,宽高比3:2
text Text 可选 text消息
  • └ content
  • String
  • 可选
  • 1
  • 消息内容
msgtype String 可选 text 消息类型
cid String 可选 12 群消息或者个人聊天会话Id,(通过JSAPI之pickConversation接口唤起联系人界面选择之后即可拿到会话ID,之后您可以使用获取到的cid调用此接口)
action_card ActionCard 可选 ActionCard消息
  • └ markdown
  • String
  • 可选
  • 1
  • 消息内容,支持markdown,语法参考标准markdown语法。图片举例:![alt text](mediaId)
  • └ title
  • String
  • 可选
  • 1
  • 透出到会话列表和通知的文案
  • └ single_title
  • String
  • 可选
  • 1
  • 使用整体跳转ActionCard样式时的标题,必须与single_url同时设置
  • └ single_url
  • String
  • 可选
  • 1
  • 使用整体跳转ActionCard样式时的链接url,必须与single_title同时设置
  • └ btn_orientation
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮排列方式,竖直排列(0),横向排列(1);必须与btn_json_list同时设置
  • btn_json_list
  • BtnJson []
  • 可选
  • 使用独立跳转ActionCard样式时的按钮列表;必须与btn_orientation同时设置
  • └ action_url
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮的链接url
  • └ title
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮的标题
msg Msg 可选 消息内容
  • action_card
  • ActionCard
  • 可选
  • 消息内容,支持markdown,语法参考标准markdown语法。图片举例:![alt text](mediaId)
  • btn_json_list
  • BtnJson []
  • 可选
  • 使用独立跳转ActionCard样式时的按钮的链接url
  • └ title
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮的链接url
  • └ action_url
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮的标题
  • └ btn_orientation
  • String
  • 可选
  • 1
  • 使用独立跳转ActionCard样式时的按钮排列方式,竖直排列(0),横向排列(1);必须与btn_json_list同时设置
  • └ single_url
  • String
  • 可选
  • url
  • 使用整体跳转ActionCard样式时的链接url,必须与single_title同时设置
  • └ single_title
  • String
  • 可选
  • title
  • 使用整体跳转ActionCard样式时的标题,必须与single_url同时设置
  • └ title
  • String
  • 可选
  • title
  • 透出到会话列表和通知的文案
  • └ markdown
  • String
  • 可选
  • ![]()xxxx
  • 消息内容,支持markdown,语法参考标准markdown语法。图片举例:![alt text](mediaId)
  • markdown
  • Markdown
  • 可选
  • markdown消息
  • └ title
  • String
  • 可选
  • title
  • markdown格式的消息
  • └ text
  • String
  • 可选
  • text
  • 首屏会话透出的展示内容
  • oa
  • Oa
  • 可选
  • oa消息
  • └ message_url
  • String
  • 可选
  • message_url
  • 消息点击链接地址,当发送消息为小程序时支持小程序跳转链接
  • └ pc_message_url
  • String
  • 可选
  • pc_message_url
  • PC端点击消息时跳转到的地址
  • body
  • Body
  • 可选
  • 消息体
  • └ author
  • String
  • 可选
  • author
  • 自定义的作者名字
  • └ image
  • String
  • 可选
  • image
  • 消息体中的图片,支持图片资源@mediaId
  • └ file_count
  • String
  • 可选
  • file_count
  • 自定义的附件数目。此数字仅供显示,钉钉不作验证
  • └ content
  • String
  • 可选
  • content
  • 消息体的内容,最多显示3行
  • rich
  • Rich
  • 可选
  • 单行富文本信息
  • └ num
  • String
  • 可选
  • num
  • 单行富文本信息的数目
  • └ unit
  • String
  • 可选
  • unit
  • 单行富文本信息的单位
  • form
  • Form []
  • 可选
  • 消息体的表单,最多显示6个,超过会被隐藏
  • └ value
  • String
  • 可选
  • value
  • 消息体的关键字对应的值
  • └ key
  • String
  • 可选
  • key
  • 消息体的关键字
  • └ title
  • String
  • 可选
  • title
  • 消息体的标题,建议50个字符以内
  • head
  • Head
  • 可选
  • 消息头部内容
  • └ bgcolor
  • String
  • 可选
  • bgcolor
  • 消息头部的背景颜色。长度限制为8个英文字符,其中前2为表示透明度,后6位表示颜色值。不要添加0x
  • └ text
  • String
  • 可选
  • text
  • 消息的头部标题 (向普通会话发送时有效,向企业会话发送时会被替换为微应用的名字),长度限制为最多10个字符
  • voice
  • Voice
  • 可选
  • 语音消息
  • └ duration
  • String
  • 可选
  • duration
  • 正整数,小于60,表示音频时长
  • └ media_id
  • String
  • 可选
  • media_id
  • 媒体文件id。2MB,播放长度不超过60s,AMR格式
  • file
  • File
  • 可选
  • 文件消息
  • └ media_id
  • String
  • 可选
  • media_id
  • 媒体文件id。引用的媒体文件最大10MB
  • link
  • Link
  • 可选
  • 链接消息
  • └ messageUrl
  • String
  • 可选
  • messageUrl
  • 消息点击链接地址,当发送消息为小程序时支持小程序跳转链接
  • └ picUrl
  • String
  • 可选
  • picUrl
  • 图片地址
  • └ text
  • String
  • 可选
  • text
  • 消息标题,建议100字符以内
  • └ title
  • String
  • 可选
  • title
  • 消息描述,建议500字符以内
  • image
  • Image
  • 可选
  • 图片消息
  • └ media_id
  • String
  • 可选
  • media_id
  • 媒体文件id,可以通过媒体文件接口上传图片获取。建议宽600像素 x 400像素,宽高比3 : 2
  • text
  • Text
  • 可选
  • 文本消息
  • └ content
  • String
  • 可选
  • content
  • 消息内容,建议500字符以内
  • └ msgtype
  • String
  • 可选
  • msgtype
  • 消息类型

响应参数

名称 类型 示例值 描述
receiver String UserID1|UserID2 如果是群,返回跟发送者同一家企业的一组工号;如果是个人聊天,只返回发送者同一家企业的一个工号;不在同一家企业,发送失败
errmsg String ok errmsg
errcode Number 0 errcode

请求示例

  • JAVA
  • .NET
  • PHP
  • CURL
  • Python
  • C/C++
  • NodeJS
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/message/send_to_conversation");
OapiMessageSendToConversationRequest req = new OapiMessageSendToConversationRequest();
req.setSender("123");
Markdown obj1 = new Markdown();
obj1.setText("1");
obj1.setTitle("1");
req.setMarkdown(obj1);
Oa obj2 = new Oa();
obj2.setPcMessageUrl("1");
Body obj3 = new Body();
obj3.setTitle("1");
List<Form> list5 = new ArrayList<Form>();
Form obj6 = new Form();
list5.add(obj6);
obj6.setValue("1");
obj6.setKey("1");
obj3.setForm(list5);
Rich obj7 = new Rich();
obj7.setNum("11");
obj7.setUnit("1");
obj3.setRich(obj7);
obj3.setContent("1");
obj3.setImage("1");
obj3.setFileCount("1");
obj3.setAuthor("1");
obj2.setBody(obj3);
Head obj8 = new Head();
obj8.setBgcolor("1");
obj8.setText("1");
obj2.setHead(obj8);
req.setOa(obj2);
Voice obj9 = new Voice();
obj9.setDuration(1L);
obj9.setMediaId("1");
req.setVoice(obj9);
File obj10 = new File();
obj10.setMediaId("1");
req.setFile(obj10);
Link obj11 = new Link();
obj11.setMessageUrl("1");
obj11.setText("1");
obj11.setTitle("1");
obj11.setPicUrl("1");
req.setLink(obj11);
Image obj12 = new Image();
obj12.setMediaId("1");
req.setImage(obj12);
Text obj13 = new Text();
obj13.setContent("1");
req.setText(obj13);
req.setMsgtype("text");
req.setCid("12");
ActionCard obj14 = new ActionCard();
obj14.setMarkdown("1");
obj14.setTitle("1");
obj14.setSingleTitle("1");
obj14.setSingleUrl("1");
obj14.setBtnOrientation("1");
List<BtnJson> list16 = new ArrayList<BtnJson>();
BtnJson obj17 = new BtnJson();
list16.add(obj17);
obj17.setActionUrl("1");
obj17.setTitle("1");
obj14.setBtnJsonList(list16);
req.setActionCard(obj14);
Msg obj18 = new Msg();
ActionCard obj19 = new ActionCard();
List<BtnJson> list21 = new ArrayList<BtnJson>();
BtnJson obj22 = new BtnJson();
list21.add(obj22);
obj22.setTitle("1");
obj22.setActionUrl("1");
obj19.setBtnJsonList(list21);
obj19.setBtnOrientation("1");
obj19.setSingleUrl("url");
obj19.setSingleTitle("title");
obj19.setTitle("title");
obj19.setMarkdown("![]()xxxx");
obj18.setActionCard(obj19);
Markdown obj23 = new Markdown();
obj23.setTitle("title");
obj23.setText("text");
obj18.setMarkdown(obj23);
Oa obj24 = new Oa();
obj24.setMessageUrl("message_url");
obj24.setPcMessageUrl("pc_message_url");
Body obj25 = new Body();
obj25.setAuthor("author");
obj25.setImage("image");
obj25.setFileCount("file_count");
obj25.setContent("content");
Rich obj26 = new Rich();
obj26.setNum("num");
obj26.setUnit("unit");
obj25.setRich(obj26);
List<Form> list28 = new ArrayList<Form>();
Form obj29 = new Form();
list28.add(obj29);
obj29.setValue("value");
obj29.setKey("key");
obj25.setForm(list28);
obj25.setTitle("title");
obj24.setBody(obj25);
Head obj30 = new Head();
obj30.setBgcolor("bgcolor");
obj30.setText("text");
obj24.setHead(obj30);
obj18.setOa(obj24);
Voice obj31 = new Voice();
obj31.setDuration("duration");
obj31.setMediaId("media_id");
obj18.setVoice(obj31);
File obj32 = new File();
obj32.setMediaId("media_id");
obj18.setFile(obj32);
Link obj33 = new Link();
obj33.setMessageUrl("messageUrl");
obj33.setPicUrl("picUrl");
obj33.setText("text");
obj33.setTitle("title");
obj18.setLink(obj33);
Image obj34 = new Image();
obj34.setMediaId("media_id");
obj18.setImage(obj34);
Text obj35 = new Text();
obj35.setContent("content");
obj18.setText(obj35);
obj18.setMsgtype("msgtype");
req.setMsg(obj18);
OapiMessageSendToConversationResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());

响应示例

  • JSON示例
{
    "receiver":"UserID1|UserID2",
    "errmsg":"ok",
    "errcode":0
}

异常示例

  • JSON示例
{
	"error_response":{
		"msg":"Remote service error",
		"code":50,
		"sub_msg":"非法参数",
		"sub_code":"isv.invalid-parameter"
	}
}

错误码解释

错误码 错误描述 解决方案

API工具

如何获得此API

FAQ

返回
顶部