There is a time when we want our chat system send a message, as if it were from a user who is about to use our chat for the first time. This feature is common in Facebook Messenger with its "Get Started" message or in Telegram with its "/start". So, how do we do that in Qiscus widget?
You could flag user whether it is his/her first time to use the chat and make use of "sendComment" method in "chatRoomCreatedCallback" to do send a message. Shown in a snippet code below for web SDK,
https://codepen.io/ishlah/pen/rRNKop
QiscusSDK.core.init({
AppId: [your app id],
options: {
avatar: !0,
loginSuccessCallback: function() {
// Do something after successfully login
// Chat with available user, need to be register first
QiscusSDK.core.UI.chatTarget("qo@qiscus.com");
},
chatRoomCreatedCallback: function (room) {
// if this is for the first time user is having chat, than send "hi" to SDK
// as first trigger for bot
if (first_chat) {
var activeRoomId = QiscusSDK.core.selected.id;
var today = new Date();
var uniqueId = today.getTime();
var messageText = 'Hi' // you can use any text to trigger bot to start a conversation
// send comment to SDK
QiscusSDK.core.sendComment(
activeRoomId,
messageText,
uniqueId
);
// update first_chat value
i['first_chat'] = false;
localStorage.setItem("data", JSON.stringify(i))
}
}
}
});
Comments
0 comments
Please sign in to leave a comment.