有没有办法在连接到直线时添加对话历史记录?
Is there a way to add conversation history when connecting to direct line?
我们正在使用 botframework-webchat v4。有什么方法可以提供将在聊天中显示的历史记录吗?
这是我目前拥有的,但它不起作用,不确定店内活动应该采用什么格式。
const store = window.WebChat.createStore(
{
activities: ['{"type":"message",...}']
},
({ dispatch }: { dispatch: any }) => (next: any) => (action: any) => {
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
const { activity } = action.payload;
if (activity.type === 'event' && activity.name === 'sample:backchannel') {
alert(JSON.stringify(activity, null, 2));
}
}
return next(action);
}
)
window.WebChat.renderWebChat(
{
directLine: this.directLine,
userID: this.userId,
styleOptions,
store
},
this.botWindowElement.nativeElement
);
提前致谢!!
@StevenKanberg 感谢您的帮助!
我在BotFramework-WebChat的源代码中找到了答案。
这是示例,
test('absolute timestamp', async () => {
const activities = [
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000000',
timestamp: '2019-08-08T16:41:12.9397263Z',
from: {
id: 'dl_654b35e09ab4149595a70aa6f1af6f50',
name: '',
role: 'user'
},
textFormat: 'plain',
text: 'echo "Hello, World!"'
},
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000001',
timestamp: '2019-08-08T16:41:13.1835518Z',
from: {
id: 'webchat-mockbot',
name: 'webchat-mockbot',
role: 'bot'
},
text: 'Echoing back in a separate activity.'
},
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000002',
timestamp: '2019-08-08T16:41:13.3963019Z',
from: {
id: 'webchat-mockbot',
name: 'webchat-mockbot',
role: 'bot'
},
text: 'Hello, World!'
}
];
const styleOptions = { timestampFormat: 'absolute' };
const { driver } = await setupWebDriver({ storeInitialState: { activities }, props: { styleOptions } });
从技术上讲,您上面的解决方案是可行的。虽然,它在长 运行 中的可扩展性不是很好。我建议您查看此 BotFramework-WebChat 实验示例 Conversation History. It utilizes the sendConversationHistory API。此示例有点复杂,但会准确执行您想要的操作,即在启动新会话时加载先前用户的对话。
如果您想要重新连接之前的对话(意思是使用相同的 conversationId
继续对话),那么您应该知道 Direct Line 服务具有某些限制。重新连接最多只能在最后一次 activity 对话后的 14 天内有效,如果存在活动,则只能在 24 小时内有效。
希望得到帮助!
我们正在使用 botframework-webchat v4。有什么方法可以提供将在聊天中显示的历史记录吗?
这是我目前拥有的,但它不起作用,不确定店内活动应该采用什么格式。
const store = window.WebChat.createStore(
{
activities: ['{"type":"message",...}']
},
({ dispatch }: { dispatch: any }) => (next: any) => (action: any) => {
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
const { activity } = action.payload;
if (activity.type === 'event' && activity.name === 'sample:backchannel') {
alert(JSON.stringify(activity, null, 2));
}
}
return next(action);
}
)
window.WebChat.renderWebChat(
{
directLine: this.directLine,
userID: this.userId,
styleOptions,
store
},
this.botWindowElement.nativeElement
);
提前致谢!!
@StevenKanberg 感谢您的帮助! 我在BotFramework-WebChat的源代码中找到了答案。
这是示例,
test('absolute timestamp', async () => {
const activities = [
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000000',
timestamp: '2019-08-08T16:41:12.9397263Z',
from: {
id: 'dl_654b35e09ab4149595a70aa6f1af6f50',
name: '',
role: 'user'
},
textFormat: 'plain',
text: 'echo "Hello, World!"'
},
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000001',
timestamp: '2019-08-08T16:41:13.1835518Z',
from: {
id: 'webchat-mockbot',
name: 'webchat-mockbot',
role: 'bot'
},
text: 'Echoing back in a separate activity.'
},
{
type: 'message',
id: '6266x5ZXhXkBfuIH0fNx0h-o|0000002',
timestamp: '2019-08-08T16:41:13.3963019Z',
from: {
id: 'webchat-mockbot',
name: 'webchat-mockbot',
role: 'bot'
},
text: 'Hello, World!'
}
];
const styleOptions = { timestampFormat: 'absolute' };
const { driver } = await setupWebDriver({ storeInitialState: { activities }, props: { styleOptions } });
从技术上讲,您上面的解决方案是可行的。虽然,它在长 运行 中的可扩展性不是很好。我建议您查看此 BotFramework-WebChat 实验示例 Conversation History. It utilizes the sendConversationHistory API。此示例有点复杂,但会准确执行您想要的操作,即在启动新会话时加载先前用户的对话。
如果您想要重新连接之前的对话(意思是使用相同的 conversationId
继续对话),那么您应该知道 Direct Line 服务具有某些限制。重新连接最多只能在最后一次 activity 对话后的 14 天内有效,如果存在活动,则只能在 24 小时内有效。
希望得到帮助!