0
votes

I am passing the token and userid from the direct line web channel. I want to know How to receive those values in Bot side to show the userid or email passed from the direct line channel.

<html>
<div id="webchat" role="main" />
<head>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
</head>
<body>
<script>
  window.WebChat.renderWebChat({
      directLine: window.WebChat.createDirectLine({ token: '@Model.Token' }),
        userID: '@Model.UserId'
  }, 
  document.getElementById('webchat'));
</script>
</body>
<html>
1
Please make sure to make my reply as answer if it had helped you ,so others can make use of it.Chithambara Kumar

1 Answers

1
votes

You can create a store like below and add c custom data channelData , i have used simpleUpdatein Package for it

const store = window.WebChat.createStore(
            {},
            ({ dispatch }) => next => action => {
                if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
                    action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'myData'], () => myDataObj);
                } 
                return next(action);
            }
        );

Then inject this store to directline instance like

window.WebChat.renderWebChat({
            directLine: window.WebChat.createDirectLine({
                token:  '@Model.Token', 
            }),
            userID: '@Model.UserId'
            store, 
        }, document.getElementById('webchat'));

Now in Bot side you can access it under context object ,full path below

dialogContext.Context.Activity.ChannelData

You can also take a look at this Samplefor more info