自定义消息
如果您想实现访客进入对话时主动发送一条自定义消息(如商品咨询提示、活动引导语等),可以通过添加 URL 参数 custommsg 来实现。
使用前提:本接口面向具备前端开发能力的技术人员,调用前请确保已获取客源多对话链接基础 URL(即含
appid 参数的链接)。接口能力概览
参数:custommsg=消息JSON字符串
位置:对话链接 URL 查询参数
支持消息类型:文本消息(type:0)、卡片消息(type:6)
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
custommsg |
string | 自定义消息 JSON 字符串,需先 JSON.stringify 再 encodeURIComponent 编码 |
消息格式
| 消息类型 | type 值 | 消息结构 |
|---|---|---|
| 文本消息 | 0 | { type: 0, content: "文本内容" } |
| 卡片消息 | 6 | { type: 6, content: "卡片JSON字符串" },其中 content 为 JSON.stringify 后的 { title, description, imgurl, url } |
示例代码
文本消息
// 自定义文本消息
var txt = { type : 0, content : encodeURIComponent("文本消息内容") };
// 将文本消息网址编码
var custommsg = encodeURIComponent(JSON.stringify(txt));
// custommsg 参数,参数值为自定义文本消息内容
http://www.域名.net/chat?appid=######&custommsg=custommsg
卡片消息
// 自定义卡片消息
var card = {
type : 6,
content : encodeURIComponent(JSON.stringify({
"title" : "标题",
"description" : "描述",
"imgurl" : "图片地址",
"url" : "跳转链接"
}))
};
// 将卡片消息网址编码
var custommsg = encodeURIComponent(JSON.stringify(card));
// custommsg 参数,参数值卡片消息
http://www.域名.net/chat?appid=######&custommsg=custommsg