无法让 Skype 机器人响应正确的事件



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

您发送的 [消息] 是 [长度] 字符

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

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行,但这只会使机器人响应

您发送了 0 个字符

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

任何帮助不胜感激!

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

我从未使用过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://learn.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-connector


以上可能仍然不起作用,如果您查看我发布的文档链接,您可能需要使用 CreateDirectConversationAsync 方法开始对话(如果尚不存在(。

相关内容

  • 没有找到相关文章

最新更新