问题
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