limit. The default value 100
Message types. All message types by default
timestamp in milliseconds. If unspecified, or the value is set to 0, its value will be affected by reverse
Retrieve the message history of a chat room by tag.
Start time
Limit on quanity. The default value: 100.
The default value is 0.
tags ['tag1', 'tag2', 'tag3']
End time
Message type
Callback
You can call this API for custom messages, such as rock-paper-scissors and dice rolling.
This interface returns the message body in the sending state, and the sent message body needs to be obtained by passing options.done.
Calling this API can trigger:
chatroom.sendCustomMsg({
//The recipient receives the message using onMsg
//if msg.type === 'custom', the recipient reads msg.content and then calls the business code
content: JSON.stringify({type: 1}),
done: function(err, msg) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', msg)
}
}
})
Calling this API can trigger:
chatroom.sendFile({
type: 'image',
fileInput: 'domId',
done: function(err, msg) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', msg)
}
}
})
chatroom.previewFile({
type: 'image',
fileInput: fileInput,
uploadprogress: function(obj) {
console.log('Total size of a file: ' + obj.total + 'bytes');
console.log('Size of uploaded data: ' + obj.loaded + 'bytes');
console.log('Upload progress: ' + obj.percentage);
console.log('Upload progress in percentage: ' + obj.percentageText);
},
done: function(error, file) {
console.log('Uploading the image' + (!error?'success':'failure'));
// show file to the user
if (!error) {
var msg = chatroom.sendFile({
file: file,
done: sendMsgDone
});
console.log('Sending the image message, id=' + msg.idClient);
pushMsg(msg);
}
}
})
let message = chatroom.sendFile({
type: 'image',
fileInput: 'domId',
done: function(err, obj) {
if (err) {
console.log('Failed to send the message', err)
// Resend the message. When the file upload fails, the msg of the obj parameter contains the message body, and in other cases, the obj is the message body.
setTimeout(function () {
resendMessage(obj.msg ? obj.msg : obj)
}, 3000)
} else {
console.log('Message sent: ', obj)
}
}
})
// Get the idClient for rendering before uploading
console.log(message.idClient)
// Resend the message
function resendMessage(oldMessage) {
nim.sendFile(Object.assign(oldMessage, {
type: 'image',
fileInput: 'domId',
resend: true, // Note that the resend is marked as true, so that the idClient in oldMessage can be used.
done: function(err, obj) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', obj)
}
}
}))
}
Send a location message
This interface returns the message body in the sending state, and the sent message body needs to be obtained by passing options.done.
Calling this API can trigger:
chatroom.sendGeo({
//The recipient receives the message using onMsg
//if msg.type === 'geo', the recipient reads msg.geo, and then calls the business code
geo: {
lng: 116.3833,
lat: 39.9167,
title: 'Beijing'
},
done: function(err, msg) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', msg)
}
}
})
Send a text message
This interface returns the message body in the sending state, and the sent message body needs to be obtained by passing options.done.
Calling this API can trigger:
chatroom.sendText({
text: 'hello',
done: function(err, msg) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', msg)
}
}
})
Sending an alert Alerts are sent for notifications in a conversation. Typical use cases include welcome messages when joining a group or tips when hitting keywords for moderation in chats.
This interface returns the message body in the sending state, and the sent message body needs to be obtained by passing options.done.
Calling this API can trigger:
chatroom.sendTipMsg({
//The recipient receives the message using onMsg
//if msg.type === 'tip', the recipient reads msg.tip, and then calls the business code
tip: 'tip content',
done: function(err, msg) {
if (err) {
console.log('Failed to send the message', err)
} else {
console.log('Message sent: ', msg)
}
}
})
Retrieve the message history of a chat room..