Desktop Push Notifications
You can create your own desktop notification by using newMessageCallback, for example:
x
// Show a nofication when receiving new message from Qiscus Chat SDK
qiscus.init({
AppId: 'YOUR_APP_ID',
options: {
// For documentation about event handler in Qiscus Chat SDK
// you can read it here
// http://sdk.qiscus.com/docs/web#event-handler
// and for more information about message object\
// you can just inspect it with your prefered devtools
// or even just doing `console.log` it.
newMessageCallback: function (messages) {
// Here you can setup a notification to notify your user,
// You can use a desktop notification, or simply
// modifying browser title
const message = messages
showDesktopNotification(message)
}
}
})
// For example showing a desktop notification for every new message
// docs: https://developer.mozilla.org/en-US/docs/Web/API/notification
function showDesktopNotification (data) {
if (Notification.permission() !== 'granted') {
Notification.requestPermission()
}
var username = data.username
var useravatar = data.user_avatar
var message = data.message
var notification = new Notification('You get a new message from ' + username, {
icon: useravatar,
body: message
})
}
Was this page helpful?