Building Echo Bot Agent in CSharp
Introduction
In this tutorial, you'll learn how to build a simple Echo Bot Agent using C# and the Microsoft 365 Agents SDK. An Echo Bot is a basic bot that replies to user messages with the same text, making it a great starting point for learning bot development.
Prerequisites
- .NET SDK 8.0+
- Visual Studio 2022 or VS Code
- A Microsoft 365 account (for testing)
- Basic knowledge of C#
1. Create a New C# Project
Open a terminal and run:
dotnet new console -n EchoBotAgent
cd EchoBotAgent
2. Add Microsoft 365 Agents SDK
Install the SDK NuGet package:
dotnet add package Microsoft.Teams.Agents.Sdk
3. Implement the Echo Bot Logic
Replace the contents of Program.cs
with the following code:
using Microsoft.Teams.Agents.Sdk;
var builder = Agent.CreateBuilder();
builder.OnMessage(async (context, message) =>
{
// Echo the received message
await context.SendActivityAsync($"You said: {message.Text}");
});
var agent = builder.Build();
await agent.RunAsync();
4. Run and Test Your Bot
Run your bot locally:
dotnet run
Test your bot using the Microsoft Teams client or Bot Framework Emulator. When you send a message, the bot will reply with the same text prefixed by "You said: ".
5. Next Steps
- Explore more features in the Microsoft 365 Agents SDK documentation
- Add authentication, adaptive cards, or integrate with other Microsoft 365 services
Happy coding! If you have questions, leave a comment below or check out the official docs for more advanced scenarios