我用的是互动卡片普通版功能。在模板配置页面配好之后发送测试卡片到钉钉是没问题的。但是写进代码以后调用接口发送到钉钉就出问题了,下拉框可以展示,但是点击其中某一个选项后没办法选中那个选项
这是我的最终生成的卡片模板
{
"config": {
"autoLayout": true,
"enableForward": true
},
"header": {
"title": {
"type": "text",
"text": "会议预约"
},
"logo": "@lALPDtXaA1csu9g4MA"
},
"contents": [
{
"type": "text",
"text": "会议标题:大模型研讨",
"id": "text_1694401882766"
},
{
"type": "text",
"text": "会议时间:2023-09-12 10:00 —— 2023-09-12 12:30",
"id": "text_1694401882766"
},
{
"type": "text",
"text": "参会人员:百度团队,小碗,我",
"id": "text_1694401882766"
},
{
"type": "section",
"content": {
"type": "text",
"text": "会议室",
"id": "text_1694402253377"
},
"extra": {
"type": "select",
"options": [{
"label": {
"type": "text",
"text": "集团大厦B塔5楼1104-XYJT(最大容量null人)",
"id": "text_3e0cd8e74f5f4ea5841f3c2d1e4e93e4"
},
"value": "8a058ac3867bd6fc01867d10a3940012"
}
,{
"label": {
"type": "text",
"text": "万科广场8楼8号(最大容量100人)",
"id": "text_8f474feab7a3400ba5dc935aeaee0ee6"
},
"value": "8a058ac484d25c490184e0570c21002d"
}
,{
"label": {
"type": "text",
"text": "万科广场上海区域1号会议室(最大容量12人)",
"id": "text_d8f1749cffc642908c27d7b4f8282dbb"
},
"value": "8a058ac484b38bb90184b3d08ca1000b"
}
],
"placeholder": {
"type": "text",
"text": "请选择",
"id": "text_1694402253424"
},
"id": "select_d8f1749cffc642908c27d7b4f8282dbb"
},
"id": "section_1694402253377"
},
{
"type": "divider",
"id": "divider_1694401882767"
},
{
"type": "divider",
"id": "divider_1694401882864"
},
{
"type": "action",
"actions": [
{
"type": "button",
"label": {
"type": "text",
"text": "确认预约",
"id": "text_1694401882771"
},
"actionType": "request",
"url": {
"all": "https://www.dingtalk.com"
},
"status": "primary",
"id": "button_1647334806546",
"iconCode": "icon_accept"
}
],
"id": "action_1694401882767"
}
]
}
这是我发送卡片的代码
public void replayCard (String msg , String openConversationId) throws Exception {
Client client = createClientKim();
SendRobotInteractiveCardHeaders sendRobotInteractiveCardHeaders = new SendRobotInteractiveCardHeaders();
sendRobotInteractiveCardHeaders.xAcsDingtalkAccessToken = getAccessToken();
MeetingInfo meetingInfo = ernieBotService.getChatResult(msg);
QueryMeetingRoomResponseDTO meetingRoomResponseDTO = meetingService.getMeetingRoom(meetingInfo.convertToQueryMeetingRoomRequestDTO(meetingInfo));
String meetingRoomName = null;
List<String> selectOptions = Lists.newArrayList();
String selected = null;
if(Optional.ofNullable(meetingRoomResponseDTO).map(QueryMeetingRoomResponseDTO::getContent).isPresent()){
List<MeetingRoomInfo> content = meetingRoomResponseDTO.getContent().stream().filter(obj -> obj.getAddressName() != null && obj.getName() != null).collect(Collectors.toList());
if(content.size() > 3){
content = content.subList(0,3);
}
String optionTemplate = """
{
"label": {
"type": "text",
"text": "%s(最大容量%s人)",
"id": "text_%s"
},
"value": "%s"
}
""";
for(MeetingRoomInfo meetingRoomInfo : content){
selected = UUID.randomUUID().toString().replace("-","");
String option = String.format(optionTemplate, meetingRoomInfo.getAddressName() + meetingRoomInfo.getName(),meetingRoomInfo.getCapacityNum(),selected, meetingRoomInfo.getId());
selectOptions.add(option);
}
meetingRoomName = content.stream().map(obj -> obj.getAddressName() + obj.getName()).collect(Collectors.joining(","));
}
// 人员数组处理成字符串
List<String> participants = meetingInfo.getParticipants();
String meetPerson = "";
if (!CollectionUtils.isEmpty(participants)) {
meetPerson = participants.stream().collect(Collectors.joining(",")).toString();
}
String cardData = """
{
"config": {
"autoLayout": true,
"enableForward": true
},
"header": {
"title": {
"type": "text",
"text": "会议预约"
},
"logo": "@lALPDtXaA1csu9g4MA"
},
"contents": [
{
"type": "text",
"text": "会议标题:%s",
"id": "text_1694401882766"
},
{
"type": "text",
"text": "会议时间:%s",
"id": "text_1694401882766"
},
{
"type": "text",
"text": "参会人员:%s",
"id": "text_1694401882766"
},
{
"type": "section",
"content": {
"type": "text",
"text": "会议室",
"id": "text_1694402253377"
},
"extra": {
"type": "select",
"options": %s,
"placeholder": {
"type": "text",
"text": "请选择",
"id": "text_1694402253424"
},
"id": "select_%s"
},
"id": "section_1694402253377"
},
{
"type": "divider",
"id": "divider_1694401882767"
},
{
"type": "divider",
"id": "divider_1694401882864"
},
{
"type": "action",
"actions": [
{
"type": "button",
"label": {
"type": "text",
"text": "确认预约",
"id": "text_1694401882771"
},
"actionType": "request",
"url": {
"all": "https://www.dingtalk.com"
},
"status": "primary",
"id": "button_1647334806546",
"iconCode": "icon_accept"
}
],
"id": "action_1694401882767"
}
]
}
""".formatted(meetingInfo.getTitle(), meetingInfo.getStartTime() + " —— " + meetingInfo.getEndTime(), meetPerson,"["+ String.join(",", selectOptions) +"]",selected);
System.out.println(cardData);
SendRobotInteractiveCardRequest sendRobotInteractiveCardRequest = new SendRobotInteractiveCardRequest()
.setCardTemplateId("StandardCard")
.setOpenConversationId(openConversationId)
.setCardBizId("card_" + UUID.randomUUID())
.setRobotCode(AppKey)
.setCallbackUrl("https://***")
.setCardData(cardData)
.setPullStrategy(false);
try {
SendRobotInteractiveCardResponse sendRobotInteractiveCardResponse = client.sendRobotInteractiveCardWithOptions(sendRobotInteractiveCardRequest, sendRobotInteractiveCardHeaders, new RuntimeOptions());
System.out.println(JSONObject.toJSONString(sendRobotInteractiveCardResponse.getBody()));
} catch (Exception _err) {
_err.printStackTrace();
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
什么是互动卡片普通版搭建平台
互动卡片普通版搭建平台是在线可视化搭建互动卡片的平台,提供了创建互动卡片、编辑互动卡片等功能,帮助开发者更加方便、快速地接入互动卡片。钉钉同时提供了丰富的组件来满足复杂的样式需求,是一套开箱即用的互动卡片解决方案,开发者无需从零开始搭建卡片模板,可以通过调用接口可发送卡片。
https://open.dingtalk.com/document/resourcedownload/ding-card-interactive-card-building-platform-new

交互模块
提供可交互的表单组件,增加卡片的交互性,目前以支持以下6种交互组件:
