2

I noticed the Direct Line request url is like this: https://localhost:8011/api/ in the documention. What should replace it with?

I have deployed a todoBot example project from botbuilder Examples folder. And I have created a bot in My bots section, the ending point is: http://www.bigluntan.com:3978/api/messages. I have tested in Test connection to your bot section, it is working when I type something and send it. Right now, I want to give Direct Line a try. So I added Direct Line to Channels. But the most confused part is, how do I call this Direct Line api, cause the ending point is different than my bot's ending point.

yong ho
  • 3,892
  • 9
  • 40
  • 81

2 Answers2

6

The base URL is https://directline.botframework.com, so for instance, the POST request to get a new conversationId should be https://directline.botframework.com/api/conversations/

The request headers should include the Content-Type and also the following:

Authorization: BotConnector < Your secret >

where your secret is the code which was created when you created a Direct Line channel for your registered Bot (see image below). e.g.

Content-Type: application/json; charset=utf-8 
Authorization: BotConnector pB7INWcXQjA.cwA.RF4.cglOUNHUOzWVv0Rlk3ovFNhtp1JPz1Zx9jmu8vX7zXs

Once you get a conversationId, you can POST a message using the URL https://directline.botframework.com/api/conversations/< conversationId >/messages

The body of the request should include the message text. You will not get the reply in the POST response. Instead, you need to get it by sending a GET to https://directline.botframework.com/api/conversations/< conversationId >/messages. From there, you can get the "from" value in your first message, and use it in subsequent calls to the same conversation (otherwise the bot will not recognise the state, and just keep repeating the first reply message), e.g.

{
text: "yes",
from: "EQxvIzZOspA"
}

enter image description here

Andy Thomas
  • 1,367
  • 2
  • 14
  • 30
  • Also just ensure you don't add a ID to your message, it somehow never worked for me. – Siddharth Gupta Apr 16 '16 at 18:41
  • You may be able to set the from property to whatever you choose, rather than getting it from the conversation history. I have not tried doing that. – Andy Thomas Apr 23 '16 at 17:37
  • The API suggests sending a JSON object as a message but you hint that you should send raw text - which is it? And if you send JSON, how do you populate the fields? – Brendan Jun 23 '16 at 13:10
  • @Brendan - I did not mean to suggest sending raw text. The body of the request should indeed be a JSON object. See the code excerpt above, where the body includes a JSON object with "text" and "from" properties. – Andy Thomas Jun 26 '16 at 02:30
  • @AndyThomas Thanks for your answer. But one question, When get the conversation by sending a GET to https://directline.botframework.com/api/conversations/< conversationId >/messages . All I get are conversations that I send, I am not getting the message coming from the bot. It suppose to send "Hi, What's you name?" when I send "Hi" to the bot. I tried on bot emulator and in skyp bot and it's all working except direct line rest api. – yong ho Aug 04 '16 at 06:01
  • @yong ho If the responses are showing up in the bot emulator, then you are correct in that you should also expect to see them in the GET request for the full conversation history. If you are not seeing the full history, check that you are not setting the watermark property. Otherwise, this sounds like a genuine issue - try creating an issue on the repo tab (it looks like they have removed their support e-mail) – Andy Thomas Aug 04 '16 at 15:55
  • @AndyThomas Thank you for the explanation. I tried your solution with postman, where I made a POST request to https://directline.botframework.com/api/conversations/ with basic auth where user name is BotConnector and secret is the one I get from my bot page (direct line enabled). Still get "Missing token or secret" error though. Any ideas? – tahsintahsin Sep 02 '16 at 11:49
1

I found this out by trial and error. If you want to use the direct line api you should try https://directline.botframework.com as the base URL

Koshin
  • 21
  • 1
  • 1
    Thanks for the url. The `api_key ` in the doc, does it mean the bot's `App Id` or the direct line `Secret`? By the way, I am trying to generate a new token for conversation with `/api/tokens/conversation`, but i am still getting `"message": "Missing token or secret"`. Do you have a url request example you could share? Thanks. – yong ho Apr 13 '16 at 09:05