Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Ezequiel Jadib 6b3df2c0b3
Update documentation links to point to new docs (#118)
7 years ago
..
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
1cac51aaa5
Merge pull request #119
7 years ago
6b3df2c0b3
Update documentation links to point to new docs (#118)
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
0a0ac96754
Adding samples related to documentation
7 years ago
1cac51aaa5
Merge pull request #119
7 years ago

README.md

You have to be logged in to leave a comment. Sign In

Middleware Bot Sample

A sample bot showing how to intercept messages and log them.

Prerequisites

The minimum prerequisites to run this sample are:

  • The latest update of Visual Studio 2015. You can download the community version here for free.
  • The Bot Framework Emulator. To install the Bot Framework Emulator, download it from here. Please refer to this documentation article to know more about the Bot Framework Emulator.

Code Highlights

One of the most common operations when working with conversational history is to intercept and log message activities between bots and users. The Microsoft.Bot.Builder.History namespace provides interfaces and classes for doing this. In particular, the IActivityLogger interface contains the definition of the functionality that a class needs to implement to log message activities.

Check out the DebugActivityLogger implementation of the IActivityLogger interface that writes message activities to the trace listeners only when running in debug.

public class DebugActivityLogger : IActivityLogger
{
    public async Task LogAsync(IActivity activity)
    {
        Debug.WriteLine($"From:{activity.From.Id} - To:{activity.Recipient.Id} - Message:{activity.AsMessageActivity()?.Text}");
    }
}

By default, the BotBuilder library registers a NullActivityLogger with the conversation container, which is a no-op activity logger. Check out the registration in the Autofac container of the DebugActivityLogger of the sample in the Global.asax.cs.

var builder = new ContainerBuilder();
builder.RegisterType<DebugActivityLogger>().AsImplementedInterfaces().InstancePerDependency();
builder.Update(Conversation.Container);

Outcome

You will see the following result in the Debug text pane of the Visual Studio Output window when opening and running the sample solution.

A message received by the bot:

From:default-user - To:ii845fc9l02209hh6 - Message:Hello bot!

A the message sent to the user:

From:ii845fc9l02209hh6 - To:default-user - Message:You sent Hello bot! which was 10 characters

More Information

To get more information about how to get started in Bot Builder for .NET and Conversational history please review the following resources:

Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...