2

How do I sent custom data to my back end with each message the user sends? For example, let's say I want to send the user's local time (using the client's browser to run javascript: new Date()) with every message to my back end. How would I do this using Bot Framework Web Chat?

I'm using regular JS and not react.

AskYous
  • 4,332
  • 9
  • 46
  • 82

1 Answers1

3

You can check out the following example in the official docs. Basically you can add a Middleware from which you can "capture" all outgoing activities.

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

      return next(action);
    });

And now all 'DIRECT_LINE/POST_ACTIVITY' sent on this bot will now have an email added to the channel data.

Armend Ukehaxhaj
  • 533
  • 6
  • 17