Skip to main content

AITools

BotCore provides some tools for external use, enabling users to quickly implement basic features using tools.

AITools currently provides publicly available tools.

AITools method namedescription
searchDBQuery data model content
searchFileSearch file content
searchKnowledgeBaseQuery knowledge base content
searchNetworkQuery network content
sendWxClientMessageSend messages to the WeChat client
speechToTextSpeech to Text
textToSpeechText to Speech
getTextToSpeechObtain Text to Speech result
getWxMediaContentObtain the voice content in the WeChat callback

Methods

searchDB()

searchDB(botId, msg, databaseModel): Promise\<SearchDBResult>

Query data model content

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

msg

string

conversation message content

databaseModel

string[]

Data Model List

Returns

Promise\<SearchDBResult>

Usage Example

const result = await this.botContext.bot.tools.searchDB(
this.botContext.info.botId,
msg,
this.botContext.info.databaseModel
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query data model content: ${result?.message}`);
}

searchFile()

searchFile(botId, msg, files): Promise\<SearchFileResult>

Search file content

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

msg

string

conversation message content

files

string[]

fileID of files uploaded to cloud storage

Returns

Promise\<SearchFileResult>

Usage Example

const result = await this.botContext.bot.tools.searchFile(
this.botContext.info.botId,
msg,
files
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query file content: ${result?.message}`);
}

searchKnowledgeBase()

searchKnowledgeBase(botId, msg, knowledgeBase): Promise\<SearchKnowledgeResult>

Query knowledge base content

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

msg

string

conversation message content

knowledgeBase

string[]

Knowledge Base ID

Returns

Promise\<SearchKnowledgeResult>

Usage Example

const result = await this.botContext.bot.tools.searchKnowledgeBase(
this.botContext.info.botId,
msg,
this.botContext.info.knowledgeBase
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query knowledge base content: ${result?.message}`);
}

searchNetwork()

searchNetwork(botId, msg): Promise\<SearchNetworkResult>

Query network content

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

msg

string

conversation message content

Returns

Promise\<SearchNetworkResult>

Usage Example

const result = await this.botContext.bot.tools.searchNetwork(
this.botContext.info.botId,
msg
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query network content: ${result?.message}`);
}

sendWxClientMessage()

sendWxClientMessage(botId, triggerSrc, wxClientMessage): Promise\<toolsCommonResp>

Push messages to the WeChat client

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

triggerSrc

string

WeChat callback source

wxClientMessage

WxClientMessageDto

Message content pushed to the WeChat client

Returns

Promise\<toolsCommonResp>

Usage Example

const sendResult = await this.botContext.bot.tools.sendWxClientMessage(
this.botContext.bot.botId,
triggerSrc,
{
msgType: toWxMsgData?.msgType,
touser: toWxMsgData?.touser,
text: toWxMsgData?.text,
openKfId: toWxMsgData?.openKfId,
msgId: toWxMsgData?.msgId,
}
);
console.log("sendResult:", sendResult);

speechToText()

speechToText(botId, engSerViceType, voiceFormat, voiceUrl): Promise\<SpeechToTextResult>

Speech to Text

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

engSerViceType

string

Language

voiceFormat

string

Audio file type, Input language 16k_zh: Chinese General 16k_zh-PY: Chinese-English-Cantonese 16k_zh_medical: Chinese Medical 16k_en: English 16k_yue: Cantonese

voiceUrl

string

Voice file public network link

Returns

Promise\<SpeechToTextResult>

Usage Example

const result = await this.botContext.bot.tools.speechToText(
this.botContext.info.botId,
input.engSerViceType,
input.voiceFormat,
input.url
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Speech to Text failed: ${result?.message}`);
}

textToSpeech()

textToSpeech(botId, text, voiceType): Promise\<TextToSpeechResult>

Text to Speech

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

text

string

Text to be converted to speech

voiceType

number

Voice type to be converted to, Output voice type 101004: General Male Voice 101005: General Female Voice 601004: Advisory Male Voice 501001: Advisory Female Voice 101010: General Male Voice (Large Model) 101035: General Female Voice (Large Model)

Returns

Promise\<TextToSpeechResult>

Usage Example

const result = await this.botContext.bot.tools.textToSpeech(
this.botContext.info.botId,
input.text,
input.voiceType
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Text to Speech failed: ${result?.message}`);
}

getTextToSpeech()

getTextToSpeech(botId, taskId): Promise\<GetTextToSpeechResult>

Obtain Text to Speech result

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

taskId

string

taskID returned by the textToSpeech interface

Returns

Promise\<GetTextToSpeechResult>

Usage Example

const result = await this.botContext.bot.tools.getTextToSpeech(
this.botContext.info.botId,
input.taskId
);

if (result?.code && result?.code?.length !== 0) {
throw new Error(`Failed to query Text to Speech status: ${result?.message}`);
}

getWxMediaContent()

getWxMediaContent(botId, triggerSrc, media): Promise\<GetWxMediaContentResult>

Obtain the voice content in the WeChat callback

Parameters

botId

string

botId, that is, the ID of the function-type Agent.

triggerSrc

string

WeChat callback source

media

string

WeChat voice media ID

Returns

Promise\<GetWxMediaContentResult>

Usage Example

const mediaResult = await this.botContext.bot.tools.getWxMediaContent(
this.botContext.bot.botId,
triggerSrc,
mediaId
);

content = mediaResult?.content;

Type

ChatDBSearchResult

Properties

answerPrompt

answerPrompt: string

relateTables

relateTables: unknown[]


SearchDBResult

Properties

code?

optional code: string

message?

optional message: string

searchResult

searchResult: ChatDBSearchResult


SearchFileResult

Properties

code?

optional code: string

content

content: string

message?

optional message: string


KnowledgeBaseDocument

Properties

data

data: object

allParentParagraphTitles

allParentParagraphTitles: string[]

endPos

endPos: number

next

next: unknown[]

paragraphTitle

paragraphTitle: string

pre

pre: unknown[]

startPos

startPos: number

text

text: string

documentSet

documentSet: object

author

author: string

documentSetId

documentSetId: string

documentSetName

documentSetName: string

fileId

fileId: string

fileMetaData

fileMetaData: string

fileTitle

fileTitle: string


score

score: number


SearchKnowledgeResult

Properties

code?

optional code: string

documents

documents: KnowledgeBaseDocument

knowledgeBase?

optional knowledgeBase: string[]

knowledgeMeta?

optional knowledgeMeta: string[]

message?

optional message: string


SearchResult

Properties

abstract

abstract: string

extra?

optional extra: string

index

index: number

publisher

publisher: string

publishTime

publishTime: number

source

source: "thirdparty" | "knowledgebase"

title

title: string

url

url: string


SearchInfo

Properties

searchResults

searchResults: SearchResult[]


SearchNetworkResult

Properties

code?

optional code: string

content

content: string

message?

optional message: string

searchInfo

searchInfo: SearchInfo


toolsCommonResp

Properties

code?

optional code: string

message?

optional message: string


WxClientMessageDto

Properties

msgId

msgId: string

msgType

msgType: string

openKfId?

optional openKfId: string

text

text: object

content

content: string

touser

touser: string


SpeechToTextResult

Properties

code?

optional code: string

message?

optional message: string

result

result: string


TextToSpeechResult

Properties

code?

optional code: string

message?

optional message: string

taskId

taskId: string


GetTextToSpeechResult

Properties

code?

optional code: string

message?

optional message: string

resultUrl

resultUrl: string

status

status: number

statusStr

statusStr: string

taskId

taskId: string


GetWxMediaContentResult

Properties

code?

optional code: string

content

content: string

message?

optional message: string