What does the "store" object of the WebChat do?

1.3k views Asked by At

For the following javascript code snippet found at Health Bot Container Sample, the "store" object created from window.WebChat.createStore, what does the "store" object do? What is the "store" object's purpose?

I am reading the web chat api documentation, but the description and explanation of the "store" object is not clear.

Thank you very much for your help on this matter.

const store = window.WebChat.createStore({}, function(store) { return function(next) { return function(action) {
    if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        store.dispatch({
            type: 'DIRECT_LINE/POST_ACTIVITY',
            meta: {method: 'keyboard'},
            payload: {
                activity: {
                    type: "invoke",
                    name: "InitConversation",
                    locale: user.locale,
                    value: {
                        // must use for authenticated conversation.
                        jsonWebToken: jsonWebToken,

                        // Use the following activity to proactively invoke a bot scenario
                        /*
                        triggeredScenario: {
                            trigger: "{scenario_id}",
                            args: {
                                myVar1: "{custom_arg_1}",
                                myVar2: "{custom_arg_2}"
                            }
                        }
                        */
                    }
                }
            }
        });

    }
    
    return next(action);
}}});

1

There are 1 answers

9
Kyle Delaney On BEST ANSWER

The store is a Redux store. You will need to be familiar with Redux to fully understand it, but for the purposes of Web Chat you can think of it as an object that allows you to dispatch actions and use middleware. The samples in this folder should help you get the hang of it.