It is possible to add custom channel data to outgoing activities in Web Chat v4. You can create a custom store middleware to modify activities sent by the user. Channel data is a channel-specific property bag that can be used to send non-standard in-band data. Refer to the Backchannel Piggyback on Outgoing Activities Web Chat Sample for more details.
For example,
Here, I will be making use of the package simple-update-in
to update the immutable action objects. Then add the minified js file from unpkg.com to the < head> of the html:
…
<head>
<title>Web Chat: Inject data on post activity</title>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
+ <script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>
…
This helps to make use of the middleware to customise DIRECT_LINE/POST_ACTIVITY
by updating the action with deep cloning.
…
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);
}
);
…
Now all the DIRECT_LINE/POST_ACTIVITY
sent on this bot will have an email attached to the channel data. Similarly, you can customize the data you want to send.
Furthermore, as linked in the above answer, you can implement channel-specific functionality by passing the metadata to the channel in the activity object's channel data property.
Hope this helps.