question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ChannelData Is Empty on Server Side

See original GitHub issue

Screenshots

n/a

Version

lastest

Describe the bug

We are posting an event via DirectLine with channeldata. However, the channel data is empty on the bot side. I feel like I am missing something very basic but I cannot figure out what it is.

To Reproduce

CLIENT-SIDE

      // create directLine variable
                    var dl = window.WebChat.createDirectLine({ "token": tokenResponse });

                    // render webchat control
                    window.WebChat.renderWebChat(
                        {
                            directLine: dl,
                            renderMarkdown: markdownIt.render.bind(markdownIt),
                            groupTimestamp: groupTimestamp,
                            styleOptions: styleOptions,
                            userID: userId
                        },
                        document.getElementById('webchat')
                    );

                    // post activity to start conversation and trigger welcome message
                    var activity = {
                        from: {
                            id: userId
                        },
                        name: 'startConversation',
                        type: 'event',
                        value: '',
                        channelData: {
                            "personId": userId,
                            "environment": window.location.host,
                            "usercontext": payloadUserContext,
                            
                        }
                    };
                    dl.postActivity(activity).subscribe(function (id) {
                        if (console) {
                            console.log('"trigger requestWelcomeDialog" sent');
                        }
                    });

SERVER-SIDE

   public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            _logger.LogDebug(turnContext.Activity.ChannelData); // always empty
        }

Expected behavior

turnContext.Activity.ChannelData should contain object with data.

Additional context

[Bug]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stevkancommented, Jul 8, 2020

Consider using Web Chat’s store to update an activity when posted, as demonstrated in the 04.api/b.piggyback-on-outgoing-activities sample.

Please note: There are security considerations when posting potentially sensitive data from the page to the bot. As mentioned here, this can open you up to forgery attacks.

To send data back to the bot from the page, first add this script to your page:

<!-- We are using simple-update-in package to simplify demo code. -->
<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>

Next, create the Web Chat store and filter on the action type for DIRECT_LINE/POST_ACTIVITY actions and pass in your data:

const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
  if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
    // Mocking data to be sent
    const userId = 'xyz789';
    const payloadUserContext = action.payload;

    action = window.simpleUpdateIn(
      action,
      ['payload', 'activity', 'channelData'],
      () => ({
        'personId': userId,
        'environment': window.location.host,
        'userContext': payloadUserContext
      })
    )
  }
  return next ( action );
} );

Lastly, pass the store as a property in renderWebChat():

window.WebChat.renderWebChat({
  directLine: window.WebChat.createDirectLine({ token }),
  store
}, document.getElementById('webchat'));

image

This does append the data to every outgoing message from the page to the bot. You will need to alter the code to fit your needs, if you only want the data sent with specific activities.

Hope of help!

0reactions
dkonyayevcommented, Nov 18, 2019

Ok, I see it now. IT was confusing because Emulator and DirectLine trigger events differently. I moved my welcome code into OnEvent, and for specific Event Name I process user context.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChannelData is returning null - Stack Overflow
I have tried back channel mechanism but failed to get any value from the server side inside ChannelData. I have script tag src="https://cdn....
Read more >
Implement channel-specific functionality in Bot Framework SDK
To implement channel-specific functionality, you can pass native metadata to a channel in the activity object's channel data property.
Read more >
Creating Channels - React chat - GetStream.io
You can achieve this by leaving the channel ID empty and providing channel type and members.
Read more >
Work with channel data | Android Developers
The Android TV system database maintains records of channel data for TV inputs. In your setup activity, for each of your channels, ...
Read more >
Configuring Server Side Tags In Google Tag Manager
Google introduced server-side tagging in 2020. By implementing a server ... You should see an empty tag assistant summary dashboard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found