【发布时间】:2020-05-16 11:14:17
【问题描述】:
我有一个静态聊天机器人,我可以通过它显示消息:
<ChatMessage bot={true}>Hi.</ChatMessage>
喜欢这张图片:
const ChatBot = () => {
return (
<Styled.ChatBox>
<ChatMessage bot={true}>Hi.</ChatMessage>
<ChatMessage bot={false}>Hello.</ChatMessage>
</Styled.ChatBox>
);
};
这是我的聊天机器人:
function ChatMessage(props) {
return (
<Styled.ChatMessage bot={props.bot}>{props.children}</Styled.ChatMessage>
);
}
ChatMessage.defaultProps = {
bot: false,
};
const Chat = props => {
console.log(props.children);
return (
<Styled.ChatBox>
<Styled.ChatHeader />
<Styled.ChatLog>{props.children}</Styled.ChatLog>
<Styled.ChatInput>
<textarea placeholder="aaaaa ..." rows={4} />
<button>Send</button>
</Styled.ChatInput>
</Styled.ChatBox>
);
};
但我想知道如何使动态显示消息与在文本区域中键入的内容相应地显示消息,并因此调用一些函数来检查作为字符串键入的内容并返回响应。但我不知道如何解决这种情况。基本上我需要在聊天中显示用户输入的消息并将该消息发送到我的后端(或前端的某些功能),然后该功能将向我发送响应。
【问题讨论】:
标签: javascript reactjs chatbot