# 侧边栏 sdk 接入
# 介绍
自定义模块功能提供外部地址接入,为外部接入能够自定义化,提供部分业务能力:
获取信息:
- 客户资料
- 群资料
- 机器人资料
- 客服资料
发送信息能力
- 发送消息到工作台(支持直接发送及粘贴文本至输入框)
调起工作台会话
当前会话对象是否变更
# 开发
原理:内嵌 iframe 通过 postmessage 与父级页面进行通讯
本质:通过 与 父级 iframe 的相互通信 传输信息
引入方式
// umd 格式的包
<script src="https://assets.aquanliang.com/sdk/side-sdk-1.7.0-umd.min.js"></script>
使用方式
全局名字为: QuanSideSDK
// umd 格式的包
const quanSideSDK = new QuanSideSDK();
# 获取数据请求: asyncGetInfo
// 用于 数据请求
// type:
// 获取用户信息: userInfo
// 获取群信息: groupInfo
// 获取机器人: robotInfo
// 获取客服信息: customerInfo
quanSideSDK.asyncGetInfo(type).then(res => {
console.log("res", res);
});
# asyncGetInfo 参数: type
值 | 描述 |
---|---|
userInfo | 客户资料 (手机号密文) |
userInfoByPlainText | 客户资料 |
groupInfo | 群资料 |
robotInfo | 机器人资料 |
customerInfo | 客服资料 |
# asyncGetInfo 返回的数据信息
# 获取 userInfo 返回参数
值 | 描述 |
---|---|
extUserId | 用户 id |
unionId | 微信 unionId |
avatar | 头像 |
name | 昵称 |
mobile | 手机号 (密文) |
userType | 用户类型(微信用户/ 企微用户+公司名称) |
addTime | 添加时间 |
channelName | 添加渠道 |
tagList | 企业标签+个人标签 |
# 获取 userInfoByPlainText 返回参数
值 | 描述 |
---|---|
extUserId | 用户 id |
unionId | 微信 unionId |
avatar | 头像 |
name | 昵称 |
mobile | 手机号 |
userType | 用户类型(微信用户/ 企微用户+公司名称) |
addTime | 添加时间 |
channelName | 添加渠道 |
tagList | 企业标签+个人标签 |
# 获取 groupInfo 返回参数
值 | 描述 |
---|---|
name | 群名称 |
memberCount | 群人数 |
memberList | 群成员信息 |
# groupInfo 群成员信息 memberList 数组
值 | 描述 |
---|---|
accountId | 成员 id |
memberName | 名称 |
memberAvatar | 头像 |
memberSex | 性别 |
memberType | 是否微信 |
adminType | 1:管理员 2:群主 |
# 获取 robotInfo 返回参数
值 | 描述 |
---|---|
robotId | 机器人 id |
strOpenId | 开放平台机器人 id |
avatar | 头像 |
name | 名称 |
remarkName | 备注名 |
ww_user_id | 成员 id |
# 获取 customerInfo 返回参数
值 | 描述 |
---|---|
customerId | 登录客服 id |
customerName | 登录客服名字(可能重复) |
loginId | 登录客服账号(唯一) |
# 发送消息: asyncSendInfo
// 用户发送信息
// data: ModelMaterial
// type: ModalMaterial_Type
// detail: ModelMaterial_Detail 详细内容看下面
const data = {
type: 1, // 具体内容看下方 ModalMaterial_Type
detail: {
text_desc: '详细内容体,看下方 ModalMaterial_Detail',
auto_send: true //是否允许单条文本类型消息自动发送
}
}
quanSideSDK.asyncSendInfo(data).then(res => {
console.log("res", res);
});
# asyncSendInfo 发送消息内容: ModalMaterial_Type
type ModalMaterial_Type
1: '文字消息'
2: '网页消息'
3: '图片消息'
4: '视频消息'
5: '文件消息'
6: '音频消息'
# asyncSendInfo 发送消息内容: ModelMaterial_Detail
interface ModelMaterial_Detail {
// @desc: 文本描述
// @gorm: type: varchar(1000)
// @v: max=1000
text_desc?: string;
// @desc: 网页标题
// @v: max=50
web_title?: string;
// @desc: 网页链接
// @v: max=512
web_url?: string;
// @desc: 网页描述
// @v: max=512
web_desc?: string;
// @desc: 网页 icon
// @v: max=512
web_icon?: string;
// @desc: 图片名称
// @v: max=50
picture_title?: string;
// @desc: 图片链接
// @v: max=512
picture_url?: string;
// @desc: 视频名称
// @v: max=50
video_title?: string;
// @desc: 视频链接
// @v: max=512
video_url?: string;
// @desc: 视频封面
// @v: max=512
video_cover_url?: string;
// @desc: 视频或语音时长
voice_time?: number;
// @desc: 文件名称
// @v: max=512
file_title?: string;
// @desc: 文件链接
// @v: max=512
file_url?: string;
// @desc: 音频名称
// @v: max=50
audio_title?: string;
// @desc: 音频链接
// @v: max=512
audio_url?: string;
// @desc: 文本类消息是否自动发送,传false只会填到消息输入框
auto_send?: boolean;
}
# 调起会话: asyncChangeChat
// 用户调起会话
// desc: robotId 与 strOpenId 二选一必填
const data = {
// 机器人id
robotId?: string,
// 开放平台机器人 id
strOpenId?: string,
// 私聊时必传,用户id
extUserId?: string,
// 内部群聊id,群聊时groupId/groupStrOpenId二选一
groupId?: string,
// 开平群聊id,群聊时groupId/groupStrOpenId二选一
groupStrOpenId?: string,
}
quanSideSDK.asyncChangeChat(data).then(res => {
console.log("res", res);
});
# 会话切换: subscribeChatChange
- 会话切换只在事件只在侧边栏配置不自动刷新的情况下才生效
const chat = quanSideSDK.subscribeChatChange(res => {
console.log("会话切换", res);
})
// 取消监听
// chat()
//1.7 版本开始支持