连接到直线时是否可以添加对话历史记录?

时间:2019-10-28 17:09:13

标签: botframework web-chat

我们正在使用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
);

提前谢谢!

2 个答案:

答案 0 :(得分:0)

@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 } });

答案 1 :(得分:0)

从技术上讲,您的上述解决方案将起作用。虽然,从长远来看,它不是很可扩展。我建议您查看一下BotFramework-WebChat实验示例Conversation History。它利用sendConversationHistory API。该示例有点复杂,但是可以完全满足您的要求,即在启动新会话时加载先前用户的会话。

如果您 想要重新连接上一个对话(即使用相同的print(final_list[3]["banana"]) 继续对话),那么您应该意识到Direct Line服务具有某些限制。重新连接最多只能在该会话的上次活动后最多14天,如果存在活动,则只能在24小时内进行。

希望有帮助!