侧边栏js接口能力介绍
<p>系统提供的聊天侧边栏可以加载自定义页面,在<code>客户接待-&gt;咨询接待-〉接待配置</code>设置的自定义页面可以使用js接口来与智域管家.云真机页面交互。</p>
<p>只要是自定义页面里配置的url的页面即可使用下面这些接口,无需做其它配置或者接入。</p>
<p><font color="red"><strong>备注:postmessage发起页和后台自定义页面里配置的url地址必须同域!</strong></font></p>
<h2>给当前对话发消息</h2>
<h3>消息类型</h3>
<pre><code class="language-js">{
&quot;text&quot;: &quot;文本&quot;,
&quot;picture&quot;: &quot;图片&quot;,
&quot;voice&quot;: &quot;音频&quot;,
&quot;link&quot;: &quot;链接&quot;,
&quot;video&quot;: &quot;视频&quot;,
&quot;file&quot;: &quot;文件&quot;,
&quot;program&quot;: &quot;小程序&quot;,
&quot;card&quot;: &quot;名片&quot;,
&quot;system&quot;: &quot;系统消息&quot;,
&quot;channel&quot;: &quot;视频号&quot;,
&quot;announcement&quot;: &quot;公告&quot;,
&quot;revoke&quot;: &quot;撤回&quot;,
&quot;location&quot;: &quot;位置&quot;,
&quot;redpacket&quot;: &quot;红包&quot;,
&quot;emotionpic&quot;: &quot;自定义表情&quot;,
&quot;imgtext&quot;: &quot;图文消息&quot;,
&quot;merge&quot;: &quot;转发的聊天记录合集&quot;
}</code></pre>
<p>侧边栏的页面中,可以给系统聊天页面的当前对话发送聊天消息。使用javascript调用,示例代码:</p>
<pre><code class="language-js">var el = document.getElementById(&#039;test&#039;)
el.addEventListener(&#039;click&#039;, function (e) {
e.preventDefault();
var msg = {
msg_type: &#039;text&#039;,
content: {
items: [
{
type: &#039;text&#039;,
text: &#039;你好啊,嘻嘻哈哈。&#039;
}
]
}
}
window.parent.postMessage(JSON.stringify(msg), &#039;https://qyb.wxb.com&#039;)
});</code></pre>
<p>> 上面postMessage的第二个参数(https:xxxxxx.com)请指定:绑定本系统的域名。</p>
<p>上面能发送的消息对象<code>msg</code>可以使用下面这些数据格式:</p>
<pre><code class="language-js">{
&quot;msg_type&quot;: &quot;announcement&quot;,
&quot;content&quot;: {
&quot;text&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;text&quot;,
&quot;content&quot;: {
&quot;items&quot;: [
{
&quot;type&quot;: &quot;text|emotion|@|add|remove|ownerChanged|addManager|delManager|nameChanged&quot;,
&quot;text&quot;: &quot;&quot;,// 文本和表情对应的内容
&quot;at_id&quot;: &quot;&quot;,//可选, 0 代表 @所有人
&quot;at_name&quot;: &quot;&quot;,// 可选
&quot;wxid_list&quot;: &quot;&quot;,//可选, type对应add、remove、addManager、delManager
&quot;owner&quot;: &quot;&quot;//新群主id
}
]
}
}
---------------
{
&quot;msg_type&quot;: &quot;system&quot;,
&quot;content&quot;: {
同上面的文本消息...
}
}
---------------
{
&quot;msg_type&quot;: &quot;picture&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;voice&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;duration&quot;: 60,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;video&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;duration&quot;: 60,//秒
&quot;width&quot;: 0,
&quot;height&quot;: 0,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;link&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;title&quot;: &quot;&quot;,
&quot;cover&quot;: &quot;&quot;,
&quot;desc&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;file&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;title&quot;: &quot;&quot;,
&quot;ext&quot;: &quot;&quot;,
&quot;desc&quot;: &quot;&quot;,
&quot;size&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;program&quot;,
&quot;content&quot;: {
&quot;appid&quot;: &quot;&quot;,
&quot;name&quot;: &quot;&quot;,
&quot;title&quot;: &quot;&quot;,
&quot;cover&quot;: &quot;&quot;,
&quot;weapp_iconurl&quot;: &quot;&quot;,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;revoke&quot;,
&quot;content&quot;: {
&quot;wx_svrid&quot;: &quot;撤回的消息id&quot;,
&quot;wx_msgid&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;card&quot;,
&quot;content&quot;: {
&quot;wxid&quot;: &quot;&quot;,
&quot;nickname&quot;: &quot;&quot;,
&quot;avatar&quot;: &quot;&quot;,
&quot;corp_name&quot;: &quot;&quot;,
&quot;corp_wxid&quot;: &quot;&quot;,
&quot;name_in_corp&quot;: &quot;&quot;,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;channel&quot;,
&quot;content&quot;: {
&quot;title&quot;: &quot;&quot;,
&quot;desc&quot;: &quot;&quot;,
&quot;avatar&quot;: &quot;&quot;,
&quot;cover&quot;: &quot;&quot;,
&quot;url&quot;: &quot;&quot;,
&quot;org_content&quot;: &quot;&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;location&quot;,
&quot;content&quot;: {
&quot;address&quot;: &quot;西湖区古翠路&quot;,
&quot;latitude&quot;: &quot;30.2814&quot;,//纬度
&quot;longitude&quot;: &quot;120.12&quot;,//经度
&quot;title&quot;: &quot;西湖国际科技大厦(杭州市西湖区)&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;redpacket&quot;,
&quot;content&quot;: {
&quot;id&quot;: &quot;1800008896202109287186013419011&quot;,
&quot;msg&quot;: &quot;来自董文龙的红包,请进入手机版企业微信领取&quot;,
&quot;text&quot;: &quot;恭喜发财,大吉大利&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;emotionpic&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;http://shp.qpic.cn/emoji/0/d9b774afbe42baa129de9ca72273ed34/0&quot;,
&quot;width&quot;: 240,
&quot;heigth&quot;: 240,
&quot;md5&quot;: &quot;b6f812257bee53becb694dee947b636a&quot;
}
}
---------------
{
&quot;msg_type&quot;: &quot;imgtext&quot;,
&quot;content&quot;: {
&quot;msg_list&quot;: [
{
&quot;msg_type&quot;: &quot;text&quot;,
&quot;content&quot;: {
&quot;items&quot;: [
{
&quot;type&quot;: &quot;text&quot; | &quot;emotion&quot; | &quot;@&quot; | &quot;add&quot; | &quot;remove&quot;,
&quot;text&quot;: &quot;&quot;// 文本和表情对应的内容
}
]
}
},
{
&quot;msg_type&quot;: &quot;picture&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;&quot;,
&quot;org_content&quot;: &quot;&quot;
}
},
{
&quot;msg_type&quot;: &quot;emotionpic&quot;,
&quot;content&quot;: {
&quot;url&quot;: &quot;http://shp.qpic.cn/emoji/0/d9b774afbe42baa129de9ca72273ed34/0&quot;,
&quot;width&quot;: 240,
&quot;heigth&quot;: 240,
&quot;md5&quot;: &quot;b6f812257bee53becb694dee947b636a&quot;
}
}
]
}
}
---------------
{
&quot;msg_type&quot;: &quot;merge&quot;,
&quot;content&quot;: {
&quot;msg_list&quot;: [
{
&quot;msg_type&quot;: &quot;text&quot;,
&quot;content&quot;: {
&quot;items&quot;: [
{
&quot;text&quot;: &quot;谢谢冲冲姐,爱你哟&quot;,
&quot;type&quot;: &quot;text&quot;
},
{
&quot;text&quot;: &quot;[调皮]&quot;,
&quot;type&quot;: &quot;emotion&quot;
}
]
},
&quot;corp_name&quot;: &quot;&quot;,
&quot;corp_wxid&quot;: &quot;0&quot;,
&quot;from_name&quot;: &quot;灵历&quot;,
&quot;from_wxid&quot;: &quot;0&quot;,
&quot;msg_time&quot;: 1644476460
},
{
&quot;msg_type&quot;: &quot;text&quot;,
&quot;content&quot;: {
&quot;items&quot;: [
{
&quot;text&quot;: &quot;[动画表情]&quot;,
&quot;type&quot;: &quot;text&quot;
}
]
},
&quot;corp_name&quot;: &quot;&quot;,
&quot;corp_wxid&quot;: &quot;0&quot;,
&quot;from_name&quot;: &quot;福尔摩斯·姜🍀&quot;,
&quot;from_wxid&quot;: &quot;7881301765916792&quot;,
&quot;msg_time&quot;: 1644476460
},
{
&quot;msg_type&quot;: &quot;text&quot;,
&quot;content&quot;: {
&quot;items&quot;: [
{
&quot;text&quot;: &quot;[动画表情]&quot;,
&quot;type&quot;: &quot;text&quot;
}
]
},
&quot;corp_name&quot;: &quot;&quot;,
&quot;corp_wxid&quot;: &quot;0&quot;,
&quot;from_name&quot;: &quot;🇨🇳 果爷&quot;,
&quot;from_wxid&quot;: &quot;7881299731023559&quot;,
&quot;msg_time&quot;: 1644476520
}
],
&quot;title&quot;: &quot;群聊的聊天记录&quot;,
&quot;org_wxid&quot;: &quot;R:11111&quot;//合并转发时需要
}
}</code></pre>