您所指的邮箱称为发送邮箱。如果您正在使用 BotFramework-Web Chat,您可以通过
styleOptions
传递值来禁用它,如下所示:
<script>
(async function () {
const styleOptions = {
hideSendBox = true
}
[...]
window.ReactDOM.render(
<ReactWebChat
directLine={directLine},
styleOptions={styleOptions}
/>,
document.getElementById( 'webchat' )
);
})
</script>
如果您使用的是 iFrame 嵌入式版本的 Web Chat,则不可配置。
希望有帮助!
如果您希望发送框根据从机器人接收到的活动类型做出响应,那么您将需要使用
activityMiddleware()
函数以及事件发射器/侦听器的组合。在下面的示例中,当 suggestedActions
是活动属性时,我隐藏/显示发送框。
请注意,数据值应为“none”和“flex”。特别是,当后者不是
suggestedActions
时,为了保持当前代码。
<script>
(async function () {
[...]
const activityMiddleware = () => next => card => {
const { activity: { suggestedActions } } = card;
const toggleSendBoxEvent = new Event('ToggleSendBoxEvent')
if (suggestedActions) {
toggleSendBoxEvent.data = "none";
window.dispatchEvent(toggleSendBoxEvent);
} else {
toggleSendBoxEvent.data = "flex";
window.dispatchEvent(toggleSendBoxEvent);
}
return next(card);
)
[...]
window.ReactDOM.render(
<ReactWebChat
directLine={ window.WebChat.createDirectLine({ token }) }
activityMiddleware={ activityMiddleware }
/>,
document.getElementById( 'webchat' )
);
window.addEventListener('ToggleSendBoxEvent', ( { data } ) => {
const sendBoxes = document.getElementsByClassName("main");
let send_Box;
for (let sendBox of sendBoxes) {
send_Box = sendBox;
}
send_Box.setAttribute('style', `display:${ data }`)
})
});
</script>
希望有帮助!
这对我来说真的很有效
<script type="text/babel" data-presets="es2015,react,stage-3">
(async function () {
const { ReactWebChat } = window.WebChat;
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
const toggleSendBoxEvent = new Event('ToggleSendBoxEvent')
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
toggleSendBoxEvent.data = "none";
window.dispatchEvent(toggleSendBoxEvent);
} else if (action.type === 'DIRECT_LINE/POST_ACTIVITY_FULFILLED') {
toggleSendBoxEvent.data = "flex";
window.dispatchEvent(toggleSendBoxEvent);
}
return next(action);
});
window.ReactDOM.render(
<ReactWebChat
directLine={window.WebChat.createDirectLine({ token: '<your token>' })}
store={ store }
/>,
document.getElementById('webchat')
);
window.addEventListener('ToggleSendBoxEvent', ( { data } ) => {
const sendBoxes = document.getElementsByClassName("webchat__send-box-text-box__input");
let send_Box;
for (let sendBox of sendBoxes) {
send_Box = sendBox;
}
send_Box.setAttribute('style', `display:${ data }`)
})
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>