消息
消息
消息
/**
* 发送文本消息[文本,表情]
* @param arg {
* to: String, //对话人id,必传
* type: String, //聊天类型,可能的值有chat:单聊,groupchat:群聊,pubaccount:公众号,不传默认chat
* content:String, //消息文本,必传
* body: Object, //扩展字段,选填
* success:function
* error:function
* }
*/
YYIMChat.sendTextMessage({
to: 'abc',
type: 'chat',
content: 'abc',
body: {},
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/*
*成功后返回字段(一个文本消息对象):
*/
{
data: {
content: "消息[愉快]", //消息内容
contentType: 2, //消息类型
dateline: 1525756786467, //发送时间
extend: "{"intelligentAnalysis":{"intelligentable":true}}" //消息扩展
},
from: "zongtf", //发送者id
id: "5075205B-CA24-41CE-9B7E-A4245724EAB1", //消息id
resource: "web-v2.6", //资源
sessionVersion: 0, //消息版本号
to: "majun5", //接受者id
type: "chat" //聊天类型
}
/**
* 发送图片消息
* @param arg{
* fileInputId:'DomID', //文件域id
* drop_element: 'dropID', //拖拽上传元素id,或者数组,无拖拽上传功能可不填
* chatInfo: function(){ //用户发送消息时获取对话人信息,必须为函数,必填
* return {
* to: String //对话人id
* type: String, //聊天类型chat/groupchat/pubaccount
* extend: String // 扩展字段,选填
* };
* },
* fileFiltered: function, //文件被添加到上传队列,必填
* fileUploaded: function, //上传队列某一个文件上传完毕,选填
* beforeUpload: function, //文件上传之前触发,必填
* progress: function, //上传进度,选填
* success:function,
* error: function,
* }
*/
YYIMChat.sendPic({
fileInputId: 'DomID',
drop_element: 'dropID',
chatInfo: function(){
return {
to: 'id',
type: 'chat',
extend: ''
}
},
fileFiltered: function(){},
fileUploaded: function(){},
beforeUpload: function(){},
progress: function(pro){
console.log('上传进度'+pro);
},
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/*
*成功后返回字段(一个图片消息对象):
*/
{
data: {
content: {
attachId: "", //资源id,可通过YYIMChat.getFileUrl(attachId)获取完整url
fid: 0,
from: 0,
id: "",
name: "", //图片名称
original: 1,
path: "", //图片路径
size: 10002, //图片大小
type: "png" //图片类型
},
contentType: 8, //消息类型
dateline: 1525756786467, //发送时间
extend: "{"intelligentAnalysis":{}}" //消息扩展
},
from: "zongtf", //发送者id
id: "", //消息id
resource: "web-v2.6", //资源
sessionVersion: 0, //消息版本号
to: "majun5", //接受者id
type: "chat" //聊天类型
}
/**
* 发送文件消息
* @param arg{
* fileInputId:'DomID', //文件域id
* drop_element: 'dropID', //拖拽上传元素id,或者数组,无拖拽上传功能可不填
* chatInfo: function(){ //用户发送消息时获取对话人信息,必须为函数,必填
* return {
* to: String //对话人id
* type: String, //聊天类型chat/groupchat/pubaccount
* extend: String // 扩展字段,选填
* };
* },
* fileFiltered: function, //文件被添加到上传队列,必填
* fileUploaded: function, //上传队列某一个文件上传完毕,选填
* beforeUpload: function, //文件上传之前触发,必填
* progress: function, //上传进度,选填
* success:function,
* error: function,
* }
*/
YYIMChat.sendFile({
fileInputId: 'DomID',
drop_element: 'dropID',
chatInfo: function(){},
fileFiltered: function(){},
fileUploaded: function(){},
beforeUpload: function(){},
progress: function(){},
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/*
*成功后返回字段(一个文件消息对象): 结构参照图片类型
*/
/**
* 发送分享消息[分享消息]
* @param arg {
* to: String, //对话人id, //必填
* type: String, //对话类型,chat:单聊,groupcgat:群聊,pubaccount:公众号,不填默认chat
* body: Object, //扩展字段,选填
* content:{
* shareImageUrl: String, //分享中图片的url
* shareUrl: String, //分享的url
* shareDesc: String, //分享的内容描述
* shareTitle: String //分享的标题
* },
* success:function
* error: function,
* }
*/
YYIMChat.sendShareMessage({
to: 'id',
type: 'chat',
body: {},
content:{
shareImageUrl: '',
shareUrl: '',
shareDesc: '',
shareTitle: ''
},
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/**
* 发送已读回执报文
* @param arg {
* to: String, //回执的对象,必传
* type: String, //聊天类型,可能的值:chat/groupchat/pubaccount,不填默认chat
* id: String, //报文id,必填
* sessionVersion: String //消息版本号,必填
* }
*/
YYIMChat.sendReadedReceiptsPacket({
to: 'abc',
id: 'abc',
type: 'chat',
sessionVersion: 255
});
初始化sdk时,通过注册回调函数方式处理在线消息的处理,例如:
YYIMChat.init({
//...,
onMessage : function(msg){}, // 接收到消息,返回一个消息对象
//...
});
/**
* 获取历史记录
* @param arg {
* id: String, //聊天对方id,必填
* type: String, //聊天类型,可能的值:chat/groupchat/pubaccount,必填
* contentType:Number, //内容类型,选填
* start: number, //开始时间戳,不填默认0
* size: number, //拉取成员长度,不填默认100
* startVersion: number, //开始的消息版本号,不填默认为0
* endVersion: number, //结束的消息版本号,必传
* success:function,
* error:function
* }
*/
YYIMChat.getHistoryMessage({
id: 'abc',
type: 'chat',
contentType: 2,
start: 0,
size: 150,
startVersion: 0,
endVersion: 100,
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/**
*成功时返回数据:
*/
{
list: [], //消息列表,列表元素是消息对象
contactReadVersion: 237, //消息被度的版本号,用来判断是否有未读消息
result: "success",
total: 20 //消息条数
}
/**
* 撤销消息
* arg {
* id: String, //消息id,必填
* to: String, //消息的另一方,待定
* type: String, //消息类型chat/groupchat/pubaccount
* success: function,
* error: function
* }
*/
YYIMChat.revokeMessage({
id: 'id',
to: 'to',
type: 'chat',
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});
/**
* 输入状态改变触发
* @param arg {
* to: String, //聊天对方id,必填
* contentType: Number, //内容类型,不传默认2,即TEXT类型
* success: function,
* error: function
* }
*/
YYIMChat.inputStateChange({
to: 'abc',
contentType: 2,
success:function(data){
console.log(data);
},
error:function(err){
console.log(err);
}
});