Search code examples
node.jsbotframeworkbotconnectordirect-line-botframework

Where is the host and port coming from when I am reading Direct Line API doc from Microsoft Bot Framework


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.


Solution

  • 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