Bots 如何处理Context.Done(R值)

Bots 如何处理Context.Done(R值),bots,botframework,chatbot,Bots,Botframework,Chatbot,我有一个msbot聊天对话框,希望具有以下行为: user -> get me some info about GARY bot -> which gary, (prompt: choice options) user -> gary peskett bot -> sure, (hero card with gary's contact details) 我有这个密码 public class CustomerRepository { private IList

我有一个msbot聊天对话框,希望具有以下行为:

user -> get me some info about GARY
bot -> which gary, (prompt: choice options)
user -> gary peskett
bot -> sure, (hero card with gary's contact details)
我有这个密码

public class CustomerRepository
{
    private IList<Customer> _customerList = new List<Customer>
    {
        new Customer
        {
            Name = "Gary Peskett"
        },
        new Customer
        {
            Name = "Gary Richards"
        },
        new Customer
        {
            Name = "Barry White"
        }
    };

    public async Task<IEnumerable<Customer>> GetAll()
    {
        // usually calls a database (which is why async is on this method)
        return _customerList;
    }
}

public class XDialog : IDialog
{
    private readonly IIntent _intent;
    private readonly CustomerRepository _customerRepository;

    public XDialog(IIntent intent, CustomerRepository customerRepository)
    {
        // An intent is decided before this point
        _intent = intent;
        _customerRepository = customerRepository;
    }

    public async Task StartAsync(IDialogContext context)
    {
        // // An intent can provide parameters
        string name = _intent.Parameters["Name"] as string;
        IEnumerable<Customer> customers = await _customerRepository.GetAll();
        IList<Customer> limitedList = customers.Where(x => x.Name.Contains(name)).ToList();

        if (limitedList.Any())
        {
            if (limitedList.Count > 1)
            {
                PromptDialog.Choice(context, LimitListAgain, limitedList,
                    "Can you specify which customer you wanted?");
            }
            else
            {
                Customer customer = limitedList.FirstOrDefault();
                Finish(context, customer);
            }
        }
        else
        {
            context.Done("No customers have been found");
        }
    }

    private static async Task LimitListAgain(IDialogContext context, IAwaitable<Customer> result)
    {
        Customer customer = await result;
        Finish(context, customer);
    }

    private static void Finish(IDialogContext context, Customer customer)
    {
        HeroCard heroCard = new HeroCard
        {
            Title = customer?.Name
        };

        context.Done(heroCard);
    }
}
有谁能帮我解释一下使用context.Done(R值)的更好方法,或者帮我返回一张英雄卡来结束对话

正在使用调用该对话框

Chain.PostToChain()
    .Select(msg => Task.Run(() => _intentionService.Get(msg.ChannelId, msg.From.Id, msg.Text)).Result)
    .Select(intent => _actionDialogFactory.Create(intent)) // returns IDialog based on intent
    .Unwrap()
    .PostToUser();

我认为问题是使用
链的副作用

您可能知道,
context.Done
不会向用户发回任何内容,它只会使用提供的值结束当前对话框

“向用户发布”实际上发生在
链末端的
.PostToUser()
中。现在,通过查看,我意识到在游戏结束时,它正在执行
context.PostAsync
item.ToString()
,在本例中,它是
context.Done
中提供的有效负载。看


一个选项(我没有测试过),可以使用
.Do
而不是
.PostToUser()
,手动执行所做的操作,最后执行一个context.PostAsync(),方法是创建一个新的
IMessageActivity
并将
HeroCard
作为附件添加。

此帖子显示它们返回context.Done(null);我想知道这是否是最好的做法:谁在调用XDialog?它是从Chain.PostToChain()调用的。我已经用我使用的代码更新了这个问题。。我懂了。我会发布一个回复,谢谢你。根据你的回答,我决定不再把谈话联系起来。我发现了这个,我现在用它来管理我的对话框流
Chain.PostToChain()
    .Select(msg => Task.Run(() => _intentionService.Get(msg.ChannelId, msg.From.Id, msg.Text)).Result)
    .Select(intent => _actionDialogFactory.Create(intent)) // returns IDialog based on intent
    .Unwrap()
    .PostToUser();