Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在bot framework v4中将对话框设置为欢迎消息_C#_Botframework - Fatal编程技术网

C# 如何在bot framework v4中将对话框设置为欢迎消息

C# 如何在bot framework v4中将对话框设置为欢迎消息,c#,botframework,C#,Botframework,欢迎信息很酷,但你不一定需要它们。在我的例子中,我有多个对话框,其中一个main对话框被认为会触发其他对话框 我遇到的问题是(使用bot emulator),用户必须在触发主对话框之前键入一些内容 我们不能在添加成员时触发对话框吗? 感谢您通读:)。以下是我的全班: 此bot代码源自richcardsbot示例: 使用System.Collections.Generic; 使用系统线程; 使用System.Threading.Tasks; 使用HackBot.Dialogs; 使用Microso

欢迎信息很酷,但你不一定需要它们。在我的例子中,我有多个对话框,其中一个main对话框被认为会触发其他对话框

我遇到的问题是(使用bot emulator),用户必须在触发主对话框之前键入一些内容

我们不能在添加成员时触发对话框吗? 感谢您通读:)。以下是我的全班:

此bot代码源自richcardsbot示例:

使用System.Collections.Generic;
使用系统线程;
使用System.Threading.Tasks;
使用HackBot.Dialogs;
使用Microsoft.Bot.Builder;
使用Microsoft.Bot.Schema;
使用Microsoft.BotBuilderSamples.Bots;
使用Microsoft.Extensions.Logging;
名称空间HackBot.Bots
{
公共类RichCardsBot:DialogBot
{
公共RichCardsBot(会话状态会话状态、用户状态用户状态、主对话框、ILogger记录器)
:base(会话状态、用户状态、对话框、记录器)
{
}
MemberSaddedAsync上的受保护重写异步任务(IList membersAdded、iTurContext turnContext、CancellationToken CancellationToken)
{
foreach(membersAdded中的var成员)
{
var attachments=新列表();
//问候不是此邮件目标(收件人)的任何人。
//要了解有关自适应卡的更多信息,请参阅https://aka.ms/msbot-adaptivecards 更多细节。
if(member.Id!=turnContext.Activity.Recipient.Id)
{
var reply=MessageFactory.Attachment(附件);
//var reply=MessageFactory.Text(“以下航班已取消。”
//+“您已经预订了目的地的酒店。”
//+“您想对预订做些什么?”;
reply.Attachments.Add(Cards.FirstCard().ToAttachment());
等待turnContext.SendActivityAsync(回复、取消令牌);
}
}
}
}
}

检查会话更新活动:

 // innderDc is the **DialogContext**
 var activity = innerDc.Context.Activity;

// Check activity type
switch (activity.Type) {
 case ActivityTypes.ConversationUpdate:
     {
         if (activity.MembersAdded ? .Count > 0) {
             foreach(var member in activity.MembersAdded) {

               // do logic
                await innerDc.BeginDialogAsync(nameof("yourDialog"));

             }
         }
         break;
     }
更新: 请尝试以下操作:

 protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
    {
        foreach (var member in membersAdded)
        {
            // Greet anyone that was not the target (recipient) of this message.
            // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
            if (member.Id != turnContext.Activity.Recipient.Id)
            {
                //var reply = MessageFactory.Text("Welcome to CardBot."
                //    + " This bot will show you different types of Rich Cards."
                //    + " Please type anything to get started.");

                //await turnContext.SendActivityAsync(reply, cancellationToken);
                await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);


            }
        }
    }
受保护的覆盖MemberSaddedAsync上的异步任务(IList membersAdded、iTunesContext turnContext、CancellationToken CancellationToken)
{
foreach(membersAdded中的var成员)
{
//问候不是此邮件目标(收件人)的任何人。
//要了解有关自适应卡的更多信息,请参阅https://aka.ms/msbot-adaptivecards 更多细节。
if(member.Id!=turnContext.Activity.Recipient.Id)
{
//var reply=MessageFactory.Text(“欢迎使用CardBot。”
//+“此机器人将向您显示不同类型的富卡。”
//+“请键入任何要开始的内容。”);
//等待turnContext.SendActivityAsync(回复、取消令牌);
wait Dialog.RunAsync(turnContext,ConversationState.CreateProperty(nameof(DialogState)),cancellationToken);
}
}
}

Hi Marc,innerDc是框架的一部分,还是我必须声明它?如果是,怎么做。一旦我看到一个成员被添加!如何启动对话?在本例中,是DialogContext,请检查我的更新答案以了解如何启动新对话非常感谢Marc,明天将在office中试用并将其标记为答案。再次感谢你。嗨,Marc,如果innerDc是对话框上下文的一个元素,那么我该如何使用它?正如您在我的问题中的onmembersaddedasync代码中所看到的,它没有对话框上下文作为输入参数。我更新了我的答案,尝试一下,并告诉我它是否有效!我在代码示例中添加了以下内容:wait Dialog.RunAsync(turnContext,ConversationState.CreateProperty(nameof(DialogState)),cancellationToken);
 protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
    {
        foreach (var member in membersAdded)
        {
            // Greet anyone that was not the target (recipient) of this message.
            // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
            if (member.Id != turnContext.Activity.Recipient.Id)
            {
                //var reply = MessageFactory.Text("Welcome to CardBot."
                //    + " This bot will show you different types of Rich Cards."
                //    + " Please type anything to get started.");

                //await turnContext.SendActivityAsync(reply, cancellationToken);
                await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);


            }
        }
    }