4
votes

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
For security reasons, you can't use DirectLine to spy on messages from another conversation. Can you tell me a bit more about the use case scenario you are trying to solve? DirectLine does not seem like the right approach.Lars
I'm trying to handle situations where a bot can't answer / help the user and I want to be able to include a human (e.g. from a helpdesk) to assist. I was trying to show the human the context of the discussion by fetching e.g. the most recent 10 chat messages so the user to human interaction doesn't have to start from scratch. This principle of including a human and accepting my bot can't do everything seems sensible to me so any suggestions would be great. Adding a human to the existing conversation to create a group chat would be ideal but I'm finding that difficult too.Stu Price
Yes, this is a common scenario and 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.Lars
Thanks Lars, it's good to get some clear direction on this. I have already prototyped a solution that routes messages from Facebook to Skype which is pretty cool. In terms of brokering in a real app though, is there a 'best way' to store the links between the two conversations or should I maintain them in my own data store? Do you have any example code relating to brokering to save me from having to start from scratch? Last question, is this best asked as a new SO question on brokering? Thanks, StuStu Price
Note something BF supports locally as of yet, so maintaining in your own data store is the way to go.Lars

1 Answers

1
votes

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