insightIntent是Intents Kit的子模块,提供意图开放能力,包括共享和删除InsightIntent。应用/元服务可以通过调用本模块接口,向系统共享数据。意图框架根据共享的数据学习规律,在合适的时机在系统入口将对应的InsightIntent推荐给用户,用户点击后,根据应用/元服务声明的insightIntent API,跳转到对应页面。
举例说明:视频类应用通过insightIntent提供共享数据(如用户每天看视频的时间点、视频信息)和对应的开放API。意图框架将在用户每天看视频的时间点通过卡片推荐视频,用户点击卡片后,意图框架将调用该开放API打开视频。
起始版本: 4.0.0(10)
InsightIntent,包括意图名称、意图版本号、标识、Action信息、Entity信息。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| intentName | string | 否 | 否 | 表示意图名称,例如:'PlayMusic'。 |
| intentVersion | string | 否 | 否 | 表示意图版本,当前为初始版本'1.0.1'。 |
| identifier | string | 否 | 否 | 表示意图的标识符,开发者按照自身业务需要生成,作为单条共享记录的唯一标识符。该字段的生成方式可参考UUID生成方式,或基于时间戳生成随机字符串。例如:'52dac3b0-6520-4974-81e5-25f0879449b5'。 |
| intentActionInfo | IntentActionInfo | 否 | 否 | 表示意图的执行信息,例如:已执行或预测将要执行意图的时间。示例请参考shareIntent的示例代码。 说明: - 在5.0.0(12)版本之前,参数类型为{[key: string]: Object}。 - 从5.0.0(12)版本开始,参数类型为IntentActionInfo。该类型定义与5.0.0(12)之前版本兼容。 |
| intentEntityInfo | IntentEntityInfo | 否 | 否 | 表示意图的实体信息,包含行为和事件。示例请参考shareIntent的示例代码。 说明: 在5.0.0(12)版本之前,参数类型为{entityId: string; entityName: string; [key: string]: Object}。 从5.0.0(12)版本开始,参数类型为IntentEntityInfo。该类型定义与5.0.0(12)之前版本兼容。 |
IntentActionInfo,表示意图的执行信息。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| [key: string] | Object | 否 | 否 | 表示值的类型为包含一个或多个键值对的对象。其中键的类型为字符,值的类型为Object,键和值的取值范围因意图名称而异,具体请参考各垂域意图Schema。 |
IntentEntityInfo,表示意图的实体信息。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 5.0.0(12)
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| entityId | string | 否 | 否 | 表示意图实体的标识符,开发者按照自身业务需要生成,作为单条实体的唯一标识符。该字段的生成方式可参考UUID生成方式,或基于时间戳生成随机字符串。例如:'C10194368'。 |
| entityName | string | 否 | 否 | 表示意图实体的名称。取值请参考各垂域意图Schema。 |
| [key: string] | Object | 否 | 否 | 意图实体的其他信息,表示为一个或多个键值对。其中键的类型为字符,值的类型为Object,键和值的取值范围因意图名称而异,具体请参考各垂域意图Schema。 |
deleteIntent(context: common.BaseContext, intentName: string, identifiers: string[], callback: AsyncCallback<void>): void
删除InsightIntent。如果设置了identifiers参数,则删除intent名称下的identifiers对应的记录。否则,删除意图名称下的所有记录。使用callback异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| intentName | string | 是 | 表示意图的名称。 |
| identifiers | string[] | 是 | 表示意图的标识符。 |
| callback | AsyncCallback<void> | 是 | 回调函数。当删除操作成功,err为undefined,否则为错误对象。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('deleteIntent')
.onClick(() => {
// 删除意图下的某些记录
// 此处仅为示例,请根据实际代码上下文自行传入合适的context和意图标识符
insightIntent.deleteIntent(this.getUIContext().getHostContext(), 'PlayMusic', ['52dac3b0-6520-4974-81e5-25f0879449b5'], (error) => {
if (error?.code) {
// 处理业务逻辑错误
console.error(`deleteIntent failed, Code: ${error?.code}, message: ${error?.message}`);
return;
}
// 执行正常业务
console.info('deleteIntent succeed');
});
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
} deleteIntent(context: common.BaseContext, intentName: string, callback: AsyncCallback<void>): void
删除InsightIntent。清空指定意图名称下的所有记录。使用callback异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| intentName | string | 是 | 表示意图的名称。 |
| callback | AsyncCallback<void> | 是 | 回调函数。当删除操作成功,err为undefined,否则为错误对象。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('deleteIntent')
.onClick(() => {
// 删除指定意图下的所有记录
// 此处仅为示例,请根据实际代码上下文自行传入合适的context和意图标识符
insightIntent.deleteIntent(this.getUIContext().getHostContext(), 'PlayMusic', (error) => {
if (error?.code) {
// 处理业务逻辑错误
console.error(`deleteIntent failed, Code: ${error?.code}, message: ${error?.message}`);
return;
}
// 执行正常业务
console.info('deleteIntent succeed');
});
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
} deleteIntent(context: common.BaseContext, intentName: string, identifiers?: string[]): Promise<void>
删除InsightIntent。如果设置了identifiers参数,则删除intent名称下的identifiers对应的记录。否则,删除意图名称下的所有记录。使用Promise异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| intentName | string | 是 | 表示意图的名称。 |
| identifiers | string[] | 否 | 表示意图的标识符。如果填写该字段,则删除指定标识符的意图;如果未填写该字段,则删除意图名称下的所有记录。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('deleteIntent')
.onClick(() => {
// 删除意图下的某些记录
// 此处仅为示例,请根据实际代码上下文自行传入合适的context和意图标识符
insightIntent.deleteIntent(this.getUIContext().getHostContext(), 'PlayMusic', ['52dac3b0-6520-4974-81e5-25f0879449b5']).then(() => {
console.info('deleteIntent succeed');
})
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
} deleteEntity(context: common.BaseContext, entityName: string, entityIds: string[], callback: AsyncCallback<void>): void
根据实体ID删除InsightIntent实体。使用callback异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| entityName | string | 是 | 表示实体的名称。 |
| entityIds | string[] | 是 | 表示实体的id。 |
| callback | AsyncCallback<void> | 是 | 回调函数。当删除操作成功,err为undefined,否则为错误对象。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('deleteEntity')
.onClick(() => {
// 删除Entity数据
// 此处仅为示例,请根据实际代码上下文自行传入合适的context
insightIntent.deleteEntity(this.getUIContext().getHostContext(), 'PlayMusic', ['a5c9e9e3-3d0a-4e6a-9f3d-6b7c6b8d6b9f'], (error) => {
if (error?.code) {
// 处理业务逻辑错误
console.error(`deleteEntity failed, Code: ${error?.code}, message: ${error?.message}`);
return;
}
// 执行正常业务
console.info('deleteEntity succeed');
});
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
} deleteEntity(context: common.BaseContext, entityName: string, entityIds: string[]): Promise<void>
根据实体ID删除InsightIntent实体。使用Promise异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 4.0.0(10)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| entityName | string | 是 | 表示实体的名称。 |
| entityIds | string[] | 是 | 表示实体的id。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果的Promise对象。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('deleteEntity')
.onClick(() => {
// 删除Entity数据
// 此处仅为示例,请根据实际代码上下文自行传入合适的context
insightIntent.deleteEntity(this.getUIContext().getHostContext(), 'PlayMusic', ['a5c9e9e3-3d0a-4e6a-9f3d-6b7c6b8d6b9f']).then(() => {
console.info('deleteEntity succeed');
})
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
} getSid(context: common.BaseContext, renew: boolean): Promise<string>
获取Service Open ID。使用Promise异步回调。
模型约束: 该接口仅可在Stage模型下使用。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.AI.InsightIntent
起始版本: 5.0.0(12)
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| context | common.BaseContext | 是 | 表示应用上下文。 |
| renew | boolean | 是 | 是否强制从云端获取新的服务开放ID。如果为true,从云端获取新的服务开放ID;如果为false,则优先获取本地存储的服务开放ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<string> | Promise对象,返回获取到的Service Open ID。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 401 | The parameter check failed. |
| 1000101101 | The application has not been registered with the InsightIntent. |
| 1000101102 | HUAWEI Assistant has stopped providing services. |
| 1000101103 | The switch of the app in the Data source has been turned off. 适用版本:5.0.0(12)-5.1.0(18) |
| 1000101107 | Too many Service Open ID renew requests. |
| 1000101201 | The service is abnormal. |
示例:
import { insightIntent } from '@kit.IntentsKit';
@Entry
@Component
struct Index {
build() {
Column() {
Row() {
Button('获取Sid')
.onClick(() => {
// 获取SID
// 此处仅为示例,请根据实际代码上下文自行传入合适的context
insightIntent.getSid(this.getUIContext().getHostContext(), false).then((sid: string) => {
console.info(`getSid succeed!, sid: ${sid}`);
})
})
}
.justifyContent(FlexAlign.Center)
.alignItems(VerticalAlign.Center)
.width('100%')
}
.height('100%')
.width('100%')
}
}