Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Integrating Core Code

Updated on 2024-03-05 GMT+08:00

Prerequisites

The Huawei Cloud operations administrator has configured the authentication API in the CEC.

Procedure

  1. Introduce the JavaScript dependent framework first. In the following example, the jQuery and Axios components need to be introduced. The reference versions are jQuery 1.8.0.js and Axios.min.js. If the co-browsing function is required, introduce the cobrowse.js and cobrowseCommon.js components or release the cobrowse plugin for use. (For details about the development of the plugin, see section 3.1 "Guide to the Development and Usage of the cobrowse Plugin.") The cobrowse.js and cobrowseCommon.js components are introduced in CDN mode. Replace ip:port with the IP address and port number of the CEC, or directly with the domain name of the CEC, for example, https://www.test.com/service-cloud/resource.root/cobrowse/sdk/cobrowse.js. Figure 1 shows an example of the code. (Notes: 1. Co-browsing operations cannot be performed on a new tab page.) 2. When the cobrowse.js and cobrowseCommon.js components for co-browsing are introduced and the third-party page contains nested iFrames, co-browsing operations can be performed only in the iFrame where the JavaScript components are introduced. If an iFrame has a parent iFrame, co-browsing operations cannot be performed in the parent iFrame.

    Figure 1 Code example

    The cobrowse.js and cobrowseCommon.js components are introduced in CDN mode. Replace ip:port with the IP address and port number of the CEC, or directly with the domain name of the CEC, for example, https://www.test.com/service-cloud/resource.root/cobrowse/sdk/cobrowse.js.

  2. Obtain the JavaScript file address provided by the CEC, as shown in the following information. Replace the domain name with the actual one of the CEC.

    https://servicestage.besclouds.com/service-cloud/webclient/chat_client/js/thirdPartyClient.js?&t=1595993533588

  3. On the enterprise side, use Ajax to request to integrate the JavaScript script in the CEC. The following is the JavaScript code snippet. Variable definitions are described in the following table.

    	// Define the $aicc_ContextPath variable. The variable name must be $aicc_ContextPath, and the value is https://IP address:Port number/service-cloud/ or https://Domain name/service-cloud/.
     const $ContextPath = "https://ip:port/service-cloud"
    	// Construct request parameters.
     let timestamp = new Date().getTime();
     let serviceUrl = $ContextPath+ "/webclient/chat_client/js/thirdPartyClient.js?"+"&t=" + timestamp;
    	// The following variables need to be defined before being used. In this demo, the variables are defined when axios.js is introduced. For details about the parameters, see Table 1.
     let thirdUserData = {};
     thirdUserData['thirdUserToken'] ="XXXXXXXX";
     thirdUserData['thirdUserName'] = "XXXXXXXX" 
     thirdUserData['thirdUserId'] = "XXXXXXXX";
     thirdUserData['tenantSpaceId'] = "XXXXXXXX";
     thirdUserData['channelConfigId'] = "XXXXXXXX";
     thirdUserData['locale'] = "xx";
     thirdUserData['mapService'] = 'google';
    
        var importScript = (function (oHead) {
            function loadError(oError) {
                throw new URIError("The script " + oError.target.src + " is not accessible.");
            }
            return function (sSrc, fOnload) {
                var oScript = document.createElement("script");
                oScript.type = "text\/javascript";
                oScript.onerror = loadError;
                if (fOnload) { oScript.onload = fOnload; }
                oHead.appendChild(oScript);
                oScript.innerHTML = sSrc;
            }
    
        })(document.head || document.getElementsByTagName("body")[0]);
    
        function thirdValidate(thirdUserData) {
            let timestamp = new Date().getTime();
            let serviceUrl = $ContextPath + "/webclient/chat_client/js/newThirdPartyClient.js?"+"&t=" + timestamp;
    	// Request newThirdPartyClient.js.
            var request = $.ajax({
                url: serviceUrl,
                type: "POST",
                data: JSON.stringify(thirdUserData),
                crossDomain: true,
                dataType:"text",
                xhrFields: {withCredentials: true},
                error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.status); console.log(XMLHttpRequest.readyState); console.log(textStatus); },
                success: function (data) {
                    importScript(data)
                }
            });
        }
    
        applyChatWindow();
        function applyChatWindow() {
    
            thirdUserData['timestamp'] = timestamp;
            // Request the JavaScript file from the Service Cloud.
            axios({
                method: 'post',
                url: serviceUrl,
                data: JSON.stringify(thirdUserData),
                withCredentials: true
              })
              // Define JavaScript file variables and write them to the current web page.
              .then(resp => {
              if (resp && resp.status === 200) {
                  let str = 'var configId = "' + thirdUserData.channelConfigId + '";var userId = "' + thirdUserData.thirdUserId + '";var userName = "' + thirdUserData.thirdUserName 
                        + '";var tenantSpaceId = "' + thirdUserData.tenantSpaceId + '";var locale = "' + thirdUserData.locale  
                        + '";var token="'+ thirdUserData.thirdUserToken+'";';
                  importScript(str+resp.data);
              } else {
                this.$alert ("Link failed!");
                console.log(resp.status);
                console.log(resp);
              }
            });
        }

Table 1 Integration page parameters

Parameter

Mandatory or Not

Description

$ContextPath

Yes

Variable part of the request address in Step 2, which is usually a domain name or an IP address and port number. Replace IP address:Port number with the public network domain name of the AICC.

You are advised to configure the domain name or the IP address and port number in the configuration file or configuration table. The value of $ContextPath is obtained from the configuration item.

serviceUrl

Yes

Complete path obtained in Step 2.

Generally, the value of serviceUrl is not a full address. Instead, it consists of the $ContextPath variable and the fixed part. Ensure that the value of serviceUrl is the same as the request address provided by the CEC.

thirdUserToken

Yes

Native verification information of an enterprise, which is the same as the value of Token in the enterprise verification API.

tenantSpaceId

Yes

Tenant space ID. Choose Configuration Center > System Management > Tenant Information to view the value.

thirdUserId

Yes

Enterprise user ID. The value must be the same as that of userId in Table 1.

thirdUserName

Yes

Enterprise username. The value must be the same as that of userName in Table 1.

channelConfigId

Yes

Channel configuration ID. After the operations in 7 are complete, choose Configuration Center > Access Configuration > Channel Configuration to view the value.

locale

Yes

Tenant space language provided by the CEC.

  • zh: Chinese
  • en: English

mapService

No

User map service.

  • tencent
  • google

The default value is tencent.

NOTE:

Tencent Maps does not support locations outside China.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback