Closed christopear closed 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.
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.
We've got a CORS whitelist on directline.botframework.com -- are your preflight requests failing?
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.
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.
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
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.
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.
Thanks cajpearce and dandriscoll for this thread.
Problem solved! My added properties were wrong. Thanks a lot!
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?
@rahulsarkar123 Please open a new issue. This issue is closed.
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?