Initialization

Initialization #

Note:

Please ensure you are doing the initialization job at the very beginning of your application’s lifecycle, otherwise there maybe unintended runtime exception.

API #

You can do the AIHelp initialization job by calling this method, we also provide apis for you to monitor SDK’s initialization status.

This API requires following parameters:

  • appKey / domain / appId

    Required. You can get these parameters at here.

  • language

    Optional. This is SDK’s defalut initial language; If you are not setting this, we will use device’s locale language to initialize AIHelp SDK. Check here to learn language code you may need. Going International?

Besides, if you are building with Android platform or HTML5, you will also need to pass other parameters. You can get more details in following code examples.

Code examples #

The code of initializing AIHelp on different platforms are as follows:

Unlike other build platforms, if you are initializing AIHelp SDK in Android, your application reference is also required.

Besides, please ensure you are initializing AIHelp in onCreate() method of your Application or MainActivity.

The code examples are as follows:

// init SDK in Application.java(recommended)
public class App extends Application implements OnAIHelpInitializedCallback {

    @Override
    public void onCreate() {
        super.onCreate();
        AIHelpSupport.init(this,
                "THIS IS YOUR APP KEY",
                "THIS IS YOUR APP DOMAIN",
                "THIS IS YOUR APP ID",
                "THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)");
        AIHelpSupport.setOnAIHelpInitializedCallback(this);
    }

    @Override
    public void onAIHelpInitialized() {
        // when init job is done, you can get callback here.
    }

}

// init SDK in MainActivity.java
public class MainActivity extends AppCompatActivity implements OnAIHelpInitializedCallback {
  	
  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      	AIHelpSupport.init(this,
                "THIS IS YOUR APP KEY",
                "THIS IS YOUR APP DOMAIN",
                "THIS IS YOUR APP ID",
                "THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)");
        AIHelpSupport.setOnAIHelpInitializedCallback(this);
    }
  
  	@Override
    public void onAIHelpInitialized() {
        // when init job is done, you can get callback here.
    }
  
}

For native iOS, you need to call AIHelpSupportSDK#init to start AIHelp’s initialization.

1、include the related .h file: #import <AIHelpSupportSDK/AIHelpSupportSDK.h>

2、do the init job in application: didFinishLaunchingWithOptions of AppDelegate.m

The code examples are as follows:

#import <AIHelpSupportSDK/AIHelpSupportSDK.h>
...
  
void AIHelp_onInitializationCallback() {
    // do something you want
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
		[AIHelpSupportSDK initWithApiKey:@"THIS IS YOUR APP KEY" 
              			domainName:@"THIS IS YOUR APP DOMAIN" 										 
              					appId:@"THIS IS YOUR APP ID" 
              				 language:@"THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)"];
	  [AIHelpSupportSDK setOnInitializedCallback:AIHelp_onInitializationCallback];
    ...
    return YES;
}

We also provide the same init function for cocos2dx platform.

1、include the AIHelpSupport.h file in your AppDelegate.cpp;

2、call AIHelpSupport::init function in AppDelegate::applicationDidFinishLaunching();

The code examples are as follows:

#include "AIHelpSupport.h"
...
void AIHelp_onAIHelpInit() {
    // do something you want
}

bool AppDelegate::applicationDidFinishLaunching() {
  	AIHelpSupport::init(
   			"THIS IS YOUR APP KEY",
    		"THIS IS YOUR APP DOMAIN",
    		"THIS IS YOUR APP ID",
    		"THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)");
	  AIHelpSupport::setOnAIHelpInitializedCallback(AIHelp_onAIHelpInit);
 ...
}

We also provide the same init function for Unity platform.

You should call init fuction at the very beginning of your application:

public class MyGameControl : MonoBehaviour
{
    ...
      
    void AIHelp_onAIHelpInit() {
    		// do something you want
		}
    
  	void Awake()
    {
        AIHelpSupport.init(
   				"THIS IS YOUR APP KEY",
    			"THIS IS YOUR APP DOMAIN",
    			"THIS IS YOUR APP ID",
    			"THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)");
      	AIHelpSupport::setOnAIHelpInitializedCallback(AIHelp_onAIHelpInit);
    }
    ...
}

You will need to configure your supportMode to determine your page route, you can get more details at here.

The code examples are as follows:

<script src="https://aihelp.net/webchat/aihelp.js"></script>
<script>
    (function () {
        var userConfig = {
            userId: "",
            userName: "",
            userTags: "tag1,tag2,tag3",
            customData: {
                key1: "value1",
                key2: "value2"
            }
        };
        var supportConfig = {
            conversationIntent: 1,
            alwaysShowHumanSupportButtonInBotPage: true,
            welcomeMessage: ""
        };
        var initConfig = {
            appKey:'THIS IS YOUR APP KEY',
            domain:'THIS IS YOUR APP DOMAIN',
            appId: 'THIS IS YOUR APP ID',
            appName: "THIS IS YOUR APP NAME",
            language:'THIS IS YOUR DEFAULT LANGUAGE(OPTIONAL)',
            supportMode: 'THIS IS YOUR SUPPORT MODE',
            supportConfig: supportConfig,
            userConfig: userConfig
        };
        if (typeof AIHelpSupport !== undefined) {
            AIHelpSupport.init(initConfig);
        }
    })();

    function openAIHelp() {
        AIHelpSupport.show();
    }
</script>

Remark #

The illustration shows where you can get the required parameters for initialization: