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

How to call any method of action provider from another react component which is not a widget?

Open VeenaMalali13 opened this issue 3 years ago • 1 comments

I have react component "Somefile.jsx" from where I am calling <Chatbot> component of react-chatbot-kit. In Somefile.jsx I am calling "abc" method using setInterval to check session timeout. on 6th and 8th min of chat I want to display some session messages in chatbot using createChatbotMessage method. But we cant call this method in Somefile.jsx, because its not declared as widget. Can you please help me with this?

e.g class ActionProvidder{ .... .. abc(idleTime){ if(idleTime == 6) ---> display msg in chatbot ​ ​} }

In another file Somefile.jsx

class Somefile extends react.Component{

   how to call abc() here ???

...... <Chatbot config={config} actionProvide={ActionProvider} messageParser={MessageParsser} }

VeenaMalali13 avatar Jun 28 '21 08:06 VeenaMalali13

I'm not an expert, but why not try to use contextAPI. Since its parent, and contextAPI is easy to use. Set actionProvider as globalActionProvider in contextAPI state. so you can access it anywhere. Or any other state manager.

alanmrochadeveloper avatar Jul 23 '21 02:07 alanmrochadeveloper