Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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# Azure Bot模板-Bot应用程序_C#_Azure_Azure Bot Service - Fatal编程技术网

C# Azure Bot模板-Bot应用程序

C# Azure Bot模板-Bot应用程序,c#,azure,azure-bot-service,C#,Azure,Azure Bot Service,我下载了Azure机器人模板。现在,我的机器人正在工作,并回复了我所说的话,以及在我使用机器人框架模拟器运行它时它有多少个字符。但我想让我的机器人开始对话。我该怎么做?我想让机器人先打招呼,不管用户输入是什么。“post async”方法仅在收到用户输入后将消息打印到聊天室 代码: 命名空间应用程序1.对话框 { [可序列化] 公共类RootDialog:IDialog { 公共任务StartSync(IDialogContext上下文) { Microsoft.Bot.Builder.Dial

我下载了Azure机器人模板。现在,我的机器人正在工作,并回复了我所说的话,以及在我使用机器人框架模拟器运行它时它有多少个字符。但我想让我的机器人开始对话。我该怎么做?我想让机器人先打招呼,不管用户输入是什么。“post async”方法仅在收到用户输入后将消息打印到聊天室

代码:

命名空间应用程序1.对话框
{
[可序列化]
公共类RootDialog:IDialog
{
公共任务StartSync(IDialogContext上下文)
{
Microsoft.Bot.Builder.Dialogs.Internals.IBotToUser($“嗨!请键入一个公众人物的名字!”);//编译时错误
context.PostAsync($“Hello user”);//仅在用户输入后打印“Hello user”
Wait(MessageReceivedAsync);
返回Task.CompletedTask;
}
专用异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
var活动=等待作为活动的结果;
//算点东西让我们回去
int length=(activity.Text??string.Empty).length;
//将我们的回复返回给用户
wait context.PostAsync($“您发送的{activity.Text}为{length}个字符”);
Wait(MessageReceivedAsync);
}
}
}
有什么帮助吗?如果不在这里,那么去哪里询问???? 求你了

多谢各位


Hadas

您应该将欢迎消息添加到消息控制器中,而不是根对话框中

如果您的bot接收到一个conversationUpdate活动,表明某个用户已加入该对话,您可以选择让它通过向该用户发送欢迎消息进行响应

演示代码

if (message.Type == ActivityTypes.ConversationUpdate)
    {
        // Handle conversation state changes, like members being added and removed
        // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
        // Not available in all channels

        // Note: Add introduction here:
        IConversationUpdateActivity update = message;
        var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
        if (update.MembersAdded != null && update.MembersAdded.Any())
        {
            foreach (var newMember in update.MembersAdded)
            {
                if (newMember.Id != message.Recipient.Id)
                {
                    var reply = message.CreateReply();
                    reply.Text = $"Welcome {newMember.Name}!";
                    client.Conversations.ReplyToActivityAsync(reply);
                }
            }
        }
    }
if (message.Type == ActivityTypes.ConversationUpdate)
    {
        // Handle conversation state changes, like members being added and removed
        // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
        // Not available in all channels

        // Note: Add introduction here:
        IConversationUpdateActivity update = message;
        var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
        if (update.MembersAdded != null && update.MembersAdded.Any())
        {
            foreach (var newMember in update.MembersAdded)
            {
                if (newMember.Id != message.Recipient.Id)
                {
                    var reply = message.CreateReply();
                    reply.Text = $"Welcome {newMember.Name}!";
                    client.Conversations.ReplyToActivityAsync(reply);
                }
            }
        }
    }