Skip to content

Commit fe946cc

Browse files
committed
Merge branch 'develop'
2 parents d1e5fec + 16ca102 commit fe946cc

File tree

180 files changed

+21065
-3633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+21065
-3633
lines changed

CSharp/Documentation/Dialogs.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// \tableofcontents
55
/// [LUIS]: http://luis.ai
66
/// [How to Setup LUIS]: http://aka.ms/bf-node-nl
7+
/// [Buttons]: http://docs.botframework.com/connector/message-actions/#actions-on-attachments
78
///
89
/// \section Overview
910
/// %Dialogs model a conversational process, where the exchange of messages between bot and user
@@ -145,11 +146,16 @@
145146
///
146147
/// The Chain methods provide a fluent interface to dialogs that is usable in linq query syntax. The compiled form of linq query syntax often leverages anonymous methods.
147148
/// If these anonymous methods do not reference the environment of local variables, then these anonymous methods have no state and are trivially serializable. However, if
148-
/// the anonymous method captures any local variable in the environment, the resulting closure object (generated by the compiler) is not marked as serializable. The %Bot Builder
149+
/// the anonymous method captures any local variable in the environment, the resulting closure object (generated by the compiler) is not marked as serializable. The %Bot %Builder
149150
/// will detect this situation and throw a ClosureCaptureException to help diagnose the issue.
150151
///
151152
/// If you wish to try to leverage reflection to serialize classes that are not marked as serializable, the library has a reflection-based serialization surrogate that
152153
/// can be registered with Autofac as follows:
154+
/// ~~~
155+
/// var builder = new ContainerBuilder();
156+
/// builder.RegisterModule(new DialogModule());
157+
/// builder.RegisterModule(new ReflectionSurrogateModule());
158+
/// ~~~
153159
///
154160
/// \dontinclude Microsoft.Bot.Builder.Tests\ChainTests.cs
155161
/// \skip includeReflection
@@ -217,5 +223,5 @@
217223
/// \section Conclusion
218224
/// Through this description we have seen how you can easily create stateless bots that can reuse dialog building blocks
219225
/// ranging from simple prompts to advanced natural language. As a next step, you should explore \ref forms which
220-
/// describes how the %Bot Builder framework can automatically build dialogs from a C# class you want the user to fill in.
226+
/// describes how the %Bot %Builder framework can automatically build dialogs from a C# class you want the user to fill in.
221227
}

CSharp/Documentation/Documentation.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<SccAuxPath>SAK</SccAuxPath>
1212
<SccProvider>SAK</SccProvider>
1313
<ProjectGuid>{72C60ACB-4804-4584-AD49-00289A89F227}</ProjectGuid>
14-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
1515
<TargetFrameworkProfile />
1616
</PropertyGroup>
1717
<PropertyGroup Condition="'$(Configuration)' == 'Documentation'">

CSharp/Documentation/Forms.cs

+164-11
Large diffs are not rendered by default.

CSharp/Documentation/Overview.cs

+5
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ namespace Microsoft.Bot.Builder.Internals.Fibers { }
8989
/// <summary>Namespace for the machinery needed to talk to http://luis.ai.</summary>
9090
/// <remarks>This namespace is not useful for most developers.</remarks>
9191
namespace Microsoft.Bot.Builder.Luis { }
92+
93+
/// <summary>
94+
/// Namespace for resources.
95+
/// </summary>
96+
namespace Microsoft.Bot.Builder.Resource { }

CSharp/Documentation/app.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
3+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>
44
<runtime>
55
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
66
<dependentAssembly>

CSharp/Library/Dialogs/BotData.cs

+41-8
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@
3737

3838
using Microsoft.Bot.Builder.Internals.Fibers;
3939
using Microsoft.Bot.Connector;
40+
using System.IO;
4041

4142
namespace Microsoft.Bot.Builder.Dialogs.Internals
4243
{
4344
public abstract class BotDataBase<T> : IBotData
4445
{
45-
protected readonly Message mesage;
46+
protected readonly Message message;
4647

4748
public BotDataBase(Message message)
4849
{
49-
SetField.NotNull(out this.mesage, nameof(mesage), message);
50+
SetField.NotNull(out this.message, nameof(BotDataBase<T>.message), message);
5051
}
5152

5253
protected abstract T MakeData();
@@ -56,11 +57,11 @@ IBotDataBag IBotData.ConversationData
5657
{
5758
get
5859
{
59-
var data = (T)this.mesage.BotConversationData;
60+
var data = (T)this.message.BotConversationData;
6061
if (data == null)
6162
{
6263
data = this.MakeData();
63-
this.mesage.BotConversationData = data;
64+
this.message.BotConversationData = data;
6465
}
6566

6667
return this.WrapData(data);
@@ -71,11 +72,11 @@ IBotDataBag IBotData.PerUserInConversationData
7172
{
7273
get
7374
{
74-
var data = (T)this.mesage.BotPerUserInConversationData;
75+
var data = (T)this.message.BotPerUserInConversationData;
7576
if (data == null)
7677
{
7778
data = this.MakeData();
78-
this.mesage.BotPerUserInConversationData = data;
79+
this.message.BotPerUserInConversationData = data;
7980
}
8081

8182
return this.WrapData(data);
@@ -86,11 +87,11 @@ IBotDataBag IBotData.UserData
8687
{
8788
get
8889
{
89-
var data = (T)this.mesage.BotUserData;
90+
var data = (T)this.message.BotUserData;
9091
if (data == null)
9192
{
9293
data = this.MakeData();
93-
this.mesage.BotUserData = data;
94+
this.message.BotUserData = data;
9495
}
9596

9697
return this.WrapData(data);
@@ -209,4 +210,36 @@ protected override IBotDataBag WrapData(JObject data)
209210
return new Bag(data);
210211
}
211212
}
213+
214+
public sealed class BotDataBagStream : MemoryStream
215+
{
216+
private readonly IBotDataBag bag;
217+
private readonly string key;
218+
public BotDataBagStream(IBotDataBag bag, string key)
219+
{
220+
SetField.NotNull(out this.bag, nameof(bag), bag);
221+
SetField.NotNull(out this.key, nameof(key), key);
222+
223+
byte[] blob;
224+
if (this.bag.TryGetValue(key, out blob))
225+
{
226+
this.Write(blob, 0, blob.Length);
227+
this.Position = 0;
228+
}
229+
}
230+
231+
public override void Flush()
232+
{
233+
base.Flush();
234+
235+
var blob = this.ToArray();
236+
this.bag.SetValue(this.key, blob);
237+
}
238+
239+
public override void Close()
240+
{
241+
this.Flush();
242+
base.Close();
243+
}
244+
}
212245
}

CSharp/Library/Dialogs/BotToUser.cs

+55-15
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3232
//
3333

34+
using Microsoft.Bot.Builder.Internals.Fibers;
35+
using Microsoft.Bot.Connector;
3436
using System.Collections.Generic;
3537
using System.IO;
38+
using System.Linq;
3639
using System.Threading;
3740
using System.Threading.Tasks;
3841

39-
using Microsoft.Bot.Builder.Internals.Fibers;
40-
using Microsoft.Bot.Connector;
41-
4242
namespace Microsoft.Bot.Builder.Dialogs.Internals
4343
{
4444
public sealed class SendLastInline_BotToUser : IBotToUser
@@ -90,26 +90,39 @@ async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationT
9090
}
9191
}
9292

93-
public sealed class BotToUserQueue : IBotToUser
93+
public sealed class AlwaysSendDirect_BotToUser : IBotToUser
9494
{
9595
private readonly Message toBot;
96-
private readonly Queue<Message> queue = new Queue<Message>();
97-
public BotToUserQueue(Message toBot)
96+
private readonly IConnectorClient client;
97+
public AlwaysSendDirect_BotToUser(Message toBot, IConnectorClient client)
9898
{
9999
SetField.NotNull(out this.toBot, nameof(toBot), toBot);
100+
SetField.NotNull(out this.client, nameof(client), client);
100101
}
101-
102-
public void Clear()
102+
103+
Message IBotToUser.MakeMessage()
103104
{
104-
this.queue.Clear();
105+
var toUser = this.toBot.CreateReplyMessage();
106+
toUser.BotUserData = this.toBot.BotUserData;
107+
toUser.BotConversationData = this.toBot.BotConversationData;
108+
toUser.BotPerUserInConversationData = this.toBot.BotPerUserInConversationData;
109+
return toUser;
105110
}
106111

107-
public IEnumerable<Message> Messages
112+
async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationToken)
108113
{
109-
get
110-
{
111-
return this.queue;
112-
}
114+
await this.client.Messages.SendMessageAsync(message, cancellationToken);
115+
}
116+
}
117+
118+
public sealed class BotToUserQueue : IBotToUser
119+
{
120+
private readonly Message toBot;
121+
private readonly Queue<Message> queue;
122+
public BotToUserQueue(Message toBot, Queue<Message> queue)
123+
{
124+
SetField.NotNull(out this.toBot, nameof(toBot), toBot);
125+
SetField.NotNull(out this.queue, nameof(queue), queue);
113126
}
114127

115128
Message IBotToUser.MakeMessage()
@@ -145,7 +158,34 @@ Message IBotToUser.MakeMessage()
145158
async Task IBotToUser.PostAsync(Message message, CancellationToken cancellationToken)
146159
{
147160
await this.inner.PostAsync(message, cancellationToken);
148-
await this.writer.WriteLineAsync(message.Text);
161+
await this.writer.WriteLineAsync($"{message.Text}{ActionsToText(message.Attachments)}");
162+
}
163+
164+
private static string ActionsToText(IList<Attachment> attachments)
165+
{
166+
var buttonAttachments = attachments?.Where(attachment => attachment.Actions?.Count > 0);
167+
string text = string.Empty;
168+
if (buttonAttachments != null)
169+
{
170+
foreach (var attachment in buttonAttachments)
171+
{
172+
if (attachment != null && attachment.Actions != null && attachment.Actions.Count() > 0)
173+
{
174+
foreach (var action in attachment.Actions)
175+
{
176+
if (!string.IsNullOrEmpty(action.Message))
177+
{
178+
text += $"\n{action.Message}. {action.Title}";
179+
}
180+
else
181+
{
182+
text += $"\n* {action.Title}";
183+
}
184+
}
185+
}
186+
}
187+
}
188+
return text;
149189
}
150190
}
151191
}

0 commit comments

Comments
 (0)