如何向新用户启动新的Dialog? (Microsoft Bot Builder - 主动消息)

时间:2017-10-05 16:27:20

标签: c# botframework

我正在使用官方示例https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-proactiveMessages

有3个单独的示例:一个用于发送简单消息,另外两个用于启动新对话框。

在第一个示例中,他们创建新活动,然后定义:接收者,发件人,消息文本等。但在第二和第三个例子中,他们都没有定义。他们只使用来自原始传入活动的数据,这实际上只是对原始邮件的延迟回复。这甚至不是真正的主动信息。但是如何从子对话中发送真正的主动消息?

所以我需要这些例子中混合的东西。

My ConversationStarter:

public class ConversationStarter
{
    public static async Task Resume()
    {
        string ServiceUrl = "http://localhost:50891";

        ChannelAccount BotAccount = new ChannelAccount(
            name: "Bot", 
            id: "default-bot"
        );

        ChannelAccount UserAccount = new ChannelAccount(
            name: "User", 
            id: "default-user"
        );

        ConnectorClient ForwardClient = new ConnectorClient(new Uri(ServiceUrl));
        ConversationResourceResponse ForwardConversation = ForwardClient.Conversations.CreateDirectConversation(BotAccount, UserAccount);
        IMessageActivity ForwardMessage = Activity.CreateMessageActivity();
        ForwardMessage.From = BotAccount;
        ForwardMessage.Recipient = UserAccount;
        ForwardMessage.Conversation = new ConversationAccount(id: ForwardConversation.Id);

        using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, ForwardMessage))
        {
            var botData = scope.Resolve<IBotData>();
            await botData.LoadAsync(CancellationToken.None);
            var task = scope.Resolve<IDialogTask>();

            //interrupt the stack
            var dialog =new ForwardDialog();
            task.Call(dialog.Void<object, IMessageActivity>(), null);

            await task.PollAsync(CancellationToken.None);

            //flush dialog stack
            await botData.FlushAsync(CancellationToken.None);           
        }
    }
}

我的对话框:

public class ForwardDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {
        await context.PostAsync("Hello, I'm ForwardDialog. I'm interrupting your conversation.");
        context.Wait(this.MessageReceivedAsync);
    }

    public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
    {
        await context.PostAsync("Great, back to the original conversation!");
        context.Done(String.Empty); //Finish this dialog
    }
}

context.PostAsync()这里返回一个错误:&#34; ReplyToId&#34;不能为空

但它不是对任何消息的回复,因此它不能有任何ReplyToId参数。

0 个答案:

没有答案