microsoft / botframework-sdk

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

Receiving no response message from Direct Line v 3.0 websocket #2058

Closed christopear closed 7 years ago

christopear commented 7 years ago

Hey there, I'm writing a direct line connection to the bot framework in javascript at the moment. I'm successfully starting a conversation with the bot via /v3/directline/conversations, and creating a websocket with the streamUrl provided as response. I am sending a simple json string of {"text": "[userMessage]"} to the websocket. I also am receiving a MessageEvent. However, the MessageEvent data field is consistently empty (no reply from the bot).

I've been following the documentation on the website, however I am fairly new to websockets and so am not sure how to diagnose this issue. Am I supposed to poll directline for new messages via HTTP GET after receiving the empty message from the websocket? Or is this not the expected response from the websocket?

dandriscoll commented 7 years ago

Hi @cajpearce, to send an Activity via Direct Line 3.0, you send a POST via HTTPS. The WebSocket ignores uploaded Activities.

In Direct Line 3.0, you get to decide how you want to receive messages. You can use polling GET, or you can use the Web Socket. (You do not need to use both.) In either case, you must use POST to send a message.

christopear commented 7 years ago

Ah, so I can't send activities via WebSocket.send()? That might explain it. I was hoping to use the WebSocket due to CORS issues posting to the bot framework straight from jQuery. I was hoping to avoid using a CORS proxy while testing.

dandriscoll commented 7 years ago

We've got a CORS whitelist on directline.botframework.com -- are your preflight requests failing?

christopear commented 7 years ago

No, I get a 400 bad request when I input the correct URL: https://directline.botframework.com/v3/directline/conversations/5tRxVSV9XlyFE5toUMrSTY/activities Failed to load resource: the server responded with a status of 400 (Bad Request)

I have included the relevant code here.

I will pursue this further, but still unsure as to what this error means as it does not provide any further information.

christopear commented 7 years ago

Ignore me! A combination of a spelling mistake in the URL leading to failed preflight requests (activites instead of activities) originally confused me, and thus I tried 1.0 which lead me to using the wrong JSON structure when switching back to v 3. Managed to confuse myself to no end. Everything is working now. Cheers.

Lugo239 commented 7 years ago

Hey Cajpearce!

I faced the same problem with the spelling. Despite the fix i am now getting a 500er result. Any hints for fixing the problem?

Greetings Lugo

christopear commented 7 years ago

Hey @Lugo239, in javascript I went with using direct line 3.0 and the websocket.

POST to https://directline.botframework.com/v3/directline/conversations to start the conversation (with auth + token)

then my success function created a websocket for receiving messages that looks like this success: function(direct_line_response) { webSocket = new WebSocket(direct_line_response.streamUrl); webSocket.onmessage = messageReceived; // where messageReceived is your function for processing msgs conversationId = direct_line_response.conversationId; }

To post user messages to your bot, you need to use REST to post to this URL:

"https://directline.botframework.com/v3/directline/conversations/" + conversationId + "/activities" // where conversationId is saved in your success function

Hope that helps at all! I'm not very experienced on the bot framework.

Lugo239 commented 7 years ago

Hey cajpearce thanks for the fast reply!

I want to use direct line 3.0 and the websocket for my android application.

I. CHECK I start the conversation with Authorization posting to "https://directline.botframework.com/v3/directline/conversations". The result is 201 with the Streamurl "wss://...." . II. CHECK Creating a WebSocketClient with the streamURL as input. Server handshake 101. III. FAILURE Sending a simple text from the user to "https://directline.botframework.com/v3/directline/conversations/" + conversationID + "/activities" with Authorization.

Currently the result is a bad request. Maybe some detail in the post is missing.

EDIT: When i try to post a message via the Websocket method i get after a bunch of seconds a null message in the onMessage part. Normal post still bad request.

Lugo239 commented 7 years ago

Thanks cajpearce and dandriscoll for this thread.

Problem solved! My added properties were wrong. Thanks a lot!

rahulsarkar123 commented 7 years ago

Hi Team, I have implemented Direct Line 3.0 from my client application. But while calling the DirectLine API from our client application we are not getting the expected response always. From the json string, sometimes we are not being able to see the exact response text .Can you please suggest?

nwhitmont commented 7 years ago

@rahulsarkar123 Please open a new issue. This issue is closed.