Skip to content

Commit

Permalink
[CSharp-DirectLine] Update to Microsoft.Bot.Builder v3.5.0 and Micros…
Browse files Browse the repository at this point in the history
…oft.Bot.Connector.DirectLine v.3.0.0
  • Loading branch information
ejadib authored Jan 9, 2017
1 parent 57a322e commit 28795f6
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 119 deletions.
28 changes: 14 additions & 14 deletions CSharp/core-DirectLine/DirectLineBot/DirectLineBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,42 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
<Reference Include="Autofac, Version=4.2.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.2.1\lib\net45\Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Chronic, Version=0.3.2.0, Culture=neutral, PublicKeyToken=3bd1f1ef638b0d3c, processorArchitecture=MSIL">
<HintPath>..\packages\Chronic.Signed.0.3.2\lib\net40\Chronic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Builder, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Reference Include="Microsoft.Bot.Builder, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Builder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Bot.Connector, Version=3.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.2.1\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Reference Include="Microsoft.Bot.Connector, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Builder.3.5.0\lib\net46\Microsoft.Bot.Connector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.2.33, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.2.206221351\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Reference Include="Microsoft.IdentityModel.Protocol.Extensions, Version=1.0.3.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Protocol.Extensions.1.0.3.308261200\lib\net45\Microsoft.IdentityModel.Protocol.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.4\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.20622.1351, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=4.0.30826.1200, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.IdentityModel.Tokens.Jwt.4.0.3.308261200\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net" />
Expand Down
13 changes: 6 additions & 7 deletions CSharp/core-DirectLine/DirectLineBot/DirectLineBotDialog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace DirectLineBot
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
Expand All @@ -17,34 +18,32 @@ public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitabl
{
var message = await result;
var reply = context.MakeMessage();
reply.Attachments = new List<Attachment>();

switch (message.Text.ToLower())
{
case "show me a hero card":
reply.Text = $"Sample message with ChannelData using the BotBuilder Hero's card";
reply.Text = $"Sample message with a HeroCard attachment";

var heroCardAttachment = new HeroCard
{
Title = "Sample Hero Card",
Text = "Displayed in the DirectLine client"
}.ToAttachment();

// Not using a anonymous object due to #998 (https://github.com/Microsoft/BotBuilder/issues/998)
reply.ChannelData = heroCardAttachment;

reply.Attachments.Add(heroCardAttachment);
break;
case "send me a botframework image":

reply.Text = $"Sample message with ChannelData using the BotBuilder Attachment structure";
reply.Text = $"Sample message with an Image attachment";

var imageAttachment = new Attachment()
{
ContentType = "image/png",
ContentUrl = "https://docs.botframework.com/en-us/images/faq-overview/botframework_overview_july.png",
};

// Not using a anonymous object due to #998 (https://github.com/Microsoft/BotBuilder/issues/998)
reply.ChannelData = imageAttachment;
reply.Attachments.Add(imageAttachment);

break;
default:
Expand Down
14 changes: 13 additions & 1 deletion CSharp/core-DirectLine/DirectLineBot/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand All @@ -63,6 +63,18 @@
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.30826.1200" newVersion="4.0.30826.1200" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Protocol.Extensions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.3.42" newVersion="1.0.3.42" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
14 changes: 7 additions & 7 deletions CSharp/core-DirectLine/DirectLineBot/packages.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net46" />
<package id="Autofac" version="4.2.1" targetFramework="net46" />
<package id="Chronic.Signed" version="0.3.2" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.2.1" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
<package id="Microsoft.Bot.Builder" version="3.5.0" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.3.308261200" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net46" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.3.308261200" targetFramework="net46" />
</packages>
2 changes: 1 addition & 1 deletion CSharp/core-DirectLine/DirectLineClient/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bot.Connector.DirectLine, Version=1.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Connector.DirectLine.1.0.2\lib\net45\Microsoft.Bot.Connector.DirectLine.dll</HintPath>
<Reference Include="Microsoft.Bot.Connector.DirectLine, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bot.Connector.DirectLine.3.0.0-beta\lib\net45\Microsoft.Bot.Connector.DirectLine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.1.8.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.4\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -58,7 +59,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Models\DirectLineChannelData.cs" />
<Compile Include="Models\DirectLineCardContent.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

This file was deleted.

72 changes: 39 additions & 33 deletions CSharp/core-DirectLine/DirectLineClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Bot.Connector.DirectLine;
using Microsoft.Bot.Connector.DirectLine.Models;
using Models;
using Newtonsoft.Json;

Expand All @@ -25,7 +24,7 @@ private static async Task StartBotConversation()
{
DirectLineClient client = new DirectLineClient(directLineSecret);

var conversation = await client.Conversations.NewConversationAsync();
var conversation = await client.Conversations.StartConversationAsync();

new System.Threading.Thread(async () => await ReadBotMessagesAsync(client, conversation.ConversationId)).Start();

Expand All @@ -43,13 +42,14 @@ private static async Task StartBotConversation()
{
if (input.Length > 0)
{
Message userMessage = new Message
Activity userMessage = new Activity
{
FromProperty = fromUser,
Text = input
From = new ChannelAccount(fromUser),
Text = input,
Type = ActivityTypes.Message
};

await client.Conversations.PostMessageAsync(conversation.ConversationId, userMessage);
await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage);
}
}
}
Expand All @@ -61,33 +61,34 @@ private static async Task ReadBotMessagesAsync(DirectLineClient client, string c

while (true)
{
var messages = await client.Conversations.GetMessagesAsync(conversationId, watermark);
watermark = messages?.Watermark;
var activitySet = await client.Conversations.GetActivitiesAsync(conversationId, watermark);
watermark = activitySet?.Watermark;

var messagesFromBotText = from x in messages.Messages
where x.FromProperty == botId
select x;
var activities = from x in activitySet.Activities
where x.From.Id == botId
select x;

foreach (Message message in messagesFromBotText)
foreach (Activity activity in activities)
{
Console.WriteLine(message.Text);
Console.WriteLine(activity.Text);

if (message.ChannelData != null)
if (activity.Attachments != null)
{
var channelData = JsonConvert.DeserializeObject<DirectLineChannelData>(message.ChannelData.ToString());

switch (channelData.ContentType)
foreach (Attachment attachment in activity.Attachments)
{
case "application/vnd.microsoft.card.hero":
RenderHeroCard(channelData);
break;

case "image/png":
Console.WriteLine($"Opening the requested image '{channelData.ContentUrl}'");

Process.Start(channelData.ContentUrl);
break;
}
switch (attachment.ContentType)
{
case "application/vnd.microsoft.card.hero":
RenderHeroCard(attachment);
break;

case "image/png":
Console.WriteLine($"Opening the requested image '{attachment.ContentUrl}'");

Process.Start(attachment.ContentUrl);
break;
}
}
}

Console.Write("Command> ");
Expand All @@ -97,16 +98,21 @@ private static async Task ReadBotMessagesAsync(DirectLineClient client, string c
}
}

private static void RenderHeroCard(DirectLineChannelData channelData)
private static void RenderHeroCard(Attachment attachment)
{
const int Width = 70;
Func<string, string> contentLine = (content) => string.Format($"{{0, -{Width}}}", string.Format("{0," + ((Width + content.Length) / 2).ToString() + "}", content));

Console.WriteLine("/{0}", new string('*', Width + 1));
Console.WriteLine("*{0}*", contentLine(channelData.Content.Title));
Console.WriteLine("*{0}*", new string(' ', Width));
Console.WriteLine("*{0}*", contentLine(channelData.Content.Text));
Console.WriteLine("{0}/", new string('*', Width + 1));
var heroCard = JsonConvert.DeserializeObject<HeroCard>(attachment.Content.ToString());

if (heroCard != null)
{
Console.WriteLine("/{0}", new string('*', Width + 1));
Console.WriteLine("*{0}*", contentLine(heroCard.Title));
Console.WriteLine("*{0}*", new string(' ', Width));
Console.WriteLine("*{0}*", contentLine(heroCard.Text));
Console.WriteLine("{0}/", new string('*', Width + 1));
}
}
}
}
6 changes: 3 additions & 3 deletions CSharp/core-DirectLine/DirectLineClient/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bot.Connector.DirectLine" version="1.0.2" targetFramework="net461" />
<package id="Microsoft.Rest.ClientRuntime" version="1.8.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net461" />
<package id="Microsoft.Bot.Connector.DirectLine" version="3.0.0-beta" targetFramework="net461" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.4" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages>
Loading

0 comments on commit 28795f6

Please sign in to comment.