ChannelIO
boot
Initialize for the SDK.
The Channel button appears, and features like the marketing pop-up are ready to use.
For more details, see boot.
ChannelIO('boot', bootOption: object, callback?: Function)
parameter | type | description |
---|---|---|
bootOption | object | A boot option to initialize the SDK. |
callback | (optional) Function | Callback function executed after boot. If boot fails, the callback receives an error object as the first argument and null as the second argument. If boot succeeds, the callback receives null as the first argument and a user object as 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
Stops all SDK operations and initializes internal data.
ChannelIO('shutdown');
showMessenger
Shows the messenger.
ChannelIO('showMessenger');
hideMessenger
Hides the messenger.
ChannelIO('hideMessenger');
openChat
Opens a chat.
- If
chatId
isundefined
, a new chat is opened. If themessage
argument is provided, it appears in the input field. If the workflow is active, it will be triggered. - If a chat corresponding to
chatId
exists, it is opened and themessage
argument is ignored. If the chat does not exist, an error page is displayed.
behavior | chatId | message | note |
---|---|---|---|
Open a new chat. | undefined | undefined | If the workflow is active, it will be triggered. |
Open a new chat with a message. | undefined | string | If the workflow is active, it will be triggered. The message appears in the input field after the workflow's operation. |
Open a specific chat. | string | undefined | If the chat does not exist, an error page is displayed. |
ChannelIO('openChat', chatId?: string, message?: string)
parameter | type | description |
---|---|---|
chatId | (optional) string | The chat ID. |
message | (optional) string | The message to be inputted in the input field when a new chat opens. |
// Opens a new chat.
ChannelIO('openChat');
// Opens a new chat with 'Text here' in the message field.
// If the support bot is active, it's triggered before the message appears.
ChannelIO('openChat', undefined, 'Text here');
// Opens a chat with ID '123' or displays an error page if it doesn't exist.
ChannelIO('openChat', '123');
openWorkflow
Opens a user chat and starts the specified workflow.
openWorkflow
can only be executed when the workflow trigger is set to "When starting a chat via Channel Talk."- If a corresponded workflow with the provided
workflowId
is exists, it will be executed. ifworkflowId
is invalid, an error page is displayed. - If you don't pass
workflowId
, no action is taken.
ChannelIO('openWorkflow', workflowId: string)
parameter | type | description |
---|---|---|
workflowId | string | The ID of workflow to start with. An error page will be shown if such workflow does not exist. |
// Starts an workflow with ID '123',
// or shows an error page if such workflow does not exist.
ChannelIO('openWorkflow', '123');
track
Tracks an event.
- If you track a new event that has not been created before, it will be created.
- It may take a few minutes to a few hours for the event to be visible at the desk.
ChannelIO('track', eventName: string, eventProperty?: object);
parameter | type | description |
---|---|---|
eventName | string | The name of the event. A maximum of 64 characters is allowed. |
eventProperty | (optional) object | The property of the event. |
// Tracks an event named 'OrderRequest'.
ChannelIO('track', 'OrderRequest');
// Tracks an event named 'Order' with additional properties.
ChannelIO('track', 'Order', {
"price": 100,
"currency": 'USD'
});
onShowMessenger
Registers a callback that is invoked when the messenger is shown.
ChannelIO('onShowMessenger', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when the messenger is shown. |
ChannelIO('onShowMessenger', function onShowMessenger() {
console.log('Messenger is shown.');
});
onHideMessenger
Registers a callback that is invoked when the messenger is hidden.
ChannelIO('onHideMessenger', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when the messenger is hidden. |
ChannelIO('onHideMessenger', function onHideMessenger() {
console.log('Messenger is hidden.');
});
onBadgeChanged
Registers a callback that is invoked when there is a change in the count of messages that the user has not yet read.
ChannelIO('onBadgeChanged', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when there is a change in the count of messages that the user has not yet read. The callback receives two arguments: unread (the total number of unread notifications, displayed as a red dot on the channel button) and alert (the number of important unread notifications, displayed as a number on the channel button). |
ChannelIO('onBadgeChanged', function onBadgeChanged(unread, alert) {
console.log(`Unread count: ${unread}, Alert count: ${alert}.`);
});
onChatCreated
Registers a callback that is invoked when a chat is created.
ChannelIO('onChatCreated', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when a new chat is created. |
ChannelIO('onChatCreated', function onChatCreated() {
console.log('New Chat is created.');
});
onFollowUpChanged
Registers a callback that is invoked when there are changes to the user's profile.
ChannelIO('onFollowUpChanged', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when the user's profile is updated. The callback receives the updated profile object as an argument. |
The profile object 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
Registers a callback that is invoked when the user clicks a link. This includes following links.
- Link button or Link text in marketing pop-ups
- Link button or Link text sent by managers or a user in chat
ChannelIO('onUrlClicked', callback: Function);
parameter | type | description |
---|---|---|
callback | Function | Callback function invoked when a link is clicked. It receives the URL of the clicked link as an argument. |
ChannelIO('onUrlClicked', function onUrlClicked(url) {
console.log(`User clicked URL: ${url}`);
});
clearCallbacks
Clears all callbacks registered by following APIs.
ChannelIO('clearCallbacks');
updateUser
Update a user’s information.
ChannelIO('updateUser', userObject: object, callback?: Function);
parameter | type | description |
---|---|---|
userObject | object | An object containing the user’s information to be updated. |
callback | (optional) Function | Callback function invoked after the update. If the update fails, the callback receives an error object as the first argument and null as the second argument.If the update succeeds, the callback receives null as the first argument and an updated user object at the second argument. |
You can set the following fields to update a user’s information.
field | type | description |
---|---|---|
language | (optional) string | Sets the user’s language. UI text changes to the specified language if language is ‘ko’ or ‘ja’ . Otherwise, UI text defaults to English. |
profile | (optional) object | null | Sets the user’s profile. Passing null resets the entire profile. To reset a specific field in the profile object, pass null for that field. Empty objects are not allowed, and field names should follow Camel Case. For mobileNumber , follow e.164 format. |
profileOnce | (optional) object | Sets the user’s profile with fields that have no existing values. |
tags | (optional) array | null | Sets the user’s tags. A maximum of 10 tags are allowed. Passing null resets all tags. Empty arrays are not allowed. |
unsubscribeEmail | (optional) boolean | Sets whether the user is subscribed to marketing emails. Subscription is terminated if set to true . |
unsubscribeTexting | (optional) boolean | Sets whether the user is subscribed to marketing SMS. Subscription is terminated if set to 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
Adds a user’s tags.
ChannelIO('addTags', tags: array, callback?: Function)
parameter | type | description |
---|---|---|
tags | string[] | An array of tags to add. A maximum of 10 tags is allowed. Tags are always in lowercase. |
callback | (optional) Function | Callback function invoked after adding tags. If the addition fails, the callback receives an error object as the first argument and null as the second argument. If the addition succeeds, the callback receives null as the first argument and an updated user object as the second argument. |
ChannelIO('addTags', ['tag1', 'tag2'], function onAddTags(error, user) {
if (error) {
console.error(error);
} else {
console.log('addTags success', user);
}
});
removeTags
Removes a user’s tags.
ChannelIO('removeTags', tags: array, callback?: Function)
parameter | type | description |
---|---|---|
tags | string[] | An array of tags to remove. If the corresponding tag does not exist, it will be ignored. Passing null or an empty array is not allowed. |
callback | (optional) Function | Callback function invoked after removing tags. If the removal fails, the callback receives an error object as the first argument and null as the second argument. If the removal succeeds, the callback receives null as the first argument and an updated user object as the second argument. |
ChannelIO('removeTags', ['tag1', 'tag2'], function onRemoveTags(error, user) {
if (error) {
console.error(error);
} else {
console.log('removeTags success', user);
}
});
setPage
Set the page along with user chat profile.
Page can be used instead of canonical URL.
Don’t pass
null
orundefined
topage
.If the
profile
parameter contains non-serializable value (e.g. function object), such values are ignored.
ChannelIO('setPage', page: string, profile?: Record<string, any>)
parameter | type | description |
---|---|---|
page | string | The value of the page to set. |
profile | (optional)Record<string, any> | The user chat profile value. When null is assigned to a specific field within the profile object, only the value of that field is cleared. The user chat profile value is applied when a user chat is created. |
// Sets the page to 'https://example.com/product'.
ChannelIO('setPage', 'https://example.com/product');
// Sets the page and userchat profile.
ChannelIO('setPage', 'https://example.com/product', {
currency: 'USD',
// ...
});
resetPage
Resets the page
and user chat profile value set by setPage .
When resetPage
is used, the canonical URL will be used as the page value.
ChannelIO('resetPage');
showChannelButton
Show the channel button.
After boot, channel button shows without
showChannelButton
.Manual execution of
showChannelButton
is only necessary if you have set hideChannelButtonOnBoot totrue
or have called hideChannelButton.
ChannelIO('showChannelButton');
hideChannelButton
Hides the channel button.
ChannelIO('hideChannelButton');
setAppearance
Set the appearance of the theme.
‘light’
: Uses the light theme.‘dark’
: Uses the dark theme.‘system’
: Follows the system theme.null
: Follows the theme setting from the desk.
ChannelIO('setAppearance', appearance: ‘light’ | ‘dark’ | ‘system’ | null)
parameter | type | description |
---|---|---|
appearance | ‘light’ | ‘dark’ | ‘system’ | null | The appearance setting for the theme. |
ChannelIO('setAppearance', 'dark');
Updated 13 days ago