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.Annotations; |
| 4 | using Microsoft.Teams.Apps.Extensions; |
| 5 | using Microsoft.Teams.Apps.Routing; |
| 6 | using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions; |
| 7 | using Microsoft.Teams.Plugins.AspNetCore.Extensions; |
| 8 | |
| 9 | namespace Samples.Echo; |
| 10 | |
| 11 | public static partial class Program |
| 12 | { |
| 13 | public static void Main(string[] args) |
| 14 | { |
| 15 | var builder = WebApplication.CreateBuilder(args); |
| 16 | builder.Services.AddOpenApi(); |
| 17 | builder.Services.AddTransient<Controller>(); |
| 18 | builder.AddTeams().AddTeamsDevTools(); |
| 19 | |
| 20 | var app = builder.Build(); |
| 21 | |
| 22 | if (app.Environment.IsDevelopment()) |
| 23 | { |
| 24 | app.MapOpenApi(); |
| 25 | } |
| 26 | |
| 27 | app.UseHttpsRedirection(); |
| 28 | app.UseTeams(); |
| 29 | app.Run(); |
| 30 | } |
| 31 | |
| 32 | [ActivityController] |
| 33 | public class Controller |
| 34 | { |
| 35 | [Activity] |
| 36 | public async Task OnActivity(IContext<Activity> context, [Context] IContext.Next next) |
| 37 | { |
| 38 | context.Log.Info(context.AppId); |
| 39 | await next(); |
| 40 | } |
| 41 | |
| 42 | [Message] |
| 43 | public async Task OnMessage([Context] MessageActivity activity, [Context] IContext.Client client, [Context] Microsoft.Teams.Common.Logging.ILogger log) |
| 44 | { |
| 45 | log.Info("hit!"); |
| 46 | await client.Typing(); |
| 47 | await client.Send($"you said '{activity.Text}'"); |
| 48 | } |
| 49 | } |
| 50 | } |