DEV Community

Cover image for Introduction to Chatbot (Bot) Framework SDK in .NET
Duc Nguyen Thanh
Duc Nguyen Thanh

Posted on

Introduction to Chatbot (Bot) Framework SDK in .NET

Hello,
I'm Duke and I come back today to show you how to create a chatbox in .NET by Bot Framework SDK

Microsoft created the robust Bot Framework SDK for.NET to make it easier to create conversational AI apps, or "bots," utilizing the.NET framework. This SDK makes it simple for developers to build bots that communicate with users through a variety of platforms, such as Facebook Messenger, Slack, and Microsoft Teams, increasing user engagement and automating a range of tasks.

Bot

Bot framework


Getting Started with Bot Framework SDK in .NET

1. Installation:
Install the Bot Framework SDK package via NuGet after creating a.NET project. For ASP.NET Core integration, Microsoft.Bot.Builder and Microsoft.Bot.Builder.Integration.AspNet.Core are the primary packages needed.

dotnet add package Microsoft.Bot.Builder
dotnet add package Microsoft.Bot.Builder.Integration.AspNet.Core
Enter fullscreen mode Exit fullscreen mode

2. Basic Bot Structure:
The SDK has a simple structure for creating bots. Starting with a bot class that inherits from ActivityHandler, you can handle typical activities with methods like OnMessageActivityAsync and OnMembersAddedAsync.

3. Dialog Management:
Create dialogs to manage conversational flow. Use Waterfall dialogs for linear conversations and adaptive dialogs for more complex interactions, allowing for conditional responses based on user inputs.

4. Testing and Debugging: For local bot testing, Microsoft offers a desktop program called the Bot Framework Emulator. You may log actions, examine messages, and debug in real time with the emulator.

Bot Framework Emulator


Use Case

Open Source AI Challenge with pgai and Ollama

For the "Open Source AI Challenge with pgai and Ollama" challenge, I made a chatbox to respond to inquiries concerning insurance or finance-related subjects.

Tools Used

To accomplish its responsive, high-performance AI capabilities, this project makes use of a number of potent tools and technologies:
- Database: PostgreSQL server, provided by Timescale, serves as the foundational database for vector storage and querying.
- Programming Language: Built using .NET 8 for seamless and robust server-side execution.
- Model: Utilized Ollama’s nomic-embed-text model to generate precise embeddings and support AI Bot’s semantic understanding.
- Embedding API: Ollama’s embedding API enabled enhanced text matching and contextual understanding.
- Algorithm: Cosine Similarity was implemented to measure and match query relevance.
- Cache: Optimized with Memory Cache for faster responses and reduced computation time.
- AI Extension: pgvector was instrumental in managing and querying vector data.

Demo: https://www.youtube.com/watch?v=MTUj1jAPEdk&feature=youtu.be
Repository: ngtduc693-AI-Hackathon-2024-pgai

Thank you for reading, and happy coding!

Top comments (5)

Collapse
 
ngtduc693 profile image
Duc Nguyen Thanh

Let me know if you have any questions

Collapse
 
dsaga profile image
Dusan Petkovic

Great one, do you have some resources on how to integrate with Facebook Messenger, Slack, and Microsoft Teams ? would like to read more on that!

Collapse
 
ngtduc693 profile image
Duc Nguyen Thanh

I will guide in the next post about integrating other platforms like Facebook, the trick is to create Facebook App and webhook for it

Collapse
 
dsaga profile image
Dusan Petkovic

Also is it easy to get it running locally?

Collapse
 
ngtduc693 profile image
Duc Nguyen Thanh

@dsaga it's easy to run on locally, just run the server through the dotnet run command