Microsoft Bot Framework DirectLine Can't Acces

2019-05-07 02:52发布

I am trying to use the Microsoft Bot Framework DirectLine API to read and add messages to existing conversations between other users and my bot. From what I've read I believe this should be possible when using the master-secret but it's just not working for me. I'm using a WebAPI to try and access two of my existing conversations (on Facebook & Skype) as follows:

    [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 :-)";
    }

It fails silently calling PostMessage() and fails with a 404 for the GetMessages(). I seem to be doing the right thing, the bot is live etc and works very well in Facebook & Skype separately from the DirectLine API. It only works if I create a new conversation using the DirectLine API, I can then access its messages and post new messages to it.

This question sort of helps but doesn't quite tell me what to do to fix it: Difficulty accessing messages in an existing conversation in Microsoft Bot Framework

Any help would be much appreciated.

Thanks

1条回答
贪生不怕死
2楼-- · 2019-05-07 03:11

For security reasons, you can't use DirectLine to spy on messages from another conversation. For the scenario you describe (escalating to a human) there a number of different ways to approach this. One is to have your bot broker conversations between the accounts (i.e. Facebook End User <-> Your Bot <-> Facebook Support Person). Each is talking to the bot, and the bot passes the message through to the other user. (Could also be Facebook User <-> Your Bot <-> Skype User) Your bot would have to store last n messages to provide context. Alternatively, I've seen folks build their own customer support chat interface using direct line that sits on the far side. Hope this helps

查看更多
登录 后发表回答