gpt4 book ai didi

c# - 结束对话 C# 机器人

转载 作者:行者123 更新时间:2023-11-30 20:29:19 24 4
gpt4 key购买 nike

我正在用 C# 构建一个 ChatBot,我希望在收到一些消息后对话停止,但我不知道该怎么做。我已经设置了消息限制,我希望在达到此限制后不再发送消息。有我的代码:

private int NombreDeMessages;

protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
{
var message = await item;
NombreDeMessages += 1;

if (message.Text != null && NombreDeMessages < 3)
{
await base.MessageReceived(context, item);
}
else
{
var reply = context.MakeMessage();
await context.PostAsync(reply);
context.Wait(this.MessageReceived);
}
}

我删除了 HeroCard 部分,因为它在这里没用。

我想要的是在末尾的 context.Wait 之后,添加对话结束,这样用户就不能再与聊天机器人交谈了。

最佳答案

谢谢,解决了我的问题。如果它可以帮助某人,我会发布代码!

private int NombreDeMessages;
protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
{
var message = await item;
NombreDeMessages += 1;
string code = EndOfConversationCodes.CompletedSuccessfully;
CancellationToken cancellationToken = default(CancellationToken);


if (message.Text != null && NombreDeMessages < 3)
{
await base.MessageReceived(context, item);

}
else if (message.Text != null && NombreDeMessages == 3)
{
AdaptiveCard card = new AdaptiveCard();
card.Body.Add(new TextBlock()
{
Text = "STOP FLOODING",
Weight = TextWeight.Bolder,
IsSubtle = true,
Wrap = true,
Size = TextSize.Large
});

card.Body.Add(new TextBlock()
{
Text = "You have reach the limit of queries",
IsSubtle = false,
Wrap = true,
Size = TextSize.Normal
});

card.Body.Add(new Image()
{
Url = "http://images.roadtrafficsigns.com/img/dp/lg/traffic-stop-sign.png",

HorizontalAlignment = HorizontalAlignment.Center,
Size = ImageSize.Stretch
});

Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
var flood = context.MakeMessage();
flood.Attachments.Add(attachment);

await context.PostAsync(flood);

}
else
{

var reply = context.MakeMessage();

reply.Type = ActivityTypes.EndOfConversation;
reply.AsEndOfConversationActivity().Code = code;

await context.PostAsync(reply, cancellationToken);

}

}

关于c# - 结束对话 C# 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46242016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com