微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – Microsoft Bot Framework DirectLine无法访问对话

我正在尝试使用Microsoft Bot Framework DirectLine API来读取和添加消息到其他用户和我的机器人之间的现有对话.从我所读到的内容来看,我相信在使用主秘密时这应该是可能的,但它不适合我.我正在使用WebAPI尝试访问我现有的两个对话(在Facebook和Skype上),如下所示:

[HttpPost]
    [Route("remind")]
    public string Remind()
    {
        var secret = System.Configuration.ConfigurationManager.AppSettings["secret"];

        var uri = new Uri("https://directline.botframework.com/");
        var creds = new DirectLineClientCredentials(secret);

        DirectLineClient client = new DirectLineClient(uri,creds);
        Conversations convs = new Conversations(client);

        var conversationIDs = new string[] { "0000000000000000-0000000000000000","00:0123456789abcdefghijklmnopqrstuvwxyz0123456789-A-_0123456798ABCDEF" }; // Existing Facebook & Skype conversations

        // Send a message to each conversation:
        foreach (var conversationID in conversationIDs)
        {
            Message message = new Message(conversationId: conversationID,fromProperty: "My Bot",text: "hey dude,remember that thing!");
            Console.WriteLine(message.Text);
            convs.PostMessage(conversationID,message); // FAILS - This executes but doesn't do anything.
        }

        // Try reading the messages from a conversation (just to test if it's working):
        string waterMark = null;
        var set = convs.GetMessages(conversationIDs[0],waterMark); // FAILS - This fails with a 404 not found.
        waterMark = set.Watermark;

        return "Done :-)";
    }

它无法以静方式调用PostMessage(),并因GetMessages()而失败.我似乎正在做正确的事情,机器人是现场等在Facebook和& Skype与DirectLine API分开.它只有在我使用DirectLine API创建新会话时才有效,然后我可以访问其消息并向其发布新消息.

这个问题有点帮助,但并不能告诉我如何解决它:@H_404_14@Difficulty accessing messages in an existing conversation in Microsoft Bot Framework

任何帮助将非常感激.

谢谢

解决方法

出于安全原因,您无法使用DirectLine监视来自其他对话的邮件.对于您描述的场景(升级为人类),有许多不同的方法可以解决这个问题.一种是在账户之间进行机器人经纪人对话(即Facebook最终用户< - >您的Bot< - > Facebook支持人员).每个人都在与机器人交谈,机器人将消息传递给其他用户. (也可能是Facebook用户< - >您的Bot< - > Skype用户)您的机器人必须存储最后n条消息以提供上下文.或者,我已经看到人们使用位于远端的直线构建他们自己的客户支持聊天界面.希望这可以帮助

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐