FredrikOseberg / react-chatbot-kit

MIT License
297 stars 139 forks source link

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

Open VeenaMalali13 opened 3 years ago

VeenaMalali13 commented 3 years ago

I have react component "Somefile.jsx" from where I am calling 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} }

alanmrochadeveloper commented 2 years ago

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.