react-chatbot-kit icon indicating copy to clipboard operation
react-chatbot-kit copied to clipboard

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

Open itsmejoeyb opened this issue 2 years ago • 2 comments

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!

itsmejoeyb avatar May 18 '22 20:05 itsmejoeyb

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

FredrikOseberg avatar May 29 '22 08:05 FredrikOseberg

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; `

tejasukal avatar Jul 15 '24 05:07 tejasukal