钉钉SDK
node-dingtalk2 -Install
$ npm adduser $ npm publish . --registry=https://registry.npmjs.org/ $ npm i node-dingtalk2 --save
Usage
const DingTalk = ;const dingtalk = corpid: '' corpsecret: ''; const deparment = dingtalkdepartment;console;
Cache example
cluster 下换成 Redis 等外部存储从而降低获取 AccessToken 频率
const CACHE = {};const cache = { if CACHEkey && CACHEkeyexpired > Date return CACHEkeyvalue; else return null; } { const obj = expired: maxAge value ; CACHEkey = obj; return obj; }; // const redis = new Redis();// const cache = {// * get(key) {// return redis.get(key)// },// * set(key, value, maxAge) {// return redis.set(key, value, 'PX', maxAge - Date.now());// },// }; const DingTalk = ;const dingtalk = corpid: '' corpsecret: '' cache;
Api
官方文档: https://open-doc.dingtalk.com/
Client
client.getAccessToken()
获取 AccessToken, 并在有效期内自动缓存, gettoken
client.getJSApiTicket()
获取 jsapi_ticket, 并在有效期内自动缓存, get_jsapi_ticket
client.getJSApiConfig()
获取 js api 接入时需要的配置数据以及签名
client.request/get/post/upload
辅助方法, 参见 npm urllib
Department
https://open-doc.dingtalk.com/doc2/detail.htm?treeId=172&articleId=104979&docType=1
department.list([opts])
获取部门列表 department/list
department.get(id)
获取部门详情 department/get
department.create({ name, parentid, … })
创建部门 department/create
department.update({ id, … })
更新部门 department/update
department.delete(id)
删除部门 department/delete
User
https://open-doc.dingtalk.com/doc2/detail.htm?treeId=172&articleId=104979&docType=1
user.list(departmentId, [isSimple], [opts])
- 获取部门成员
user/simplelist
- 获取部门成员(详情)
user/list
分页查询参数放到 opts
user.listAll([departmentId], [isSimple], [opts])
自动遍历分页查询
- 查询所有的成员 (departmentId 为空时)
- 查询该部门所有成员
user.get(id, [opts])
获取成员详情 user/get
id 对应于 userid, 参数, 其他参数放到 opts
user.create({ userid, name, department[], mobile, … })
创建成员 user/create
user.update({ userid, name, … })
更新成员 user/update
user.delete(id/id[])
- 删除成员
user/delete
- 批量删除成员
user/batchdelete
user.getUseridByUnionid(openId)
根据 unionid 获取成员的 userid, user/getUseridByUnionid
此处的 unionid 即为 user.openId
user.getByMobile(mobile)
根据手机号获取成员 userid, user/get_by_mobile
Message
message.send({ touser, toparty, msgtype, ... })
发送企业消息, message/send
message.listMessageStatus(messageId)
获取企业会话消息已读未读状态, message/list_message_status
Media
media.upload(type, filePath)
上传媒体文件 media/upload
media.download(id, targetDir, [fileName])
下载媒体文件 media/downloadFile
Questions & Suggestions
Please open an issue here.