H5&小程序 SDK API文档

H5&小程序 SDK API文档

1 初始化启动接口

接口描述:

启动 SDK

接口定义:

function init(obj: {
        appId: string,
        onSuccess: (res: any) => void,
        onFailure: (res: any) => void
    }): void;

接口说明:

参数 参数说明
appId 应用标识 APPID
onSuccess 初始化成功回调
onFailure 初始化失败回调

接口示例:


import AISDK from './lib/aisdk-${platform}.js'
import GTC from './lib/gtc-${platform}.js'
App({
    globalData: {},
    onLaunch: function () {

       AISDK.init({
            appId: DEFAULT_APP_ID,
            onSuccess: function (res) {
                const text = '初始化成功:' + stringify(res)
                console.log(text)
            },
            onFailure: function (err) {
            /*
            onFailure中的错误码说明:
            -30001:网络错误
            */
                const text = '初始化失败:' + stringify(err)
                console.error(text)
            }
        })

        console.log(AISDK.getVersion())
    },
});

2 请求智能体

接口描述:

获取智能体 url,展示智能体web。需要先初始化完成后,才能调用请求智能体API。

接口定义:

function loadAgent(obj: {
        agentId: string,
        show: boolean,
        onSuccess: (res: any) => void,
        onFailure: (res: any) => void
    }): void;

接口说明:

参数 参数说明
agentId 智能体ID
show 是否展示网页。在H5平台下,show=true时会在当前页面创建iframe并展示智能体页面。在小程序平台下,不支持show=true,开发者需要自行创建webview加载url
onSuccess 加载智能体成功回调
onFailure 加载智能体失败回调

接口示例:

var agentId = "xxx"
 AISDK.loadAgent({
            agentId,
            show: true,
            onSuccess: function (url) {
                const text = 'loadAgent 成功:' + url
                console.log(text)
            },
            onFailure: function (err) {
                const text = 'loadAgent 失败:' + stringify(err)
                console.error(text)
            }
        })

    /*
     onFailure中的错误码说明:
     -30001:网络错误

     -40001:频率超限,1s1次
     -40002:重复请求
     -40003:未注册成功
     -40004:agentid 不合法
     -40005:平台不支持show
     -40006:show参数不合法,show必须是bool值
     */

API说明文件

AISDK.d.ts⽂件如下

declare namespace AISDK {
    /**
     * 获取当前SDK版本
     * @returns {string} 当前SDK版本
     */
    function getVersion(): string;

    export function init(obj: {
        /**
         * 个推官网生成的appid
         */
        appId: string,
        /**
         * 初始化成功回调
         * @param res 初始化成功返回的数据
         */
        onSuccess: (res: any) => void,
        /**
         * 初始化失败回调
         * @param res 初始化失败返回的数据
         */
        onFailure: (res: any) => void
    }): void;

    /**
     * 请求智能体
     * @param  
     */
     export function loadAgent(obj: {
        agentId: string,
        show: boolean,
        onSuccess: (res: any) => void,
        onFailure: (res: any) => void
    }): void;


}

文档中心搜索

技术
咨询

微信扫一扫

随时联系技术支持

在线
咨询