c# - 无法让 Skype Bot 响应正确的事件

c# - Cannot get Skype Bot to respond to the proper event

我正在使用 Visual Studio 创建一个基于他们的 Bot Builder SDK 并使用 Skype 模拟器的 Skype 机器人。 (I am using this page) 我成功地让机器人连接并接收常规短信,并且它正确响应:

You sent [message] which was [length] characters

但是,我尝试添加一个事件以在添加用户时触发,它应该只发送 "Welcome"。

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{

        if (activity.Type == ActivityTypes.Message)
        {

            ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));

            int length = (activity.Text ?? string.Empty).Length;


            Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");

            await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
        }

        else
        {

            HandleSystemMessage(activity);

        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
}

private Activity HandleSystemMessage(Activity message)
{
    //The other if statements are the rest of the activity types
    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

        Activity reply = message.CreateReply("Welcome");

    }

这是我目前的代码。我尝试在第 17 行的 else 语句中添加相同的 Connectorawait 行,但这只会让机器人响应

You sent which was 0 characters

如果需要任何其他信息来解决此问题,我很乐意提供。

感谢任何帮助!

编辑:我目前拥有的代码没有任何响应。它看到 ConversationUpdate 事件但不对其执行任何操作

我从未使用过 Skype SDK,但我想如果您使用得当,它会看起来像这样:

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
    Activity reply = null;

    if (activity.Type == ActivityTypes.Message)
    {
        int length = (activity.Text ?? string.Empty).Length;
        reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
    }
    else if (activity.Type == ActivityTypes.ConversationUpdate)
    {
        reply = message.CreateReply("Welcome");
    }

    if (reply != null) 
    {
        await connector.Conversations.SendToConversationAsync((Activity)reply);
    }
}

我建议您学习 C# 教程,然后阅读 skype 文档? https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-connector


如果你看一下我发布的文档 link,上面的方法可能仍然不起作用,如果使用 CreateDirectConversationAsync 方法尚不存在,你可能需要开始对话。