microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
aamirj/ConversationalClient

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/scenarios/proactive.cs

43lines · modecode

1#!/usr/bin/dotnet run
2
3#:sdk Microsoft.NET.Sdk.Worker
4
5#:project ../../src/Microsoft.Bot.Core/Microsoft.Bot.Core.csproj
6
7using Microsoft.Bot.Core.Hosting;
8using Microsoft.Bot.Core;
9using Microsoft.Bot.Core.Schema;
10
11var builder = Host.CreateApplicationBuilder(args);
12builder.Services.AddBotApplicationClients();
13builder.Services.AddHostedService<Worker>();
14
15var host = builder.Build();
16host.Run();
17
18public class Worker(ConversationClient conversationClient, ILogger<Worker> logger) : BackgroundService
19{
20 const string conversationId = "a:17vxw6pGQOb3Zfh8acXT8m_PqHycYpaFgzu2mFMUfkT-h0UskMctq5ZPPc7FIQxn2bx7rBSm5yE_HeUXsCcKZBrv77RgorB3_1_pAdvMhi39ClxQgawzyQ9GBFkdiwOxT";
21
22 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
23 {
24 while (!stoppingToken.IsCancellationRequested)
25 {
26 if (logger.IsEnabled(LogLevel.Information))
27 {
28 CoreActivity proactiveMessage = new()
29 {
30 Text = $"Proactive hello at {DateTimeOffset.Now}",
31 ServiceUrl = new Uri("https://smba.trafficmanager.net/amer/56653e9d-2158-46ee-90d7-675c39642038/"),
32 Conversation = new()
33 {
34 Id = conversationId
35 }
36 };
37 var aid = await conversationClient.SendActivityAsync(proactiveMessage, stoppingToken);
38 logger.LogInformation($"Activity {aid} sent");
39 }
40 await Task.Delay(1000, stoppingToken);
41 }
42 }
43}