1

I'd like to use web-chat on a page that has a .Net form submission on Enter key that I cannot modify.

When the user is in webchat and clicks enter to send their message, it's submitting the form.

So I have an event listener to cancel that event keycode and instead send to the webchat dispatcher:

// prevents the enter key from triggering search
function EnterKeyFilter() {
  if (window.event.keyCode == 13) { 
    event.returnValue = false;
    event.cancel = true;
    let textBoxVar = __________________dunno!
    console.log(textBoxVar);
    store.dispatch({
      type: 'DIRECT_LINE/POST_ACTIVITY',
      meta: {
        method: 'keyboard'
      },
      payload: {
        activity: {
          channelData: undefined,
          text: textBoxVar,
          textFormat: 'plain',
          type: 'message'
        }
      }
    });
  }
}
window.addEventListener('keydown', EnterKeyFilter)

But I don't know what to send it -- I don't know how to get the action or activity or payload.

I got more information from tdurnford on how to intercept inside the store (or, after the dispatch?), but I need to trigger it.

const store = window.WebChat.createStore(
  {},
  ({ dispatch }) => next => action => {
    if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
      console.log({storeDispatchAction: action});
      //action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'email'], () => 'johndoe@example.com');
    }

    return next(action);
  }
);

Thank you

Joe Crockett
  • 161
  • 7

0 Answers0