FredrikOseberg / react-chatbot-kit

MIT License
325 stars 155 forks source link

TypeError: Cannot read properties of undefined (reading 'createChatBotMessage') Possible NextJS issue? #108

Open itsmejoeyb opened 2 years ago

itsmejoeyb commented 2 years ago

When attempting to trigger an actionprovider method from a widget button I keep getting this error. If I call the method using messageparser the method works as expected. Only when calling the method from a widget does the error occur.

This could be a known NextJS issue although I didn't see it in the open issues... Or I may have something configured wrong.

Here is where the method is defined in the actionprovider: method

here is where its called in widget options: options

and this is a copy of the error:

Screen Shot 2022-05-18 at 4 14 20 PM

any ideas or suggestions would great! Thanks!

FredrikOseberg commented 2 years ago

Hi. Can you provide a reproducable example or steps to reproduce this error?

tejasukal commented 2 months ago

I'm facing same kind of error TypeError: Cannot read properties of undefined (reading 'actionProvider')

`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 handleDog = () => { const botMessage = createChatBotMessage( "Here's a nice dog picture for you!", { widget: "dogPicture", }, );

setState((prev) => ({
  ...prev,
  messages: [...prev.messages, botMessage],
}));

};

const handleJavascriptList = () => { const message = this.createChatBotMessage( "Fantastic, I've got the following resources for you on Javascript:", { widget: "javascriptLinks", }, );

this.updateChatbotState(message);

};

return (

{React.Children.map(children, (child) => { return React.cloneElement(child, { actions: { handleHello, handleDog, handleJavascriptList, }, }); })}

); };

export default ActionProvider; `