我正在尝试使用 Microsoft.Bot.Connector.DirectLine .NET 客户端连接到我的 Direct Line 通道。我的客户端应用程序将同时打开许多对话(例如 1000 多个)。
我想要做的是有效地创建一个 Direct Line 客户端对象,它可以接收我所有对话的消息,并且每个对话没有一个客户端。
问题是,要创建一个新的对话,我需要创建一个新的客户端,我认为这最终会耗尽大量的套接字。有谁知道我是否可以创建一个连接然后监听多个对话?
谢谢
static async Task Main(string[] args)
{
Console.WriteLine("What is your name:");
var UserName = Console.ReadLine();
var tokenClient = new DirectLineClient(
new Uri(endpoint),
new DirectLineClientCredentials(secret));
var conversation = await tokenClient.Tokens.GenerateTokenForNewConversationAsync();
var client = new DirectLineClient(
new Uri(endpoint),
new DirectLineClientCredentials(conversation.Token));
await client.StreamingConversations.ConnectAsync(
conversation.ConversationId,
ReceiveActivities);
var startConversation = await client.StreamingConversations.StartConversationAsync();
var from = new ChannelAccount() { Id = startConversation.ConversationId, Name = UserName };
var message = Console.ReadLine();
while (message != "end")
{
try
{
var response = await client.StreamingConversations.PostActivityAsync(
startConversation.ConversationId,
new Activity()
{
Type = "message",
Text = message,
From = from,
ChannelData = new Common.ChannelData() { FromNumber = "+17081234567"}
});
}
catch (OperationException ex)
{
Console.WriteLine(
$"OperationException when calling PostActivityAsync: ({ex.StatusCode})");
}
message = Console.ReadLine();
}
Console.ReadLine();
}
四季花海
相关分类