AIHelp Cocos2d-x SDK Integration Guide
1. Download The AIHelp Cocos2d-x iOS SDK:
Select "Clone or download" to download the iOS SDK in the github page.
The folder aihelp-plugin-cocos2dx contains:
Subfolder Name | Description |
---|---|
ios/ElvaChatServiceSDK | AIHelp Android SDK Core Files |
v3.x/Classes | Contains the cpp Files for Cocos2dx version 3.x |
v2.x/Classes | Contains the cpp Files for Cocos2dx version 2.x |
2. Add AIHelp to your Cocos2dx project:
- Copy folder ElvaChatServiceSDK to the the root directory of your Cocos2dx Xcode project.
- Copy the cpp files under the folder Classes into the Classes folder of your Cocos2dx project, choose files to copy based on the version of your Cocos2dx.
- Add the following frameworks to Link Binary with Libraries
- CoreGraphics
- QuartzCore
- CoreText
- SystemConfiguration
- UIKit
- libsqlite3.0.tbd
- Security
- CoreSpotlight
- GameController(required by cocos2d-x)
- MediaPlayer(required by cocos2d-x)
- Webkit(if using
operation module API
)
3. Initialize AIHelp SDK in your Project
ECServiceCocos2dx::init( String appKey, String domain, String appId);
About Parameters:
Parameters | Description |
---|---|
AppKey | Unique Developer API Key |
Domain | AIHelp Domain Name. For Example: foo.AIHELP.NET |
AppId | Unique ID Assigned to your App. |
Coding Example:
// Must be called during application/game initialization, otherwise you can't use AIHelp properly ECServiceCocos2dx::init( "YOUR_API_KEY", "YOUR_DOMAIN_NAME", "YOUR_APP_ID");
4. Start using AIHelp
1. API Summary
Method Name | Purpose | Prerequisites |
---|---|---|
showElva |
Launch AI Conversation Interface | |
showElvaOP |
Launch Operation Interface | Need to configure Operation Sections |
showFAQs |
Show all FAQs by Sections | Need to Configure FAQs |
showConversation |
Launch Manual Conversation Interface | Need to setUserName and setUserId |
showSingleFAQ |
Show Single FAQ | Need to Configure FAQ |
setName |
Set APP/Game Name | Use it after Initialization |
setUserName |
Set User In-App Name | |
setUserId |
Set Unique User ID | |
setSDKLanguage |
Set SDK Language |
2. Launch the AI Conversation Interface,Use showElva
ECServiceCocos2dx::showElva( string playerName, string playerUid, int serverId, string playerParseId, string showConversationFlag);
or
ECServiceCocos2dx::showElva( string playerName, string playerUid, int serverId, string playerParseId, string showConversationFlag, cocos2d::ValueMap& config);
Coding Example:
// Presenting AI Help Converation with your customers void GameSettingsScene::menuHelpCallback(CCObject* pSender) { ECServiceCocos2dx::showElva ( "USER_NAME", "USER_ID", 123, "", "1", { elva-custom-metadata={ elva-tags='vip, pay1', VersionCode='3' } }); }
About Parameters:
- playerName: In-App User Name
- playerUid: In-App Unique User ID
- serverId: The Server ID
- playerParseId: Can be empty string, can NOT be NULL.
- showConversationFlag: Should be "0" or "1". If set at "1", the VIP conversation entry will be displayed in the upper right hand side of the AI conversation interface.
- config: Optional parameters for custom ValueMap information. You can pass specific Tag information using vector elva-tags, see the above coding example. Please note that you also need to configure the same tag information in the Web console so that each conversation can be correctly tagged.
Best Practice:
- Use this method to launch your APP's customer service. Configure specific welcome texts and AI story lines in the AIHelp Web Console to better the customer support experiences.
- Enable VIP Conversation Entry to allow users’ to chat with your human support team with the parameters "showConversationFlag" setting to "1", you may use this method for any user or as a privilege for some users only.
3. Launch The Operation Interface, use showElvaOP
The operation module is useful when you want to present updates, news, articles or any background information about your APP/Game to users.
ECServiceCocos2dx::showElvaOP( string playerName, string playerUid, int serverId, string playerParseId, string showConversationFlag, cocos2d::ValueMap& config);
or
ECServiceCocos2dx::showElvaOP( string playerName, string playerUid, int serverId, string playerParseId, string showConversationFlag, cocos2d::ValueMap& config, int defaultTabIndex);
Coding Example:
// Presenting Operation Info to your customers void GameSettingsScene::menuOperationCallback(CCObject* pSender) { ECServiceCocos2dx::showElvaOP ( "USER_NAME", "USER_ID", 123, "", "1", { elva-custom-metadata={ elva-tags='vip, pay1', VersionCode='3' } }); }
About Parameters:
- playerName: User Name in Game/APP
- playerUid: Unique User ID
- serverId: The Server ID
- playerParseId: Can be empty string, can NOT be NULL.
- showConversationFlag: Should be "0" or "1". If set at "1", the VIP conversation entry will be shown in the top right-hand side of the AI conversation interface.
- config: Custom ValueMap information. You can pass specific Tag information using vector elva-tags, see the above coding example. Please note that you also need to configure the same tag information in the Web console so that each conversation can be correctly tagged.
- defaultTabIndex: Optional. The index of the first tab to be shown when entering the operation interface. Default value is the left-most tab,if you would like to show the AI conversation interface (the right-most side) set it to 999.
Best Practice:
- Use this API to present news, announcements, articles or any useful information to users/players. Configure and publish the information in AIHelp web console.
4. Display FAQs, use showFAQs
ECServiceCocos2dx::showFAQs();
or
ECServiceCocos2dx::showFAQs (cocos2d::ValueMap& config)
Coding Example:
// Presenting FAQs to your customers void GameSettingsScene::menuFAQCallback(CCObject* pSender) { ECServiceCocos2dx::showFAQs ( { elva-custom-metadata={ elva-tags='vip,pay1', VersionCode='3' } }); }
About Parameters:
- config: Custom ValueMap information. You can pass specific Tag information using vector elva-tags, see the above coding example. Please note that you also need to configure the same tag information in the Web console to make each conversation be correctly tagged.
Best Practice:
- Use this method to show FQAs about your APP/Game properly. Configure FAQs in AIHelp Web Console. Each FAQ can be categroized into a section. If the FAQs are great in number, you can also add Parent Sections to categorize sections to make things clear and organized.
5. Show A Specific FAQ,use showSingleFAQ
ECServiceCocos2dx::showSingleFAQ(string faqId);
or
ECServiceCocos2dx::showSingleFAQ( string faqId, cocos2d::ValueMap& config);
Coding Example:
// Presenting FAQs to your customers void GameSettingsScene::menuFAQCallback(CCObject* pSender) { ECServiceCocos2dx::showSingleFAQ ( "20", { elva-custom-metadata={ elva-tags='vip,pay1', VersionCode='3' } }); }
About Parameters:
- faqId: The PublishID of the FAQ item, you can check it at AIHelp Web Console: Find the FAQ in the FAQ menu and copy its PublishID.
- config: Custom ValueMap information. You can pass specific Tag information using vector elva-tags, see the above coding example. Please note that you also need to configure the same tag information in the Web console to make each conversation be correctly tagged.
Self-Service:
If you configure the "self-service" link in FAQ's configuration, and set UserId, UserName, ServerId in SDK, then the FAQ shows with functional menu in the right-top cornor.
Best Practice:
- Use this method when you want to show a specific FAQ in a certain location of your APP/Game.
6. Set Your App's Name for AIHelp SDK to Display,use setName
ECServiceCocos2dx::setName(string game_name);
Coding Example:
ECServiceCocos2dx::setName("Your Game");
About Parameters:
- game_name: APP/Game Name
Best Practice:
- Use this method after the SDK initialization. The App's name will be displayed in the title bar of the customer service interface.
7. Set the Unique User ID, use setUserId
ECServiceCocos2dx::setUserId(string playerUid);
Coding Example:
ECServiceCocos2dx::setUserId("123ABC567DEF");
About Parameters:
- playerUid: Unique User ID
Best Practice:
- 1. Normally you do not need to use this method if you have passed user ID in another method. However, if you want to use the FAQ's
Self-Service
, then you must set the User Id first.
8. Set User Name,use setUserName
ECServiceCocos2dx::setUserName (string playerName);
Coding Example:
ECServiceCocos2dx::setUserName ("PLAYER_NAME");
About Parameters:
- playerName: User/Player Name
Best Practice:
- Use this method to set the user name, which will be shown in the web console's conversation page for the user. You can address the user with this name during the chat.
- Normally you do not need to use this method if you have passed user name in another method. However, if you want to use the FAQ's
Self-Service
, then you must set the User Id first.
9. Set Unique Server ID,use setServerId
ECServiceCocos2dx::setServerId(int serverId);
Coding Example:
ECServiceCocos2dx::setServerId("SERVER_ID");
About Parameters:
- serverId: The Unique Server ID
Best Practice:
- Normally you do not need to use this method if you have passed the server ID in another method. However, if you want to use the FAQ's
Self-Service
, then you must set the User Id first
10. Launch VIP Chat Console, use showConversation
(need to set UserName
)
ECServiceCocos2dx::showConversation( string playerUid, int serverId);
or
ECServiceCocos2dx::showConversation( string playerUid, int serverId, cocos2d::ValueMap& config);
Coding Example:
ECServiceCocos2dx::setUserName ("PLAYER_NAME"); ECServiceCocos2dx::showConversation( "PLAYER_ID", 123, { elva-custom-metadata={ elva-tags='vip, pay1', VersionCode='3' } });
About Parameters:
- playerUid: Unique User ID
- serverId: The Unique Server ID
- The Unique Server ID: Custom ValueMap information. You can pass specific Tag information using vector elva-tags, see the above coding example. Please note that you also need to configure the same tag information in the Web console to make each conversation be correctly tagged.
Best Practice:
- 1. Normally you do not need to use this method unless you intend to allow users to enter VIP conversations without engaging with the AI chat. You may use this method as a privilege for some users.
11. Set SDK Lanague,use setSDKLanguage
Setting the SDK Language will change the FAQs, Operational information, AI Chat and SDK display language.
ECServiceCocos2dx::setSDKLanguage(string language);
Coding Example:
ECServiceCocos2dx::setSDKLanguage("en");
About Parameters:
- language: Standard Language Alias. For example: en is for English, zh_CN is for Simplified Chinese。More language labels can be viewed through AIHelp Web Console:"Settings"-->"Language"->Alias.
Best Practice:
- Normally AIHelp will use the mobile's lanaguge configuration by default. If you intend to make a different language setting, you need to use this method right after the SDK initialization.
- If you allow users to change the APP language, then you need to use this method to make AIHelp the same lanague with your APP.
12. Set a Different Greeting Story Line.
If your APP provides multiple entries to AIHelp, and you intend to introduce different AI welcome texts and story lines to users from different entries, you can set config parameters in showElva
or showElvaOP
:
map.put("anotherWelcomeText","usersay");
Coding Example:
ArrayList<String> tags = new ArrayList(); tags.add("vip"); tags.add("pay1"); HashMap<String,Object> map = new HashMap(); map.put("elva-tags",tags); // note:anotherWelcomeText is key,should be unchanged. // you need to change usersay according to the "User Say" in your new // story line map.put("anotherWelcomeText","usersay"); HashMap<String,Object> config = new HashMap(); config.put("elva-custom-metadata",map); ECServiceCocos2dx::showElva( "elvaTestName", "12349303258", 1, "", "1", config);
or
ECServiceCocos2dx::showElvaOP( "elvaTestName", "12349303258", 1, "", "1", config);
Best Practice:
- Introduce different story lines to users from different sources.