DirectLineAPI – Testing with custom client and POSTMAN – Microsoft Bot Framework

Direct Line API is used enable communication between your bot and your own client application.

This post will show you how can we use the direct line API of our BOT to start a conversation and also how to exchange Activities.

We are using the Microsoft Sample bot example of Notes Bot.

The below pic show how the sample conversation would go like:

d1
Notes Bot Sample Conversation

Enabling the Direct line API:

Go to your Azure Portal and then Go to your Bot resource and in the menu click on the channels then enable the Direct line API for your site:

d2
configure the Direct Line and generate the secret key 

Once the Direct Line API is enabled, copy the secret key.

Starting the conversation:

Issue a POST request to start a new conversation:

POST https://directline.botframework.com/v3/directline/conversations
Authorization: Bearer SECRET_OR_TOKEN

d3
Add the Authorization header and click on send

You will receive the Conversation Id as show below. Means the connection has been established.

d4

Sending the Activity to the Bot:

POST https://directline.botframework.com/v3/directline/conversations/abc123/activities
Authorization: Bearer XXXXXXXXXXXXX
Content-Type: application/json
[other headers]

Sending a POST request:

d6
sending an activity with a custom body
d7
You will receive the response as conversation Id

Receiving an activity or Response from the bot:

GET https://directline.botframework.com/v3/directline/conversations/abc123/activities?watermark=0001a-94

Authorization: Bearer xxxxxxxxxx

Sending a GET Request:

d9
Send a GET request to receive the Bot response
d8
Received response from the BOT

Activities received is the array of the whole conversation which contains the sent activities from user and received activity from Bot.

The text sent was “create a note” and the text received is “What would like to call your note?”

So send Consecutive POST and GET request to hold a conversation with the bot.

Hope it Helps!

For full official documentation visit here

In coming posts i will try to show how can build custom chat user interface and how that custom bot can leverage the use of Direct line API.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s