Rovo 触发器
(原为谈话助理-pubsub)
提供各种触发事件来驱动Rovo Chat的功能,例如发布订阅和 URL 参数钩头
示例用途
发布
import { usePublish } from "@atlaskit/rovo-triggers";
const YourComponent = () => {
const publish = usePublish('ai-mate');
const handleClick = () => {
publish({
type: "message-send",
data: "hello Rovo Chat",
source: "my-source", // source is used for analytics
})
}
return (
<div>
<button onClick={handleClick}>
Send message onbehalf of user in Rovo Chat
</button>
</div>
);
}
订阅
import { useSubscribe } from "@atlaskit/rovo-triggers";
const YourComponent = () => {
const [message, setMessage] = useState('Waiting for messages...');
useSubscribe({ topic: 'ai-mate' }, ({ type, data }) => {
if(type === 'message-received') {
setMessage(data)
}
});
return (<div>{message}</div>);
}
订阅( TriggerLasters)
import { useSubscribe } from "@atlaskit/rovo-triggers";
const YourComponent = () => {
const [message, setMessage] = useState('Waiting for messages...');
// This subscription will trigger immediately if an event has already been published to the 'ai-mate' topic
useSubscribe({ topic: 'ai-mate', triggerLatest: true }, ({ type, data, source }) => {
if(type === 'message-received') {
setMessage(data)
}
});
return (<div>{message}</div>);
}
装一次
出版商可将事件标记为 consumeOnce: true 只有一个挂起的例子
消费者应处理这一事件。 订阅者选择在稳定的情况下这样做
consumeOnceKey;共享相同密钥的订阅者将处理 a consumeOnce 事件总数.
无订阅者 consumeOnceKey 继续正常观察事件.
用于复制出版物的投递id由内部生成 rovo-triggers 没有
在事件有效载荷中暴露。 这破解了一个在多个挂载上发布扇形
订阅者;单独发布的呼叫作为单独事件处理.
const YourComponent = () => {
useSubscribe({ topic: 'ai-mate', consumeOnceKey: 'your-consumer' }, ({ type, data }) => {
if(type === 'message-send') {
sendMessage(data)
}
});
}
const AnotherComponent = () => {
const publish = usePublish('ai-mate');
const handleClick = () => {
publish({
type: 'message-send',
source: 'my-source',
consumeOnce: true,
data: { prompt: 'hello Rovo Chat' },
})
}
}
全部订阅
说明 - 别用这个 现在它只是想成为Rovo Chat的代名词 当新事件发布时打开, 如果它还没有打开.
import { useSubscribeAll } from "@atlaskit/rovo-triggers";
const YourComponent = () => {
useSubscribeAll(() => {
console.log('pubsub received an event')
// do something like open the Rovo Chat panel
});
});
}
有条件地运行订阅
您可以有条件地调用一个使用 triggerLatest 通过有条件的
<Subscriber /> 组件。 这对确保你处于最佳状态有帮助
触发是订阅( 例如不再加载)
const YourComponent = ({ startSubscription }: { startSubscription: boolean }) => startSubscription ? (
<Subscriber
topic={topic}
triggerLatest={true}
onEvent={({ type, data }) => {
if (type === 'message-send') {
setMsg(`${data} received at ${new Date().toLocaleTimeString()}`);
setCount(count + 1);
}
}}
/>
) : null
登记新事件
事件是一个主题和事件类型的组合. 因此,您可以通过 要么:
- 创建新
Topic,并利用现有EventTypes - 创建新
Topic,并创建一些新的EventTypes将使用 - 创建另一个
EventType用于对付现有Topic
这一点可能会随着效用和打字的演变而改变,因为要继续建立与此的结合 软件包.
专题
这个 ai-mate 主题被保留用于 conversation-assistant 事件,是唯一一个
当前存在。 看着这个空间.
事件类型
事件类型是指在Rovo Chat中发生的行动,或者您想引发的行动
在罗沃聊天室里 只要有一个注册 publish 活动 ai-mate 主题,你可以
订阅.
这项工作将随着一体化的发展而记录在案.
参数工具
Rovo Chat 使用很强的一组被编码的查询参数 rovoChat 用于
产品之间一致.
这些值可用于触发状态变化,路径,动作等.
-
clearPageRovoParams- 从地址栏中删除rooChat参数和它的价值. -
updatePageRovoParams- 方便地增加属性rovoChat地址栏中的参数;这是 帮助不断更新用于书签或共享的URL。 这种方法使用addRovoParamsToUrl在引擎盖下. -
addRovoParamsToUrl- 前一个功能在引擎盖下使用,但你可以称之为 直接将它们添加到任意的 URL 字符串中, 因此让我们假设您想要从嵌入式中重定向 面板到阿特拉斯并做某种事情,你可以调用这个并传递所有所需的数据以确保 在阿特拉斯上 -
getRovoParams- 你用来执行轨道参数中值的主要方法 能够执行 Atlas 页面路由,或触发嵌入式体验中的动作(根据UIConfig.fullScreen=false(中文(简体) )
这里有一些你可能使用的例子 getRovoParams 结果值:
- 打开新聊天
{ pathway: 'chat' } - 打开特定聊天
{ pathway: 'chat', conversationId: '123' } - 打开与特定代理商的新聊天
{ pathway: 'chat', agentId: '456' } - 打开特定代理聊天
{ pathway: 'chat', conversationId: '123', agentId: '456' } - 打开新聊天并发送消息
{ pathway: 'chat', prompt: 'What should I work on next?' } - 打开特定聊天并发送消息
{ pathway: 'chat', conversationId: '123', prompt: 'What should I work on next?' } - 打开与 Rovo 行程归属的聊天
{ pathway: 'chat', rovoJourneyId: '00000000-0000-4000-8000-000000000001' } - 打开特定代理聊天并发送消息
{ pathway: 'chat', conversationId: '123', agentId: '456', prompt: 'What should I work on next?' } - 浏览代理
{ pathway: 'agents-browse' } - 查看代理代理细节
{ pathway: 'agents-browse', agentId: '456' } - 打开创建代理体验
{ pathway: 'agents-create' }