FredrikOseberg / react-chatbot-kit

MIT License
301 stars 141 forks source link

Possible to pass state to the action provider? #19

Closed tylert93 closed 3 years ago

tylert93 commented 3 years ago

Hi,

I just wanted to start by thanking for making this chatbot and the tutorials which went along with it. I have found the chatbot extremely useful for a project I am making in my professional life.

I was wondering if it would be possible for you to amend the source files so that the 'state' is passed to the action provider as a fourth argument. I use the state to store specific answers the user has given along the way. The then want to display the state to the user once they have answered all the questions so they can confirm if they are happy. Many of my answers require very specific questions and so I use widgets to display 'options' which then trigger a function within the action provider. As the state is not accessible within the action provider, I cannot display this to the user once they have answer all the questions.

Thanks

FredrikOseberg commented 3 years ago

@tylert93 Thanks! Actually, the state is accessible in the action provider, you can use the setState method to access all of the chatbot state:

in action provider 
const myAction = () => {
     this.setState(state => {
         console.log(state)
         // Perform your tasks here

         return state
     })
}
tylert93 commented 3 years ago

Awesome! thanks for your help and your quick response :)