botframework

How do I debug channel data in bot framework?


I have a bot where I've recently started passing channel data (user info) in from my directline client but now this makes it really hard to debug/test code that relies on this channel data.

Is there a way to have the Bot Framework Emulator send channel data or is there a better way to debug in this situation?


Solution

  • Emulator doesn't have an easy, built-in way to send custom channelData. There's a few different ways you can (kind of) do this, though:

    Debug Locally

    As @EricDahlvang mentioned (I forgot about this), you can debug any channel locally

    WebChat

    Emulator is built in WebChat, so the output will be the exact same. However, you miss some of the debugging functionality from Emulator.

    1. Clone a WebChat Sample
    2. Edit index.html with http://localhost:3978/api/messages and your channelData
    3. Run npx serve
    4. Navigate to http://localhost:5000

    Modify Messages In OnTurnAsync()

    This would only be for testing/mocking purposes and you'd want to ensure this doesn't go into production, but you can modify incoming messages inside OnTurnAsync() and manually add the channelData.

    Something like:

    public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = turnContext.Activity;
    
        activity.ChannelData = new
        {
            testProperty = "testValue",
        };
    

    You could even make it happen with only specific messages, with something like:

    if (turnContext.Activity.Text == "change channel data")
    {
        activity.ChannelData = new
        {
            testProperty = "testValue",
        };
    }
    

    There's a lot of different options with this one, you just need to make sure it doesn't go into production.