
https://fredrikoseberg.github.io/react-chatbot-kit-docs/docs/
const AddButton = () => {
return (
<div>
<button>추가</button>
</div>
);
};
export default AddButton;
import DogPicture from '../components/AddButton.jsx"
const config = {
initialMessages: [createChatBotMessage("Hi!")],
widgets: [
{
widgetName: 'addButton',
widgetFunc: (props) => <AddButton {...props} />,
},
],
};
import React from 'react';
const ActionProvider = ({ createChatBotMessage, setState, children }) => {
const handleHello = () => {
const botMessage = createChatBotMessage('Hello. Nice to meet you.');
setState((prev) => ({
...prev,
messages: [...prev.messages, botMessage],
}));
};
const handleAdd = () => {
const botMessage = createChatBotMessage(
"해당 내용을 추가하시겠습니까?",
{
widget: 'addButton',
}
);
setState((prev) => ({
...prev,
messages: [...prev.messages, botMessage],
}));
};
// Put the handleHello and handleDog function in the actions object to pass to the MessageParser
return (
<div>
{React.Children.map(children, (child) => {
return React.cloneElement(child, {
actions: {
handleHello,
handleAdd,
},
});
})}
</div>
);
};
export default ActionProvider;
handleAdd 액션이 실행되게 되면 텍스트 아래에 widget이 생기게 된다.
{
widget: "checkWidget",
widgetProps: {
addData: data, // 데이터를 위젯에 넘긴다
},
}