我想在 Microsoft 聊天机器人中添加和发送消息,而无需在 Bot 窗口底部的文本区域中键入该消息。我需要将消息作为用户端的活动提供。
我们尝试使用以下代码设置文本值,但它仅在文本区域中显示消息,但当我们单击按钮时,消息未到达聊天机器人后端代码。
$('.webchat__send-box-text-box__input').val("测试一下这个")
$('.webchat__send-box-text-box__input').attr("value","测试一下这个")
我发现这种方法适用于 ReactJS。
componentDidMount(){
document.getElementsByClassName('wc-shellinput')[0].value = "testMsg"
console.log(this.chat);
this.chat.shellRef.props.onChangeText('testMsg');
}
我通常依赖webchat提供的hook 您的文档记录在 [github 上的网络聊天文档][1]
在你的情况下这应该足够了:
const [sendBoxValue, setSendBoxValue] = useSendBoxValue();
setSendBoxValue('testMsg');
[1]: https://github.com/microsoft/BotFramework-WebChat/blob/main/docs/HOOKS.md