microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Samples/Samples.Echo/Program.cs
57lines · 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.AddOpenApi(); |
| 18 | builder.Services.AddTransient<Controller>(); |
| 19 | builder.AddTeams().AddTeamsDevTools(); |
| 20 | |
| 21 | var app = builder.Build(); |
| 22 | |
| 23 | if (app.Environment.IsDevelopment()) |
| 24 | { |
| 25 | app.MapOpenApi(); |
| 26 | } |
| 27 | |
| 28 | app.UseHttpsRedirection(); |
| 29 | app.UseTeams(); |
| 30 | app.Run(); |
| 31 | } |
| 32 | |
| 33 | [TeamsController] |
| 34 | public class Controller |
| 35 | { |
| 36 | [Activity] |
| 37 | public async Task OnActivity(IContext<Activity> context, [Context] IContext.Next next) |
| 38 | { |
| 39 | context.Log.Info(context.AppId); |
| 40 | await next(); |
| 41 | } |
| 42 | |
| 43 | [Message] |
| 44 | public async Task OnMessage([Context] MessageActivity activity, [Context] IContext.Client client, [Context] Microsoft.Teams.Common.Logging.ILogger log) |
| 45 | { |
| 46 | log.Info("hit!"); |
| 47 | await client.Typing(); |
| 48 | await client.Send($"you said '{activity.Text}'"); |
| 49 | } |
| 50 | |
| 51 | [Microsoft.Teams.Apps.Events.Event("activity")] |
| 52 | public void OnEvent(IPlugin plugin, Microsoft.Teams.Apps.Events.Event @event) |
| 53 | { |
| 54 | Console.WriteLine("!!HIT!!"); |
| 55 | } |
| 56 | } |
| 57 | } |