Reactjs 如何在Microsoft botframework webchat的React组件中插入文本?
我想在MicrosoftChatbot中添加和发送消息,而无需在Bot窗口底部的textArea中键入该消息。 我需要将消息作为道具提供给react组件(botframework webchat) 我尝试了本文中给出的建议,但它对我不起作用 我该怎么做 我试过这个Reactjs 如何在Microsoft botframework webchat的React组件中插入文本?,reactjs,botframework,Reactjs,Botframework,我想在MicrosoftChatbot中添加和发送消息,而无需在Bot窗口底部的textArea中键入该消息。 我需要将消息作为道具提供给react组件(botframework webchat) 我尝试了本文中给出的建议,但它对我不起作用 我该怎么做 我试过这个 import { Chat } from "botframework-webchat"; class ChatBox extends Component { componentDidMount() { document.ge
import { Chat } from "botframework-webchat";
class ChatBox extends Component {
componentDidMount() {
document.getElementsByClassName('wc-shellinput')[0].value = "testMsg"
document.getElementsByClassName('wc-send')[0].click()
}
render() {
return (
<React.Fragment>
<div>
<Chat
directLine={{
secret:
"...."
}}
user={{ id: "Test" }}
bot={{ id: "Demo" }}
resize={"detect"}
ref="chatBox"
/>
</div>
</React.Fragment>
)
}
}
从“botframework-webchat”导入{Chat};
类ChatBox扩展组件{
componentDidMount(){
document.getElementsByClassName('wc-shellinput')[0]。value=“testMsg”
document.getElementsByClassName('wc-send')[0]。单击()
}
render(){
返回(
)
}
}
我不擅长React,但我发现在React中,我们只能通过其状态更新输入值。通过via,似乎有一个名为onChangeText()
的入口函数
因此,请尝试以下代码段来更新输入值:
componentDidMount(){
console.log(this.chat);
this.chat.shellRef.props.onChangeText('testMsg');
}
我将它作为
this.refs.chatBox.shellRef.props.onChangeText('testMsg')
添加到我的代码中,它成功了。。你救了我一天。非常感谢你。。。