sdk连接
新建卡片模板 下载node.js sdk config.json 配置应用信息 启动项目npm i npm run build npm run start 连接成功
获取卡片回调
注册卡片回调事件 调用https://api.dingtalk.com/v1.0/card/instances 创建卡片实例,返回实例Id
{ "cardTemplateId" : "b7078d27-e321-4ee6-9b2d-ef3cb89cea05.schema" , "outTrackId" : "asdasdas" , "cardData" : { "cardParamMap" : { "flowStatus" : "3" , "feedbacks" : "" , "feedbackinput" : "" , "markdowm" : "钉钉平台<font color=common_blue1_color>markdown内容</font>**" , "likeStatus" : "" , "likes" : "0" } } , "robotCode" : "dingimeeh8go8yo8usyc" , "callbackType" : "STREAM"
}
调用https://api.dingtalk.com/v1.0/card/instances/spaces 新增场域
{ "outTrackId" : "asdasdas" , "imGroupOpenSpaceModel" : { "supportForward" : false , "lastMessageI18n" : { "ZH_CN" : "卡片" , "EN_US" : "card" } } }
调用https://api.dingtalk.com/v1.0/card/instances/deliver 投放卡片
{ "outTrackId" : "asdasdas" , "openSpaceId" : "dtv1.card//IM_GROUP.cid5o+bbZdK/80y1V5ESE5Trw==" , "imGroupOpenDeliverModel" : { "robotCode" : "dingimeeh8go8yo8usyc" }
}
更新示例
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) ) ; }
} ) ;