microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Samples/Samples.Echo/Program.cs
50lines · modecode
| 1 | using Microsoft.Teams.Api.Activities; |
| 2 | using Microsoft.Teams.Apps; |
| 3 | using Microsoft.Teams.Apps.Activities; |
| 4 | using Microsoft.Teams.Apps.Annotations; |
| 5 | using Microsoft.Teams.Apps.Extensions; |
| 6 | using Microsoft.Teams.Apps.Plugins; |
| 7 | using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions; |
| 8 | using Microsoft.Teams.Plugins.AspNetCore.Extensions; |
| 9 | |
| 10 | namespace Samples.Echo; |
| 11 | |
| 12 | public static partial class Program |
| 13 | { |
| 14 | public static void Main(string[] args) |
| 15 | { |
| 16 | var builder = WebApplication.CreateBuilder(args); |
| 17 | builder.Services.AddTransient<Controller>(); |
| 18 | builder.AddTeams().AddTeamsDevTools(); |
| 19 | |
| 20 | var app = builder.Build(); |
| 21 | app.UseHttpsRedirection(); |
| 22 | app.UseTeams(); |
| 23 | app.Run(); |
| 24 | } |
| 25 | |
| 26 | [TeamsController] |
| 27 | public class Controller(ILogger<Controller> logger) |
| 28 | { |
| 29 | [Activity] |
| 30 | public async Task OnActivity(IContext<Activity> context, [Context] IContext.Next next) |
| 31 | { |
| 32 | logger.LogInformation(context.AppId); |
| 33 | await next(); |
| 34 | } |
| 35 | |
| 36 | [Message] |
| 37 | public async Task OnMessage([Context] MessageActivity activity, [Context] IContext.Client client) |
| 38 | { |
| 39 | logger.LogInformation("hit!"); |
| 40 | await client.Typing(); |
| 41 | await client.Send($"you said '{activity.Text}'"); |
| 42 | } |
| 43 | |
| 44 | [Microsoft.Teams.Apps.Events.Event("activity")] |
| 45 | public void OnEvent(IPlugin plugin, Microsoft.Teams.Apps.Events.Event @event) |
| 46 | { |
| 47 | Console.WriteLine("!!HIT!!"); |
| 48 | } |
| 49 | } |
| 50 | } |