您的位置:首页 > 游戏 > 手游 > 钉钉 ai卡片 stream模式联调

钉钉 ai卡片 stream模式联调

2024/11/18 19:40:49 来源:https://blog.csdn.net/Gimamy/article/details/140666534  浏览:    关键词:钉钉 ai卡片 stream模式联调

sdk连接

  1. 新建卡片模板
  2. 下载node.js sdk
  3. config.json 配置应用信息 启动项目npm i npm run build npm run start
  4. 连接成功
    在这里插入图片描述

获取卡片回调

  1. 注册卡片回调事件
  2. 调用https://api.dingtalk.com/v1.0/card/instances 创建卡片实例,返回实例Id
//参数结构
{"cardTemplateId": "b7078d27-e321-4ee6-9b2d-ef3cb89cea05.schema","outTrackId": "asdasdas","cardData" : {"cardParamMap" : {"flowStatus" : "3", //ai卡片状态"feedbacks":"","feedbackinput": "","markdowm": "钉钉平台<font color=common_blue1_color>markdown内容</font>**","likeStatus": "","likes": "0"}},"robotCode": "dingimeeh8go8yo8usyc","callbackType":"STREAM"
}
  1. 调用https://api.dingtalk.com/v1.0/card/instances/spaces 新增场域
{"outTrackId" : "asdasdas","imGroupOpenSpaceModel" : { // 群聊场域属性"supportForward" : false, // 是否支持转发"lastMessageI18n" : { // 消息lastMessage"ZH_CN": "卡片","EN_US": "card"}}}
  1. 调用https://api.dingtalk.com/v1.0/card/instances/deliver 投放卡片
{"outTrackId" : "asdasdas","openSpaceId" : "dtv1.card//IM_GROUP.cid5o+bbZdK/80y1V5ESE5Trw==","imGroupOpenDeliverModel" : { // 群聊投放属性"robotCode" : "dingimeeh8go8yo8usyc" // 机器人code}
}

在这里插入图片描述

更新示例

/** 卡片回调 */
client.registerCallbackListener(TOPIC_CARD, async (res) => {// 注册卡片回调事件console.log("收到卡片消息");const accessToken = await client.getAccessToken();let datas = JSON.parse(res.data)let contens = JSON.parse(datas.content)console.log(contens)//更新数据const obj = {} as any //卡片定义回调的字段参数const params = contens.cardPrivateData.paramsif(contens.cardPrivateData.actionIds[0] === 'multiSelect'){obj['feedbacks'] = JSON.stringify(params.multiSelect.index)}else if(contens.cardPrivateData.actionIds[0] === 'input'){obj['feedbackinput'] =  params.input}else {obj['likeStatus'] =  params.action || params.axtionif(params.axtion === 'dislike'){obj['likes'] =  '0'}else {obj['likes'] =  '1'}}const dataJson = {"cardTemplateId": "b7078d27-e321-4ee6-9b2d-ef3cb89cea05.schema","outTrackId": datas.outTrackId,"cardData": {"cardParamMap": obj,"robotCode": "dingimeeh8go8yo8usyc","callbackType": "STREAM"},"cardUpdateOptions": {"updateCardDataByKey": true},}const result = await axios({url: 'https://api.dingtalk.com/v1.0/card/instances',method: "PUT",responseType: "json",data: dataJson,headers: {"x-acs-dingtalk-access-token": accessToken,},});if (result) {console.log("更新回调卡片成功");console.log((result.data));}
});

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com