TOKEN of Direct Line API
Now I am using Direct Line API in this way.
- get 'Credentials' from portal
- POST to '/api/conversations' using 'Credentials', and 'conversationId' return
- POST message to '/api/conversations/{conversationId}/messages' using 'Credentials'
- GET message from '/api/conversations/{conversationId}/messages' using 'Credentials'
[Question 1] I don't know if I am doing the right way?
[Question 2] So when the TOKEN should be use? I found that once the 'conversationId' is generated, it is valid forever, right? Why TOKEN is needed and need to renew? GET '/api/tokens' will return TOKEN POST '/api/conversations' will also return TOKEN GET '/api/tokens/{conversationId}/renew' won't return TOKEN POST ' /api/tokens/conversation' won't return TOKEN
[Question 3] Where are these Conversations Data saved? Will these data saved in Server forever or they will be deleted after a period of time?
Last question first since that's easiest, the messages will stay around temporarily but are not permanent. Don't take a dependency on them sticking around.
You can decide whether you want to use a SECRET or a TOKEN to authenticate your application.
Pros of using your secret: easier to code, secret is valid forever for all conversations Cons us using your secret: if you're using your secret in a client application, users may be able to see and steal your secret. The secret can also be used to inspect other conversations (although you have to know/guess the other conversation ID.)
Pros of using a token: valid only for one conversation, valid only for a short period of time Cons of using a token: must exchange secret for token, must refresh token while you want to use it
You can use either a secret or a token -- both are valid. You decide based on what security characteristics are important to you.
Most server-to-server applications calling Direct Line use their secret. Most client-to-server applications calling Direct Line use a token.
Hello, I am would like to start write code using DirectLineAPI to develop a client for my bot. It would be great, if someone shares the basic code to start with...Having some doubts like....it is mentioned that, "get credentials from portal"..so credentials here means...the Bots primary App secret or webchat generated secret....
Looking to see the sample code to start with.
Regards, Giri G.
Hello Team, Can u share some sample code for directline api for me to start...
Regards, Giri G.
Actually i followed the first points from the eddie, but i am always getting empty messages after polling the get messages for a long time....Any guess?
Regards, Giri G.
What you will see when you get message is something like this. { "messages":[ { "id": "DzKFNgal|131067343321045758", "conversationId": "DzKFNgal", "created": "2016-05-03T07:32:12.1045758Z", "from": "GXXPBGLn", "text": "こんにちは", "images": [], "attachments": [], "eTag": "W/"datetime'2016-05-03T07%3A32%3A12.5890281Z'"" }, { "id": "DzKFNgal|131067343351887485", "conversationId": "DzKFNgal", "created": "2016-05-03T07:32:15.1887485Z", "from": "bot-staging", "text": "こんにちは", "images": [], "attachments": [], "eTag": "W/"datetime'2016-05-03T07%3A32%3A15.6679583Z'"" }], "watermark": "1310674335187485" }
sorry for the belated response. I am getting an empty array: { "messages": [] }
I posted like this: https://directline.botframework.com/api/conversations/45I5pWxuJbK/messages/ Post message: Content-type: application/json { "id": "string", "conversationId": "45I5pWxuJbK", "created": "2016-05-29T05:17:31.651Z", "from": "string", "text": "status of train 12680", "channelData": "string", "images": [ "string" ], "attachments": [ { "url": "string", "contentType": "string" } ], "eTag": "string" }
got response as 204.
Anything I missed.
I am able to call the directline api now..however I am always getting the first message (as responses)from my bot, every time I post new messages. Can any one help me here....? Eagerly waiting for the reply.
Hi Giri, are you sending the watermark parameter when you GET /api/conversations/id/messages? The watermark is the paging parameter for the messages.
Yes. Basically, I am reusing the chat.js, and here is the code snippet:
//setting up the url.
baseUrl = "https://directline.botframework.com";
var tokenNeedsRenewal = "true";
var tokenOrSecret = "****************************";
var botId = "***********";
var callback = function() {
}
var client = new ChatLib.ChatClient(tokenNeedsRenewal, tokenOrSecret, botId, callback);
$(document).ready(function() {
$(document).off('click', '.btn-send');
$(document).on('click', '.btn-send', function() {
var msg = new ChatLib.ChatMessage();
msg.text = $(".user-message").val();
client.sendMessage(msg);
});
//I am trying to read the messages stored in conversation array.
function readMessages(startMsgIndex) {
var idx=startMsgIndex;
if(idx < client.conversation.length) {
for(; idx < client.conversation.length; idx++) {
$("#messages").html($("#messages").html() + client.conversation[idx].text + "<br/>");
}
startMsgIndex = idx;
}
setTimeout(function() {
readMessages(startMsgIndex);
}, 500);
}
readMessages(0);
});
I can see the watermark as part of the url... I am building a prototype to prove that the website context can be passed to bot, to respond context based messages.
So I appreciate, if you could help me here... Thanks.
Any suggestions from your end? On 31-May-2016 8:37 PM, "dandriscoll" [email protected] wrote:
Hi Giri, are you sending the watermark parameter when you GET /api/conversations/id/messages? The watermark is the paging parameter for the messages.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/254#issuecomment-222718289, or mute the thread https://github.com/notifications/unsubscribe/AR4V4KiR0GvzHMNVxkmX5OuavTlHWOaJks5qHE62gaJpZM4IaxLf .
hello dandriscoll, did u get a chance to debug this issue..? I am waiting for your response....Thanks.

Attached a snapshot of the scenario for your reference.
Regards, Giri G.