Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

[Node] DirectLine + WebSockets sample#87

Merged
dandriscoll merged 5 commits intomicrosoft:masterfrom
southworks:node-directline-websockets
Apr 5, 2017
Merged

[Node] DirectLine + WebSockets sample#87
dandriscoll merged 5 commits intomicrosoft:masterfrom
southworks:node-directline-websockets

Conversation

@ejadib
Copy link
Copy Markdown
Contributor

@ejadib ejadib commented Mar 9, 2017

No description provided.

Copy link
Copy Markdown
Member

@dandriscoll dandriscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small changes, and one addition of a call to the Token API would be perfect. Thanks!

// Config settings
var useW3CWebSocket = false;
var directLineSecret = 'DIRECTLINE_SECRET';
var directLineClientName = 'DirectLineClient';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directLineUserId may be better

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the following comment above this variable?

// directLineUserId is the field that identifies which user is sending activities to the Direct Line service.
// Because this value is created and sent within your Direct Line client, your bot should not
// trust the value for any security-sensitive operations. Instead, have the user log in and
// store any sign-in tokens against the Conversation or Private state fields. Those fields
// are secured by the conversation ID, which is protected with a signature.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var directLineSpecUrl = 'https://docs.botframework.com/en-us/restapi/directline3/swagger.json';

process.argv.forEach(function (val, index, array) {
if (val === 'w3c') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just call the option "websocket" ? I don't think we refer to Web Sockets as W3C Web Sockets anywhere else. They're just regular Web Sockets to us :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I noticed below that W3C is a specific kind of socket exposed by Node? If so, this is OK.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same library, but the API exposed by the two versions change. The NodeJS version uses EventEmitter to trigger events, while the 'w3cwebsocket' follows the W3C spec using event handlers set as props, which is what WebBrowsers do.

usePromise: true
});
})
.then(function (client) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also illustrate using the Token API to exchange the client's secret for a token?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added note on README here.

console.log('WebSocket Client Disconnected');
});
connection.on('message', function(message) {
if (message.type === 'utf8' && message.utf8Data.length > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment similar to:

// Occasionally, the Direct Line service sends an empty message as a liveness ping. Ignore these messages.

@@ -0,0 +1,181 @@
# Direct Line Bot Sample (using client WebSockets)

A sample bot and a custom client communicating to each other using the Direct Line API.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere near the top of the sample, we should note the following:

  • For many developers, the DirectLineJs project is an easy way to connect to the Direct Line in Node.js
  • If you're interested in writing your own client without using DirectLineJs, use this sample

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcostantini
Copy link
Copy Markdown
Contributor

@dandriscoll Hi Dan, the feedback for the Node's DirectLine with WebSockets has been applied.
Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants