ChannelIO

This page describes ChannelIO of the Channel Talk React Native SDK (hereafter refer to SDK).)

boot

Loads the information needed to use the SDK. After a successful boot, you are ready to use the features of SDK. See boot for details.

ParameterrequiredDescription
bootConfigOA boot configuration. You can set the plugin key and position of Channel button, etc.
bootCallbackXA callback from boot . It returns bootStatus and User.
const config = {
  "pluginKey": YOUR_PLUGIN_KEY,
  "memberId": MEMBER_ID,
  "memberHash": MEMBER_HASH,
  "profile": {
    "name": NAME,
    "email": EMAIL,
    "mobileNumber": "+~~~",
    "avatarUrl": AVATAR_URL,
    OTHER_KEY: OTHER_VALUE,
  },
  "language": LANGUAGE, // "en", "ko", "jp"
  "unsubscribeEmail": BOOLEAN,
  "unsubscribeTexting": BOOLEAN,
  "trackDefaultEvent": BOOLEAN,
  "hidePopup": BOOLEAN,
  "channelButtonOption": {
    "xMargin": 16,
    "yMargin": 16,
    "position": POSITION,  // "left", "right"
  },
  "appearance": APPEARANCE // "system", "light", "dark"
}

ChannelIO.boot(config).then((result) => {
  // result.status
  // result.user
})

sleep

Disable all functions except receiving system push notifications and track. See About life cycle for more details.

ChannelIO.sleep();

shutdown

Terminate connection between SDK and Channel. shutdown will discontinue features of the SDK will be discontinued. See About life cycle for more information.

ChannelIO.shutdown();
ChannelIO.shutdown()
[ChannelIO shutdown];
ChannelIO.shutdown();

showChannelButton

Displays Channel button on the global screen.

ChannelIO.showChannelButton();

hideChannelButton

Hide Channel button on the global screen.

ChannelIO.hideChannelButton();

showMessenger

Shows the messenger.

ChannelIO.showMessenger();

hideMessenger

Hides the messenger.

ChannelIO.hideMessenger();

openChat

Opens a Chat. You can open a new one or open an existing chat.

Parameterrequireddescription
chatIdXThe id of chat. If chatId is invalid or nil, it will open a newly created chat.
messageXA filled message on the message input box. It will be valid when chatId is nil.
// Open chat id is '123'
ChannelIO.openChat("123", null);

// Same as ChannelIO.openChat("123", null);
// When chat id parameter is not null, message parameter is ignored.
ChannelIO.openChat("123", "asd");

// Open new chat like click start new chat in home
ChannelIO.openChat(null, null);

// Open new chat with "123" in input box. 
// If support bot is enabled, open support bot instead.
ChannelIO.openChat(null, "123");

track

Track the user’s event. See event tracking for more details.

ParamterDescription
eventNameEvent name

max length is 30
propertiesoptional

Event properties.
// Only send event name
ChannelIO.track(EVENT_NAME);

// Send event with properties
ChannelIO.track(
  EVENT_NAME, 
  { 
    PROPERTY_KEY_1: STRING_VALUE, 
    PROPERTY_KEY_2: INT_VALUE
  }
);

updateUser

Updates user information.

Parameterrequireddescription
userDataOInformation of the user to be updated.
callbackXCallback for the updated user information.
const user = {
  "language": LANGUAGE, // "ko", "jp", "en"
  "tags": ["1", "2", "3"],
  "profile": {
    "name": NAME,
    "email": EMAIL,
    "mobileNumber": '+~~~',
    "avatarUrl": AVATAR_URL,
    OTHER_KEY: OTHER_VALUE,
  },
  "profileOnce": {
  },
  "unsubscribed": BOOLEAN,
};
ChannelIO.updateUser(user).then((result) => {
  // result.error
  // result.user
});

addTags

Add tags to the user.

Previous user's tagParameterResult
["a"]["b"]["a", "b"]
null["a", "b"]["a", "b"]
["a", "c"]["a", "b"]["a", "b", "c"]
["a", "b", "c", "d", "e", "f", "g"]["g", "h", "i", "j"]["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
["a", "b", "c", "d", "e", "f", "g"]["g", "h", "i", "j", "k"]error: combined size is 11
Parameterrequireddescription
tagsOTags to add.
• The maximum length is 10.
• Tag cannot be duplicated.
• Tag is case-insensitive (Tags are renamed to the lower-case.)
• nil, list including nil, empty list, and an empty string is not allowed.
callbackXA Callback when the update completes. It returns an error when it fails to add.
let tags = ["1", "2", "3"];
ChannelIO.addTags(tags).then((result) => {
  // result.error
  // result.user
});

removeTags

Remove tags from the user. It Ignores if tags do not exist.

Previous user's tagParameterResult
["a", "b"]["a"]["b"]
["a"]["c"]["a"]
["a"]["A", "c"]null
Parameterrequireddescription
tagsOTags to be deleted.
nil or empty strings or lists containing them are not allowed.
callbackXA Callback when the remote tag completes. It returns an error when it fails to remove.
let tags = ["1", "2"];
ChannelIO.removeTags(tags).then((result) => {
  // result.error
  // result.user
});

setPage

Sets the name of the screen when track is calling. If you call track before setPage, it will not be reflected in the event.

parameterrequireddescription
pageXThe screen name when the track is called.
A setPage(nil) call will literally set the page name as nil.
ChannelIO.setPage(page)

resetPage

Resets the name of the screen when track is called. The default value is the name of the ViewController or Activity calling the track.

ChannelIO.resetPage()

initPushToken

Notifies the change of the device token to Channel Talk.

ParameterDescription
tokenPush token
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
  this.onRefreshListener = messaging().onTokenRefresh(fcmToken => {
    ChannelIO.initPushToken(fcmToken);
  });
}

componentWillUnmount() {
  this.onRefreshListener();
}

isChannelPushNotification

Checks if the push payload is targeting on Channel Talk SDK.

ParameterDescription
payload
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
	this.backgroundMessageHandler = messaging().setBackgroundMessageHandler(
	  async (remoteMessage) => {
      // this line -
	    ChannelIO.isChannelPushNotification(remoteMessage.data).then((result) => {
	        if (result) {
	          ChannelIO.receivePushNotification(remoteMessage.data).then((_) => { });
	        } else {
	          // TODO : Your FCM code
	        }
	      },
	    );
	  },
	);
}

componentWillUnmount() {
  this.backgroundMessageHandler();
}

receivePushNotification

Notifies an event that the user has received the push notification.

+ Android
Show push notification

ParameterDescriptionEtc.
payload
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
    this.backgroundMessageHandler = messaging().setBackgroundMessageHandler(
      async (remoteMessage) => {
        ChannelIO.isChannelPushNotification(remoteMessage.data).then((result) => {
            if (result) {
              ChannelIO.receivePushNotification(remoteMessage.data).then((_) => { });
            } else {
              // TODO : Your FCM code
            }
          },
        );
      },
    );
}

componentWillUnmount() {
  this.backgroundMessageHandler();
}

hasStoredPushNotification

Checks if the plugin has unhandled push notification. See push notifications for details.

ParameterDescriptionEtc.
activityBase activity to start chatAndroid only
if (ChannelIO.hasStoredPushNotification()) {
  ChannelIO.openStoredPushNotification();
}

openStoredPushNotification

Open chat according to the push data stored by receivePushNotifcation .

ParameterDescriptionEtc.
activityBase activity to start chatAndroid only
if (ChannelIO.hasStoredPushNotification()) {
  ChannelIO.openStoredPushNotification();
}

isBooted

Checks that the SDK is in the boot status.

setDebugMode

Sets SDK’s debug mode. If it sets true, SDK prints log messages in the console.

ParameterDescription
flagDebug flag
ChannelIO.setDebugMode(true);

setAppearance

Sets the appearance of the SDK.

ParameterTypeRequiredDescription
appearanceAppearanceOIf you specify "light" and "dark", fix the theme with its properties. If "system", follow the device's system theme. default value is "system".