FormFlow'帮助'命令和Scorables / GlobalMessage处理程序'帮助'命令

时间:2017-05-25 03:46:18

标签: c# botframework formflow

当对话在FormFlow中并且用户类型为“帮助”时,目前Scorables全局消息处理程序'帮助'掌控。我想要FormFlows'帮助'在内部表单和Scorables'帮助'只有当它在其他对话中。有没有办法实现这个目标?

protected override async Task PostAsync(IActivity item, string state, 
CancellationToken token) 
{ 
     var message = item as IMessageActivity; 

     if (message != null) 
     { 
          var helpDialog = new HelpDialog(); 
          var interruption = helpDialog.Void<object, IMessageActivity>(); 
          this.task.Call(interruption, null); 
          await this.task.PollAsync(token); 
     } 
}


public class HelpDialog : IDialog<object>
{
    public async Task StartAsync(IDialogContext context)
    {

        var userHelpMessage = "You have reached Help Section.\n"
                               + StaticMessages.HelpMessage
                               + "\n Your previous conversation is active 
         and you can return to prior dialog by typing 'Back' or 'Return'.";

        await context.PostAsync(userHelpMessage);

        context.Wait(this.MessageReceived);
    }

    private async Task MessageReceived(IDialogContext context, 
    IAwaitable<IMessageActivity> result)
    {
        var message = await result;

        var incomingMessage = message.Text.ToLowerInvariant();

        if ((incomingMessage != null) && (incomingMessage.Trim().Length > 0))
        {
            context.Done<object>(null);
        }
        else if (incomingMessage.Equals("return", StringComparison.InvariantCultureIgnoreCase))
        {
            context.Done<object>(null);
        }
        else if (incomingMessage.Equals("back", StringComparison.InvariantCultureIgnoreCase))
        {
            context.Done<object>(null);
        }
        else
        {
            context.Fail(new Exception("Message was not a string or was an empty string."));
        }
    }
}

[序列化]     公共类BuildARCollRaiseDisputeForm     {

    //Custom Form Builder for custom yes options
    BuildCustomForm customForm = new BuildCustomForm();
    ARCollRaiseDisputeQuery disputeQuery = new ARCollRaiseDisputeQuery();

    public IForm<ARCollRaiseDisputeQuery> BuildARCollRaiseDisputeForms()
    {

        IForm<ARCollRaiseDisputeQuery> form;

        OnCompletionAsyncDelegate<ARCollRaiseDisputeQuery> processARCollRaiseDisputeSave = async (context, state) =>
        {
            var message = $"Saving your dispute reason against this Invoice. ";

            await context.PostAsync(message);
        };

        var builder = customForm.CreateCustomForm<ARCollRaiseDisputeQuery>()

            .Field(nameof(disputeQuery.BODISPUTEREASONOPTIONS),
                    validate: async(state, value) => await ValidatePymtDisputeReason(state, value)
                   )

            .Field(nameof(disputeQuery.DisputeItemReasons),
                    active: state =>  ActiveDisputeItemReason(state)
                    )

            .Field(nameof(disputeQuery.DisputeShipmentReasons),
                    active: ActiveDisputeShipmentReason
                    )

            .Field(nameof(disputeQuery.DisputeInvoicingReasons),
                    active: ActiveDisputeInvoicingReason
                    )

            .Field(new FieldReflector<ARCollRaiseDisputeQuery>(nameof(disputeQuery.OtherPymtDisputeReason))
                .SetActive(state => ActiveOtherPymtDisputeReason(state))
                .SetPrompt(new PromptAttribute("Do you have any custom message to my team for non-payment for this Invoice? If yes, then please type and send as single message."))
                .SetValidate(async (state, value) => await ValidateOtherPymtDisputeReason(state, value))
                )

            .AddRemainingFields()
            .Confirm("I have the following reasons for raising dispute against this Invoice and I am ready to submit your message. {BODISPUTEREASONOPTIONS}  Shall I go ahead? ")
            .OnCompletion(processARCollRaiseDisputeSave)
            .Message("Thank you");

        form = builder.Build();

        return form;



    }

}

0 个答案:

没有答案