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

[CSharp] DirectLine + WebSockets sample#86

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

[CSharp] DirectLine + WebSockets sample#86
dandriscoll merged 7 commits intomicrosoft:masterfrom
southworks:csharp-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.

Looks great overall, only a few small changes

{
private static string directLineSecret = ConfigurationManager.AppSettings["DirectLineSecret"];
private static string botId = ConfigurationManager.AppSettings["BotId"];
private static string fromUser = "DirectLineSampleClientUser";
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 fromUser?

// fromUser 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.


private static void WebSocketClient_OnMessage(object sender, MessageEventArgs e)
{
// avoid null reference exception when no data received
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.

Change this comment to:

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

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.

One other item I just thought of: can you add some code to the sample that exchanges the Direct Line secret for a token before using it?

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.

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bot.Connector.DirectLine" version="3.0.0" targetFramework="net461" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net461" />
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.

We've hit binary incompatibilities between minor versions of Microsoft.Rest.ClientRuntime. 2.3.2 is probably a better example to use.

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

select x;
````

DirectLine v3.0 (unlike version 1.1) has support for Attachments (see [Adding Attachments to a Message](https://docs.botframework.com/en-us/core-concepts/attachments) for more information about attachments). Check out the `WebSocketClient_OnMessage` method in [Program.cs](DirectLineClient/Program.cs#L73-L90) to see how the Attachments are retrieved and rendered appropriately based on their type.
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.

In printed text, Direct Line is normally two words.

It's OK to collapse them in filenames, though. ("DirectLineClient.cs" 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.

Fixed in Node too

@pcostantini
Copy link
Copy Markdown
Contributor

Hi @dandriscoll , we've updated the PR with the latest feedback.
Regards!

@dandriscoll dandriscoll merged commit 52a33a8 into microsoft:master Apr 5, 2017
@pcostantini pcostantini deleted the csharp-directline-websockets branch April 5, 2017 20:58
tracyboehrer pushed a commit that referenced this pull request Dec 23, 2025
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