How to use the botframework-webchat.createStore function in botframework-webchat

To help you get started, we’ve selected a few botframework-webchat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botframework-solutions / solutions / testharnesses / typescript / assistant-WebChat / packages / app / src / App.js View on Github external
constructor(props) {
    super(props);

    this.state = {
      webChatStore: createStore(
        {},
        ({ dispatch }) => next => action => {
          // console.log(action);

          try {
            const { payload, type } = action;

            if (type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
              const { activity } = payload;

              if (
                activity.type === 'event'
                && activity.name === 'ActiveRoute.Directions'
              ) {
                console.log(activity);
github microsoft / BotFramework-WebChat / packages / playground / src / index.js View on Github external
let store;

window.addEventListener('keydown', event => {
  const { ctrlKey, keyCode } = event;

  if (ctrlKey && keyCode === 82) {
    // CTRL-R
    sessionStorage.removeItem(REDUX_STORE_KEY);
  } else if (ctrlKey && keyCode === 83) {
    // CTRL-S
    event.preventDefault();
    store && console.log(store.getState());
  }
});

store = createStore(
  onErrorResumeNext(() => JSON.parse(window.sessionStorage.getItem(REDUX_STORE_KEY))),
  ({ dispatch }) => next => action => {
    if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
      dispatch({
        type: 'WEB_CHAT/SEND_EVENT',
        payload: { name: 'webchat/join', value: { language: window.navigator.language } }
      });
    }

    return next(action);
  }
);

store.subscribe(() => {
  sessionStorage.setItem(REDUX_STORE_KEY, JSON.stringify(store.getState()));
});
github microsoft / BotFramework-Composer / Composer / packages / client / src / pages / webchat / MinimizableWebchat.js View on Github external
window.hideWebchat = () => {
      this.handleMinimizeButtonClick();
    };

    window.insertStepAt =
      window.insertStepAt ||
      (() => {
        console.log('Cannot find API insertStepAt');
      });
    window.insertTypeAt =
      window.insertTypeAt ||
      (() => {
        console.log('Cannot find API insertStepAt');
      });

    const store = createStore({}, ({ dispatch }) => next => action => {
      if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        setTimeout(() => {
          dispatch({
            type: 'WEB_CHAT/SEND_EVENT',
            payload: {
              name: 'webchat/join',
              value: {
                language: window.navigator.language,
              },
            },
          });
        }, 1000);
      } else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
        if (action.payload.activity.from.role === 'bot') {
          this.setState(() => ({ newMessage: true }));
        }
github microsoft / BotFramework-WebChat / samples / 14.customization-piping-to-redux / src / WebChat.js View on Github external
constructor(props) {
    super(props);

    this.store = createStore({}, dispatchIncomingActivityMiddleware(props.appDispatch));

    this.state = {};
  }
github microsoft / BotFramework-WebChat / samples / 12.customization-minimizable-web-chat / src / MinimizableWebChat.js View on Github external
constructor(props) {
    super(props);

    this.handleFetchToken = this.handleFetchToken.bind(this);
    this.handleMaximizeButtonClick = this.handleMaximizeButtonClick.bind(this);
    this.handleMinimizeButtonClick = this.handleMinimizeButtonClick.bind(this);
    this.handleSwitchButtonClick = this.handleSwitchButtonClick.bind(this);

    const store = createStore({}, ({ dispatch }) => next => action => {
      if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
        setTimeout(() => {
          dispatch({
            type: 'WEB_CHAT/SEND_EVENT',
            payload: {
              name: 'webchat/join',
              value: {
                language: window.navigator.language
              }
            }
          });
        }, 1000);
      } else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
        if (action.payload.activity.from.role === 'bot') {
          this.setState(() => ({ newMessage: true }));
        }