'Auto scroll' not working On Microsoft-bot-Framework (Python SDK based)

六月ゝ 毕业季﹏ 提交于 2020-01-06 07:59:33

问题


I have some issue about microsoft-botframework.

I made a chatbot using microsoft-botframework Python SDK.

So I deploy it as Webchat , I attached this on my website, Wordpress.

However, the Auto-scroll on card doesn't work.

When new card appear, Auto scroll doesn't working.

So this is my critical Issue and I really want someone help.

Thank you.


回答1:


This is a known issue in WebChat. There is a work around where you can use a custom WebChat Activity Middleware that scrolls the last message into view when the chat window receives a new message. Take a look at the code snippet below.

const store = window.WebChat.createStore(
    {},
    ({ dispatch }) => next => action => {
        if (action.type === 'DIRECT_LINE/POST_ACTIVITY_FULFILLED') {
            document.querySelector('ul[role="list"]').lastChild.scrollIntoView({behavior: 'smooth', block: 'start'});
        }
        return next(action);
    }
);

window.WebChat.renderWebChat({
    directLine: window.WebChat.createDirectLine({ token }),
    store
}, document.getElementById('webchat'));

Hope this helps!




回答2:


This worked for me, but I have a strange usage (directline embedded in a Sharepoint page, ie. not absolute/fixed position):

 const store = window.WebChat.createStore(
    {},
    ({ dispatch }) => next => action => {
        if (action.type === 'DIRECT_LINE/POST_ACTIVITY_FULFILLED') {
            var scrollDiv = $('ul[role="list"]').first().parent();
            scrollDiv.scrollTop(scrollDiv[0].scrollHeight);
        }
        return next(action);
    }
  );    


  window.WebChat.renderWebChat(
  {
    directLine: window.WebChat.createDirectLine({
      token: 'mySecret'
    }),
    store,
    ...

Hope it can help someone else.

If you don't want to use jQuery, replace the 2 scrollDiv lines with:

var scrollDiv = document.querySelector('ul[role="list"]').parentElement;
scrollDiv.scrollTop = scrollDiv.scrollHeight;


来源:https://stackoverflow.com/questions/55614457/auto-scroll-not-working-on-microsoft-bot-framework-python-sdk-based

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!