microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/CompatProactive/ProactiveWorker.cs
34lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Bot.Builder; |
| 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; |
| 6 | using Microsoft.Bot.Schema; |
| 7 | using Microsoft.Extensions.Hosting; |
| 8 | using Microsoft.Extensions.Logging; |
| 9 | using Microsoft.Teams.Apps.BotBuilder; |
| 10 | |
| 11 | namespace CompatProactive; |
| 12 | |
| 13 | internal class ProactiveWorker(IBotFrameworkHttpAdapter compatAdapter, ILogger<ProactiveWorker> logger) : BackgroundService |
| 14 | { |
| 15 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) |
| 16 | { |
| 17 | ConversationReference conversationReference = new() |
| 18 | { |
| 19 | ServiceUrl = "https://smba.trafficmanager.net/teams/", |
| 20 | Conversation = new() { Id = "19:ad37a1f8af5549e3b81edf249fe5cb1b@thread.tacv2" }, |
| 21 | }; |
| 22 | |
| 23 | await ((TeamsBotFrameworkHttpAdapter)compatAdapter).ContinueConversationAsync("", conversationReference, callback, stoppingToken); |
| 24 | logger.LogInformation("Proactive message sent"); |
| 25 | } |
| 26 | |
| 27 | private async Task callback(ITurnContext turnContext, CancellationToken cancellationToken) |
| 28 | { |
| 29 | await turnContext.SendActivitiesAsync(new Activity[] |
| 30 | { |
| 31 | MessageFactory.Text($"Proactive with Compat Layer {DateTimeOffset.Now}") |
| 32 | }, cancellationToken); |
| 33 | } |
| 34 | } |
| 35 | |