跳到主要内容

IBot

函数型 Agent 框架提供了 IBot 接口,开发者只要实现一个满足 IBot 的类,就可以部署起相应的服务。

IBot 完整的方法定义及对应的服务如下:

提供的服务IBot 方法名描述
POST /v1/aibot/bots/:botId/send-messagesendMessage与 Agent 进行对话
POST /v1/aibot/bots/:botId/wx-send-messagewxSendMessage与 Agent 进行对话(微信回调)
GET /v1/aibot/bots/:botIdgetBotInfo查询 Agent 配置信息
GET /v1/aibot/bots/:botId/recordsgetChatRecords查询 Agent 历史对话信息
POST /v1/aibot/bots/:botId/recommend-questionsgetRecommendQuestions获取推荐问题
POST /v1/aibot/bots/:botId/feedbacksendFeedback提交用户反馈
GET /v1/aibot/bots/:botId/feedbackgetFeedback查询用户反馈
POST /v1/aibot/bots/:botId/speech-to-textspeechToText语音转文字
POST /v1/aibot/bots/:botId/text-to-speechtextToSpeech文字转语音
GET /v1/aibot/bots/:botId/text-to-speechgetTextToSpeechResult获取文字转语音结果
POST /v1/aibot/bots/:botId/conversationcreateConversation创建会话
GET /v1/aibot/bots/:botId/conversationgetConversation查询会话
PATCH /v1/aibot/bots/:botId/conversation/:conversationupdateConversation更新会话
DELETE /v1/aibot/bots/:botId/conversation/:conversationdeleteConversation删除会话

使用 BotCore 基类 能够更加快速地实现 IBot 接口。

方法​

sendMessage()​

sendMessage(input): Promise<void>

sendMessage - POST /v1/aibot/bots/:botId/send-message

与 Agent 问答对话接口实现,该接口无返回值,接口内需要通过 this.sseSender 发送 Server-Sent Events 给客户端

微信基础库 wx.cloud.extend.AI.bot.sendMessage API 对应接口

参数​

调用参数详见 HTTP API 文档


wxSendMessage()​

wxSendMessage(input): Promise<WeChatTextOutput>

wxSendMessage - POST /v1/aibot/bots/:botId/wx-send-message

使用微信接入后,微信客服消息回调 Agent 接口的实现,该接口根据微信 APPID 类型以及认证状态进行返回。

参数​

input​

WxSendMessageInput

Returns​

Promise<WeChatTextOutput>


getBotInfo()​

getBotInfo(input): Promise<GetBotInfoOutput>

getBotInfo - POST /v1/aibot/bots/:botId

获取 Agent 配置,返回 Agent 信息

微信基础库 wx.cloud.extend.AI.bot.get API 对应接口 https://developers.weixin.qq.com/miniprogram/dev/wxcloudservice/wxcloud/reference-sdk-api/extend/ai.html#AI-bot-get

参数​

调用参数详见 HTTP API 文档


getChatRecords()?​

optional getChatRecords(input): Promise<GetChatRecordOutput>

getChatRecords - GET /v1/aibot/bots/:botId/records

查询 Agent 历史对话信息接口实现,返回历史对话记录。

注意:需在 sendMessage 接口中实现记录对话信息,并在此接口查询对话信息并中返回

微信基础库 wx.cloud.extend.AI.bot.getChatRecords API 对应接口

参数​

调用参数详见 HTTP API 文档


getFeedback()?​

optional getFeedback(input): Promise<GetFeedbackOutput>

getFeedback - GET /v1/aibot/bots/:botId/feedback

获取用户反馈接口实现,返回用户反馈列表

微信基础库 wx.cloud.extend.AI.bot.getFeedBack API 对应接口

参数​

调用参数详见 HTTP API 文档


getRecommendQuestions()?​

optional getRecommendQuestions(input): Promise<void>

getRecommendQuestions - POST /v1/aibot/bots/:botId/recommend-questions

获取推荐问题接口实现,返回推荐问题列表

微信基础库 wx.cloud.extend.AI.bot.getRecommendQuestions API 对应接口

参数​

调用参数详见 HTTP API 文档


sendFeedback()?​

optional sendFeedback(input): Promise<SendFeedbackOutput>

sendFeedback - POST /v1/aibot/bots/:botId/feedback

发送用户反馈接口实现,返回发送用户反馈结果

微信基础库 wx.cloud.extend.AI.bot.sendFeedback API 对应接口

参数​

input​

SendFeedbackInput

返回​

Promise<SendFeedbackOutput>


speechToText()?​

optional speechToText(input): Promise<SpeechToTextOutput>

speechToText - POST /v1/aibot/bots/:botId/speechToText

语音转文字

参数​

调用参数详见 HTTP API 文档


textToSpeech()?​

optional textToSpeech(input): Promise<TextToSpeechOutput>

text-to-speech - POST /v1/aibot/bots/:botId/text-to-speech

文字转语音

参数​

调用参数详见 HTTP API 文档


getTextToSpeechResult()?​

optional getTextToSpeechResult(input): Promise<GetTextToSpeechResultOutput>

text-to-speech - GET /v1/aibot/bots/:botId/text-to-speech

获取文字转语音结果

参数​

调用参数详见 HTTP API 文档


createConversation()?​

optional createConversation(): Promise<CreateConversationOutput>

conversation - POST /v1/aibot/bots/:botId/conversation

创建会话

参数​

调用参数详见 HTTP API 文档


getConversation()?​

optional getConversation(input): Promise<GetConversationOutput>

conversation - GET /v1/aibot/bots/:botId/conversation

查询会话

参数​

input​

GetConversationInput

Returns​

Promise<GetConversationOutput>


updateConversation()?​

optional updateConversation(input): Promise<UpdateConversationOutput>

conversation - PATCH /v1/aibot/bots/:botId/conversation/:conversation

更新会话

参数​

input​

UpdateConversationInput

Returns​

Promise<UpdateConversationOutput>


deleteConversation()?​

optional deleteConversation(input): Promise<DeleteConversationOutput>

conversation - DELETE /v1/aibot/bots/:botId/conversation/:conversation

删除会话

参数​

input​

DeleteConversationInput

Returns​

Promise<DeleteConversationOutput>


类型​

GetChatRecordOutput​

属性​

recordList​

recordList: object[]

botId?​

optional botId: string

content?​

optional content: string

conversation?​

optional conversation: string

createTime?​

optional createTime: string

image?​

optional image: string

recordId?​

optional recordId: string

reply?​

optional reply: string

replyTo?​

optional replyTo: string

role?​

optional role: string

triggerSrc?​

optional triggerSrc: string

type?​

optional type: string

total​

total: number


GetFeedbackOutput​

属性​

feedbackList​

feedbackList: object[]

aiAnswer​

aiAnswer: string

botId​

botId: string

comment​

comment: string

createTime​

createTime: string

input​

input: string

rating​

rating: number

sender​

sender: string

tags​

tags: string[]

type​

type: string

total​

total: number


SendFeedbackInput​

属性​

aiAnswer​

aiAnswer: string

comment​

comment: string

input​

input: string

rating​

rating: number

recordId​

recordId: string

tags​

tags: string[]

type​

type: string


SendFeedbackOutput​

属性​

status​

status: "success"


SendMessageInput​

属性​

history?​

optional history: object[]

content​

content: string

role​

role: "user" | "assistant"

msg​

msg: string


WeChatTextInput​

Properties​

content​

content: string

createTime​

createTime: number

fromUserName​

fromUserName: string

msgId​

msgId: string

msgType​

msgType: string

toUserName​

toUserName: string


WeChatVoiceInput​

属性​

createTime​

createTime: number

format​

format: string

fromUserName​

fromUserName: string

mediaId​

mediaId: string

msgId​

msgId: string

msgType​

msgType: string

toUserName​

toUserName: string


WeChatWorkTextInput​

属性​

externalUserId​

externalUserId: string

msgId​

msgId: string

msgType​

msgType: string

openKfId​

openKfId: string

origin​

origin: number

sendTime​

sendTime: number

text​

text: object

content​

content: string


WeChatWorkVoiceInput​

属性​

externalUserId​

externalUserId: string

msgId​

msgId: string

msgType​

msgType: string

openKfId​

openKfId: string

origin​

origin: number

sendTime​

sendTime: number

voice​

voice: object

mediaId​

mediaId: string


WxSendMessageInput​

属性​

callbackData​

微信回调消息

callbackData: WeChatTextInput | WeChatVoiceInput | WeChatWorkTextInput | WeChatWorkVoiceInput

triggerSrc?​

根据微信 APPID 传入来源类型,微信订阅号: WXSubscription 微信服务号: WXService 微信小程序客服: WXMiniapp 企业微信客服: WXCustomerService

optional triggerSrc: string

wxVerify?​

微信 APPID 的认证状态

optional wxVerify: boolean


WeChatTextOutput​

属性​

Content?​

optional Content: string

CreateTime?​

optional CreateTime: number

FromUserName?​

optional FromUserName: string

MsgType?​

optional MsgType: string

ToUserName?​

optional ToUserName: string

SpeechToTextInput​

属性​

engSerViceType​

输入语言类型

engSerViceType: string

url​

语音文件链接

url: string

voiceFormat​

识别音频的音频格式,如 wav/mp3

voiceFormat: string


SpeechToTextOutput​

属性​

Result​

Result: string


TextToSpeechOutput​

属性​

TaskId​

TaskId: string


GetTextToSpeechResultOutput​

属性​

ResultUrl​

ResultUrl: string

Status​

Status: number

StatusStr​

StatusStr: string

TaskId​

TaskId: string


CreateConversationOutput​

属性​

conversationId​

conversationId: string

title​

title: string


GetConversationInput​

属性​

conversationId?​

optional conversationId: string

limit?​

optional limit: number

offset?​

optional offset: number


GetConversationOutput​

属性​

data​

data: object[]

conversationId​

conversationId: string

createTime​

createTime: string

title​

title: string

updateTime​

updateTime: string

total​

total: number


UpdateConversationInput​

属性​

conversationId?​

optional conversationId: string

title​

title: string


UpdateConversationOutput​

属性​

count​

count: number


DeleteConversationInput​

属性​

conversationId​

conversationId: string


DeleteConversationOutput​

属性​

count​

count: number


GetBotInfoOutput​

属性​

agentSetting?​

optional agentSetting: string

avatar?​

optional avatar: string

background?​

optional background: string

botId?​

optional botId: string

databaseModel?​

optional databaseModel: string[]

initQuestions?​

optional initQuestions: string[]

introduction?​

optional introduction: string

isNeedRecommend?​

optional isNeedRecommend: boolean

knowledgeBase?​

optional knowledgeBase: string[]

mcpServerList?​

optional mcpServerList: object[]

name?​

optional name: string

tools​

tools: object[]

url?​

optional url: string

model?​

optional model: string

modelValue?​

optional modelValue: string

multiConversationEnable?​

optional multiConversationEnable: boolean

name?​

optional name: string

searchEnable?​

optional searchEnable: boolean

searchFileEnable?​

optional searchFileEnable: boolean

tags?​

optional tags: string[]

type?​

optional type: string

updateTime?​

optional updateTime: number

voiceSettings?​

optional voiceSettings: object

enable?​

optional enable: boolean

inputType?​

optional inputType: string

outputType?​

optional outputType: number

welcomeMessage?​

optional welcomeMessage: string