microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

[Direct Line API - V1.0] Can not get the bot replies with /api/conversations/{conversationId}/messages #672

Closed hailiang-wang closed 8 years ago

hailiang-wang commented 8 years ago

hi, folks

Get a problem when trying to use Direct Line API - V1.0. The documentation is here.

commit id: bdc387474c02cd9e8926d34be6bc94e8d4bc1a5a

Background

After running a node.js application locally using ngrok and connect to my bot in MS Bot Framework. It works with the Skype Channel.

image

The nodejs application is described with this gist.

Then, I added the Direct line Channel.

image

Next, I am trying to use the Direct line REST API V1.

Create Requests with Direct line REST API

Get a Token with Secret

get the secret from dashboard

image

Create a conversation with Token

image

Post message in a conversation

image

Get messages for getting response from bot

image

Here, after many times testing, the messsages are all created with the post requests I made, but in the documentation, the bot should return the responses against the request.

So, is it a bug? or I make any mistakes.

hailiang-wang commented 8 years ago

By the way, in the docs, it mentions

The client may retrieve messages sent by the bot by calling GET on 
https://directline.botframework.com/api/messages/conversationId. 

But in the API details, I could not find this API.

hailiang-wang commented 8 years ago

More information

Request

POST /api/conversations/{conversationId}/messages

body

{
  "text": "hi2"
}

Session message in Botbuilder

{
  "type": "message",
  "timestamp": "2016-07-13T09:21:51.9826309Z",
  "text": "hi2",
  "address": {
    "id": "EVqX5pcwuOL",
    "channelId": "directline",
    "user": {
      "id": "HamZkcXSe2i",
      "name": "HamZkcXSe2i"
    },
    "conversation": {
      "id": "2GMLLqru0N3"
    },
    "bot": {
      "id": "dagama_rebecca",
      "name": "Rebecca"
    },
    "serviceUrl": "https://directline.botframework.com",
    "useAuth": true
  },
  "source": "directline",
  "attachments": [],
  "entities": [],
  "agent": "botbuilder",
  "user": {
    "id": "HamZkcXSe2i",
    "name": "HamZkcXSe2i"
  }
}

Error message in Botbuilder

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: Request to 'https://directline.botframework.com/v3/conversations/2GMLLqru0N3/activities/EVqX5pcwuOL' failed: [500] Internal Server Error
    at Request._callback (/Users/hain/glory/ai/dagama/microsoft/ms-bot-rebecca/src/node_modules/botbuilder/lib/bots/ChatConnector.js:431:46)
    at Request.self.callback (/Users/hain/glory/ai/dagama/microsoft/ms-bot-rebecca/src/node_modules/request/request.js:187:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/Users/hain/glory/ai/dagama/microsoft/ms-bot-rebecca/src/node_modules/request/request.js:1044:10)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/Users/hain/glory/ai/dagama/microsoft/ms-bot-rebecca/src/node_modules/request/request.js:965:12)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:913:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)
hailiang-wang commented 8 years ago

Also parse the session.message for skype

{
  "type": "message",
  "timestamp": "2016-07-13T09:19:41.965Z",
  "textFormat": "plain",
  "text": "hi",
  "entities": [],
  "address": {
    "id": "feWEhkz4KasbnDk",
    "channelId": "skype",
    "user": {
      "id": "29:1FKSeT2_VjIJU4NXBrXhFnHmqX3S9X7TP5oOL-D7rdjk",
      "name": "Hain"
    },
    "conversation": {
      "isGroup": false,
      "id": "29:1FKSeT2_VjIJU4NXBrXhFnHmqX3S9X7TP5oOL-D7rdjk"
    },
    "bot": {
      "id": "28:c11a90ad-b321-42bb-ac9e-545f6aeca19b",
      "name": "Rebecca"
    },
    "serviceUrl": "https://skype.botframework.com",
    "useAuth": true
  },
  "source": "skype",
  "attachments": [],
  "agent": "botbuilder",
  "user": {
    "id": "29:1FKSeT2_VjIJU4NXBrXhFnHmqX3S9X7TP5oOL-D7rdjk",
    "name": "Hain"
  }
}
hailiang-wang commented 8 years ago

Check botbuilder/lib/bots/ChatConnector.js

              request(optipackage.jsonons, function (err, response, body) {
                    if (!err) {
                        switch (response.statusCode) {
                            case 401:
                            case 403:
                                if (!refresh) {
                                    _this.authenticatedRequest(options, callback, true);
                                }
                                else {
                                    callback(null, response, body);
                                }
                                break;
                            default:
                                if (response.statusCode < 400) {
                                    callback(null, response, body);
                                }
                                else {
                                    var txt = "Request to '" + options.url + "' failed: [" + response.statusCode + "] " + response.statusMessage;
                                    callback(new Error(txt), response, null);
                                }
                                break;
                        }
                    }

After reading this piece of codes, I think it is a bug.

dandriscoll commented 8 years ago

The Bot Builder doesn't talk to the Direct Line API. The Direct Line API is a simpler version of the protocol that the Bot Builder SDK and Bot Connector Service talk to each other. It also has a different security model to allow your clients to distribute short-lived tokens.

The reference to "/api/messages/conversationId" is a documentation error that I thought I had fixed, but apparently cropped back up again in our latest release. I'll remove this. The correct paths are:

POST /api/tokens to get a token for a conversation GET /api/tokens to refresh a token

GET /api/conversations to start a new conversation POST /api/conversations/{id}/messages to send a message GET /api/conversations/{id}/messages to receive messages POST /api/conversations/{id}/upload to upload an attachment

There is an occasional 500 error I'm still working on but the API should be functional if you use the endpoints above.

dandriscoll commented 8 years ago

Documentation page is fixed now. Sorry about that.

http://docs.botframework.com/en-us/restapi/directline/

hailiang-wang commented 8 years ago

thanks, @dandriscoll, but how to make an application to talk to the bot if the bot is built with Botbuilder SDK? Since the Bot Builder doesn't talk to the Direct Line API. From the bot developer dashboard, I can see there are Skype, Slack, Facebook Messenger, Kik, Office 365 mail and other popular services. Well, I want to build a customzied channel, is there any solution?

dandriscoll commented 8 years ago

These are separate APIs with separate SDKs.

On the bot side, there's the Bot Builder SDK that talks to the Bot Connector REST API. The Bot Builder SDK allows your bot to talk to any channel.

On the channel (client) side, there's the Direct Line client that talks to the Direct Line REST API. The Direct Line client can talk to any bot registered with the Bot Framework.

At the moment, we've only got a Direct Line client written in C# -- it's available on Nuget.org under Microsoft.Bot.Connector.DirectLine. The API is fairly simple and is essentially identical to what our Web Chat embed speaks. For now, if you want to talk to the Direct Line API in JavaScript, you'll have to write your own client to the API documented in the link above, but I'm hoping to put together a small client eventually to make that simpler.

alin-nemet commented 7 years ago

Hi guys, I have a question: I have custom storage for my bot, configured through the ChatConnector, ie replaced state.botframework.com with a custom endpoint; our client uses direct client api; does direct line store data, maybe temporarily? I mean, when I start a conversation, then invoke get messages, it appears direct line gives me messages without hitting my bot connector's api getData, which makes me think it somehow has received it at some point through some interaction direct-line and my bot app; is there a way to know how the whole flow works? I also invoked get message directly for a conversationId: userMessageSet = userConversations.GetMessages(conversationId); and it didn't hit the bot connector from my app at all, which seems to tell that direct client (https://directline.botframework.com) somehow stored or cached the answer to a previous conversation. Thanks.

dandriscoll commented 7 years ago

Hi @alin-nemet, you can see my answer here: https://github.com/Microsoft/BotBuilder/issues/54

alin-nemet commented 7 years ago

already saw it, thx a lot for the help!

pranavjain commented 7 years ago

Hi @dandriscoll , I am getting { "message": "Internal error" } when I am trying to post a message to api/conversations/id/messages/. Could you please help?

dandriscoll commented 7 years ago

Hi @pranavjain, we've been experiencing intermittent service interruptions. We're monitoring and resolving these as they occur. Sorry for the interruption.

juanreyesv commented 7 years ago

Hi @dandriscoll I'm experiencing this same issue as described on the first message from @Samurais. Basically I can see the messages I sent to the API but not the ones that should be coming back from the Bot.

Do I need to specify the Bot that I want to talk to anywhere? Or will the secret key take care of this?

I'm not getting any error responses on any API calls, just no messages from my Bot, only messages from me and I'm using the right specified on the documentation.

Maybe I'm missing some key information when creating the Message or the Conversation?

Any help will be appreciated.

Thanks

EricDahlvang commented 7 years ago

Hi @juanreyesv,

 The Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repo  is the preferred platform for submitting bug fixes and feature requests.  

Please post your code in a question on Stack Overflow, so the community can benefit as well.

nupurkamble commented 7 years ago

hi @dandriscoll { "error": { "code": "BadArgument", "message": "Missing token or secret" } } im getting this error for directline deployed bot. What is causing it i cant figure out

msekkappan commented 5 years ago

Direct line access worked for twice, after that it started to give Missing token or secret