1
votes

I'm sending data from the web chat client, to the Bot via channel data, the following way:

const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
  if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
   // The channelData submitted here is very similar to HTTP cookies and vulnerable to forgery attack.
   // Make sure you use signature to protect it and verify the signature on the bot side.
   // To minimize unexpected behaviors, we recommend to treat the "action" object as if it is immutable.
   // We use simple-update-in package to update "action" with partial deep cloning.
   action = window.simpleUpdateIn(
     action,
     ['payload', 'activity', 'channelData', 'myCustomProperty'],
     () => 'Custom value'
   );
 }

 return next(action);
}); 

https://github.com/microsoft/BotFramework-WebChat/blob/master/samples/04.api/b.piggy-back-on-outgoing-activities/index.html

How do I access this data on the server side using C#?

2

2 Answers

2
votes

You can access it under channelData which is present under context object,full path below

dialogContext.Context.Activity.ChannelData

0
votes

i'm from Brazil and I got the solution to a similar problem. My final java script store object:

var cliente = {'xxx': 'xx', 'xx':'xx'} 
      const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
         if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
           dispatch({
             type: 'WEB_CHAT/SEND_EVENT',
             payload: {
               name: 'webchat/join',
               value: cliente
             }
           });
         }
         return next(action);
       });

And My C# Code:

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            await base.OnTurnAsync(turnContext, cancellationToken);
            if (turnContext.Activity.Name == "webchat/join")
            {
                await turnContext.SendActivityAsync(turnContext.Activity.Value?.ToString());
            }
            // Save any state changes that might have occurred during the turn.
            await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
            await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
        }