1.在頁面上使用客服消息
<button open-type="contact" bindcontact="handleContact"></button>
必須屬性:
open-type="contact"
非必須屬性:
session-from - 會話來源(不同按鈕,可以設置不同值,表示不同的會話場景)
send-message-title - 會話內消息卡片標題(默認:當前標題)
send-message-path - 會話內消息卡片點擊跳轉小程序路徑(默認:當前分享路徑)
send-message-img - 會話內消息卡片圖片(默認:截圖)
show-message-card - 是否顯示會話內消息卡片(默認:false)
設置爲 true,用戶進行客服會話會在右下角顯示 '可能要發送的小程序' 提示,用戶點擊後可以快速發送小程序消息
bindcontact - 客服消息回調
如果用戶在會話中,點擊了由 '服務端' 發送的小程序消息,則會返回到小程序,我們可以通過 bindcontact 事件回調,來獲取用戶所點消息的頁面路徑 path 和 參數 query
// 回調事件
handleContact (e) {
console.log(e.path)
console.log(e.query)
}
/*
注意:
'服務端' 返回的小程序消息,只能是本小程序,但可以指定不同的頁面及參數
miniprogrampage - 小程序消息結構
title - 消息標題
pagepath - 小程序頁面路徑,支持參數,例如:pages/index/index?foo=bar
thumb_media_id - 小程序消息卡片封面,image 類型的 media_id
*/
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html
https://developers.weixin.qq.com/miniprogram/dev/component/button.html
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.send.html
2.服務端接收的消息類型:
text - 文本消息
Content - 文本內容
image - 圖片消息
PicUrl -
MediaId - 圖片消息媒體ID
可以調用接口 'getTempMedia - 獲取臨時素材' 拉取數據
miniprogrampage - 小程序卡片消息
Title - 標題
AppId - 小程序 appid
PagePath - 小程序頁面路徑
ThumbUrl - 小程序封面圖的臨時 cdn 鏈接
ThumbMediaId - 小程序封面圖的臨時素材id
event - 事件消息
user_enter_tempsession - 進行會話事件
sessionForm - '客服會話按鈕' 上設置的 'session-from - 會員來源',有助於我們分析不同場景
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/receive.html
3.服務端發送的消息類型:
text - 文本消息
image - 圖片消息
link - 圖文消息(easywechat 使用的還是 news)
miniprogrampage - 小程序卡片消息
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.send.html
4.轉發客服消息:
可以將用戶的消息,轉發到網頁版的客服工具,接入多客服系統
返回的消息類型爲:
transfer_customer_service
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/trans.html
5.關於消息中,涉及到的媒體文件問題:
MediaId 以及 ThumbMediaId,有 2 個接口:
1>uploadTempMedia - 上傳臨時素材
參數:
acccess_token
type - 文件類型(目前只有:image)
media - form-data 中媒體文件標識,有filename、filelength、content-type等信息(FormData 表單數據)
2>getTempMedia - 下載臨時素材
參數:
acccess_token
media_id - 媒體文件ID
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.uploadTempMedia.html
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.getTempMedia.html
6.下發客服狀態:
這個沒測試
參考文檔:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/typing.html
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.setTyping.html
7.EasyWeChat 開發
小程序的客服消息:$app->customer_service。同公衆號的客服消息應該是一致的。
同時,進入消息、接收消息、發送消息的用法,都是參照公衆號文檔。
客服消息,跟發送普通消息的區別是(以 text 消息爲例):
// 普通消息
return new Text('你好!');
// 客服消息
$message = new Text('你好!');
$app->customer_service->message($message)->to($open_id)->send();
參考文檔:
服務端
https://www.easywechat.com/docs/4.1/official-account/server
消息
https://www.easywechat.com/docs/4.1/official-account/messages
多客服消息轉發(跟上面的第 4 點一樣,轉發給客服系統)
https://www.easywechat.com/docs/4.1/official-account/message-transfer