ChannelIO
boot
Initialize for the SDK.
Channel button shows up, and features like marketing pop-up are ready to operate.
See boot for more details.
ChannelIO('boot', bootOption: object, callback?: Function)
parameter | type | description |
---|---|---|
bootOption | object | A boot option to initialize SDK. |
callback | (optional) Function | Callback called after boot. When boot fails, the callback passes an error object at the first argument, null at the second argunent.When boot succeeds, the callback passes null at the first argument, a user object at the second argument. |
ChannelIO('boot', {
pluginKey: 'YOUR_PLUGIN_KEY'
}, function onBoot(error, user) {
if (error) {
console.error(error);
} else {
console.log('boot success', user);
}
});
shutdown
Stop all operations of the SDK and initialize internal data.
ChannelIO('shutdown');
showMessenger
Show the messenger.
ChannelIO('showMessenger');
hideMessenger
Hide the messenger.
ChannelIO('hideMessenger');
openChat
Open a chat.
If you pass an empty value for the chatId argument, a new chat will be opened. At this time, if you provide a message argument, that message will appear in the input field. If the support bot is active, it will be triggered.
If a chat corresponding to the provided chatId argument exists, that chat will be opened. In this case, the message argument is ignored. If the chat does not exist, an error page will be displayed.
behavior | chatId | message | note |
---|---|---|---|
Open a new chat. | undefined | undefined | If the support bot is active, it will be triggered. |
Open a new chat with a message. | undefined | string | If the support bot is active, it will be triggered. The message will be inputted in the input field after the support bot has completed its operation. |
Open a specific chat. | string | undefined | If the chatId is invalid, an error page will be displayed. |
ChannelIO('openChat', chatId?: string, message?: string)
parameter | type | description |
---|---|---|
chatId | (optional) string | The id of the chat. |
message | (optional) string | The message that will be inputted in the input field when a new chat is opened. |
// A new chat will open.
ChannelIO('openChat');
// A new chat will open, and 'Text here' will be inputted in the message field.
// If the support bot is active, it will be triggered. After the support bot has completed, 'Text here' will be inputted in the message field.
ChannelIO('openChat', undefined, 'Text here');
// If a chat with an ID of '123' exists, it will be opened.
// If it doesn't exist, an error page will be displayed.
ChannelIO('openChat', '123');
openSupportBot
Opens a chat and initiates a specific support bot.
If a support bot corresponding to the supportBotId argument exists, that support bot will be triggered. If you do not provide the supportBotId, no action will be taken. If the support bot corresponding to the provided supportBotId does not exist, an error page will be displayed.
If you provide a message argument, it will be inputted in the chat input field after the support bot has completed its operation.
behavior | supportBotId | message | note |
---|---|---|---|
Trigger a specific support bot | string | undefined | If the supportBotId is invalid, an error page will be displayed. |
Trigger a specific support bot and input a message after completion | string | string | If the supportBotId is invalid, an error page will be displayed. |
ChannelIO('openSupportBot', supportBotId: string, message?: string)
parameter | type | description |
---|---|---|
supportBotId | string | ID of the support bot. |
message | (optional) string | The message that will be inputted in the input field after the support bot has completed its operation. |
// If a support bot with an ID of '123' exists, it will be triggered.
// If it doesn't exist, an error page will be displayed.
ChannelIO('openSupportBot', '123');
// If a support bot with an ID of '123' exists, it will be triggered.
// If it doesn't exist, an error page will be displayed.
// After the support bot has completed, 'Text here' will be inputted in the message input field.
ChannelIO('openSupportBot', '123', 'Text here');
track
Track an event.
If you track a new event that has never been created, the event is newly created.
It takes a few minutes to a few hours to see the event at the desk.
ChannelIO('track', eventName: string, eventProperty?: object);
parameter | type | description |
---|---|---|
eventName | string | The name of the event. Max 30 characters are allowed. |
eventProperty | (optional) object | The property of the event. |
// example 1
ChannelIO('track', 'OrderRequest');
// example 2
ChannelIO('track', 'Order', {
"price": 100,
"currency": 'USD'
});
onShowMessenger
Register a callback invoked when the messenger is shown.
ChannelIO('onShowMessenger', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when the messenger is shown. |
ChannelIO('onShowMessenger', function onShowMessenger() {
console.log('Messenger is shown.');
});
onHideMessenger
Register a callback invoked when the messenger is hidden.
ChannelIO('onHideMessenger', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when the messenger is hidden. |
ChannelIO('onHideMessenger', function onHideMessenger() {
console.log('Messenger is hidden.');
});
onBadgeChanged
Register a callback invoked when the count of messages that the user has not yet read.
ChannelIO('onBadgeChanged', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when the number of messages the user has not read yet changes. The callback passes unread as the first argument and alert as the second argument.unread is the number of all unread notifications the user has not read. It includes the number of alert . It is displayed as a red dot on the channel button.alert is the number of important notifications that the user has not read. It is displayed as a number on the channel button. |
ChannelIO('onBadgeChanged', function onBadgeChanged(unread, alert) {
console.log(`Unread is changed to ${unread}, alert is changed to ${alert}.`);
});
onChatCreated
Register a callback invoked when a chat is created.
ChannelIO('onChatCreated', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when a chat is created. |
ChannelIO('onChatCreated', function onChatCreated() {
console.log('New Chat is created.');
});
onFollowUpChanged
Register a callback invoked when the user changes the user’s profile.
ChannelIO('onFollowUpChanged', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when the user changes the user’s profile. It receives the profile object as the argument. |
The profile object passed to the callback's argument includes the following fields.
속성 | 타입 | 설명 |
---|---|---|
name | (optional) string | null | The name of a user. |
email | (optional) string | null | The email of a user. |
mobileNumber | (optional) string | null | The mobile number of a user. It follows E.164 format. |
ChannelIO('onFollowUpChanged', function onFollowUpChanged(profile) {
console.log('User changed profile', profile);
});
onUrlClicked
Register a callback invoked when the user clicks a link.
The links that the user can click include the following list.
- Link button/text in marketing pop-up
- Link button/text sent by manager in chat
ChannelIO('onUrlClicked', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | The callback invoked when the user clicks a link. It receives the URL of the link as the argument. |
ChannelIO('onUrlClicked', function onUrlClicked(url) {
console.log(`User clicked url: ${url}`);
});
clearCallbacks
Clear all callbacks registered by following APIs.
ChannelIO('clearCallbacks');
updateUser
Update user’s information.
ChannelIO('updateUser', userObject: object, callback?: Function);
parameter | type | description |
---|---|---|
userObject | object | Object with user’s information. |
callback | (optional) Function | The callback invoked after updating. When it fails, the callback passes an error object at the first argument, null at the second argument.When it succeeds, the callback passes null at the first argument, an user object at the second argument. |
You can set the following fields to update a user’s information.
field | type | description |
---|---|---|
language | (optional) string | Set user’s language. If language is ‘ko’ or ‘ja’ , UI text inside ChannelTalk changes with that language. Otherwise, UI text is set with English. |
profile | (optional) object | null | Set user’s profile. If you pass null , the whole profile is initialized. If you pass null to the specific field inside profile object, that specific field is initialized. An empty object is not allowed. The name of the field must follow Camel Case. If you pass mobileNumber , it must follow e.164 format. |
profileOnce | (optional) object | Set user’s profile. Among the fields inside profileOnce object, only the fields with no existing value are added. |
tags | (optional) array | null | Set user’s tags. Max 10 tags are allowed. If you pass null , tags are initialized. An empty array([] ) is not allowed. |
unsubscribeEmail | (optional) boolean | Set whether the user subscribes to the marketing email. Terminates subscription if the value is true . |
unsubscribeTexting | (optional) boolean | Set whether the user subscribes to the marketing SMS. Terminates subscription if the value is true . |
const userObject = {
language: 'ko',
tags: ['a', 'b'],
profile: {
email: '[email protected]',
mobileNumber: '+821012345678',
name: 'test name',
},
profileOnce: {
customerType: 'vip',
registeredAt: '2022-11-22'
},
unsubscribeEmail: false,
unsubscribeTexting: true
};
ChannelIO('updateUser', userObject, function onUpdateUser(error, user) {
if (error) {
console.error(error);
} else {
console.log('updateUser success', user);
}
});
addTags
Add a user’s tags.
ChannelIO('addTags', tags: array, callback?: Function)
parameter | type | description |
---|---|---|
tags | string[] | Array of the tags to add. If the same tag exists, only one tag is added. Max 10 tags allowed. Always lowercase. |
callback | (optional) Function | The callback invoked after addition. If it fails, the callback passes an error object at the first argument, null at the second argument.If it succeeds, the callback passes null at the first argument, a user object at the second argument. |
ChannelIO('addTags', ['tag1', 'tag2'], function onAddTags(error, user) {
if (error) {
console.error(error);
} else {
console.log('addTags success', user);
}
});
removeTags
Remove a user’s tags.
ChannelIO('removeTags', tags: array, callback?: Function)
parameter | type | description |
---|---|---|
tags | string[] | Array of the tags to remove. If the corresponding tag don’t exist, that tag is ignored. null or an empty array([] ) not allowed. |
callback | (optional) Function | The callback invoked after removal. If fails, the callback passes an error object at the first argument, null at the second argument.If succeeds, the callback passes null at the first argument, a user object at the second argument. |
ChannelIO('removeTags', ['tag1', 'tag2'], function onRemoveTags(error, user) {
if (error) {
console.error(error);
} else {
console.log('removeTags success', user);
}
});
setPage
Set page.
Page can be used instead of canonical URL.
Don’t pass
null
orundefined
topage
.To reset the page, use resetPage.
ChannelIO('setPage', page: string)
parameter | type | description |
---|---|---|
page | string | The page value to change. |
ChannelIO('setPage', 'https://example.com/product');
resetPage
Reset the page
value set by setPage.
If you use resetPage
, the canonical URL is used as the page value.
ChannelIO('resetPage');
showChannelButton
Show channel button.
After boot, channel button shows without
showChannelButton
.Only when you set hideChannelButtonOnBoot to
true
or call hideChannelButton, you should manually executeshowChannelButton
.
ChannelIO('showChannelButton');
hideChannelButton
Hide channel button.
ChannelIO('hideChannelButton');
setAppearance
Set the appearance of the theme.
‘light’
: use light theme.‘dark’
: use dark theme.‘system’
: follow system theme.null
: follow desk’s theme setting.
ChannelIO('setAppearance', appearance: ‘light’ | ‘dark’ | ‘system’ | null)
parameter | type | description |
---|---|---|
appearance | ‘light’ | ‘dark’ | ‘system’ | null | The value of appearance to set. |
ChannelIO('setAppearance', 'dark');
Updated about 1 month ago