microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/update-sample-to-blazor

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/samples/CompatProactive/ProactiveWorker.cs

34lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Bot.Builder;
5using Microsoft.Bot.Builder.Integration.AspNet.Core;
6using Microsoft.Bot.Schema;
7using Microsoft.Extensions.Hosting;
8using Microsoft.Extensions.Logging;
9using Microsoft.Teams.Apps.BotBuilder;
10
11namespace CompatProactive;
12
13internal 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