Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
49fb298
Release 07-07-2017 (#176)
RobStand Jul 7, 2017
0973c43
Sync with live for 7-7-17 release
RobStand Jul 7, 2017
12646e6
ISO 639-2 recommends use of the language codes in lower case (#175)
johnd-ms Jul 8, 2017
926f3c4
Update bot-builder-dotnet-quickstart.md
brandonh-msft Jul 6, 2017
d0cd730
Removing bad metadata (#183)
Jul 14, 2017
ac1c2eb
Release 07-14-2017 (#184)
Jul 14, 2017
010b980
Conversation designer (#178)
v-ducvo Jul 14, 2017
1e3591f
Conversation Designer going live (#188)
Jul 14, 2017
574e013
requires (#186)
johnd-ms Jul 14, 2017
1ce3e76
Merge branch 'master' into live
RobStand Jul 14, 2017
6f6c2c2
Dialog next steps (#177)
v-ducvo Jul 20, 2017
9743606
Release 7-20-2017
RobStand Jul 20, 2017
3361cd6
Sync for release
RobStand Jul 20, 2017
8d30028
Subscribe to bot events, always show bot online (#189)
johnd-ms Jul 20, 2017
ec98458
Changing author alias (#193)
RobStand Jul 20, 2017
b4ec305
links to best current samples, User Story 17067 (#185)
johnd-ms Jul 20, 2017
6c0f28c
Second effort for PR181 (#187)
johnd-ms Jul 20, 2017
9370c54
Groupme screencaps (#191)
johnd-ms Jul 20, 2017
6de5e70
Updates to Slack, GroupMe, sample links, next steps (#194)
Jul 20, 2017
2c3143e
Fixed broken anchor links from table to section in topic. (#195)
v-ducvo Jul 21, 2017
36215da
Adding NoIndex, NoFollow to metadata (#196)
RobStand Jul 24, 2017
2ba2d36
Merge branch 'live' into master
RobStand Jul 24, 2017
5d966b7
Release 7-24-2017 (#197)
RobStand Jul 24, 2017
df7db59
Merge branch 'live'
RobStand Jul 24, 2017
27620f9
Removing broken video
RobStand Jul 26, 2017
88128b2
Update bot-builder-nodejs-cortana-skill.md
Jul 28, 2017
b7400f1
Update bot-builder-nodejs-cortana-skill.md (#198)
Jul 28, 2017
79f5dd8
added dotnet scorable dialogs (#180)
matthewshim-ms Jul 28, 2017
07aafb8
Merge branch 'live' into master
Jul 28, 2017
bf01cb8
Update filenames.md
RobStand Jul 28, 2017
9f42eca
Added entries about the documentation (#206)
RobStand Jul 31, 2017
23fa10d
Slack review (#204)
johnd-ms Aug 1, 2017
229e7ef
Scorable review (#203)
Aug 1, 2017
34ad2cf
Grammar correction. Whose, not Who's (#33)
Jul 24, 2017
3a6f112
Updated to correct version of IISExpress (#35)
deankroker Jul 31, 2017
ab17c93
Update resources-tools-downloads.md (#31)
mschray Aug 1, 2017
2fc82cc
Changed AttachmentLayouts to AttachmentLayoutTypes (#38)
peterkaplan Aug 1, 2017
be39fd3
Release 08-01-2017 (#207)
RobStand Aug 1, 2017
b979a3b
Updating next step
RobStand Aug 1, 2017
0b6fc95
Fixing illegal bookmark usage
RobStand Aug 1, 2017
53a0d6f
Fixing build warning in dotnet reference
RobStand Aug 1, 2017
c1fc1a8
Fixing build warning in dotnet reference
RobStand Aug 1, 2017
346bb26
Staging for fix from nuget release
RobStand Aug 1, 2017
a87b3e1
Cropped out wechat icon. wechat is not supported (#209)
RobStand Aug 2, 2017
f65fd93
Merge branch 'master' into live
RobStand Aug 2, 2017
8334a16
three downloads for one template (#212)
johnd-ms Aug 2, 2017
886333d
Initialize open publishing repository: https://github.com/MicrosoftDo…
RobStand Aug 2, 2017
e65b0ca
Initialize open publishing repository: https://github.com/MicrosoftDo…
RobStand Aug 2, 2017
46db002
Fix for bug# 17564. Add gitter.im, specifically the BotBuilder ROOM (…
johnd-ms Aug 3, 2017
22b7e60
Merge branch 'live' into master
RobStand Aug 3, 2017
998faaa
Release 08-03-2017 (#217)
RobStand Aug 3, 2017
b9e944b
Sync live with master for release
RobStand Aug 3, 2017
0748ceb
17561 deploy from local git (#215)
johnd-ms Aug 4, 2017
b2005b8
add ms.date metadata (#219)
Aug 4, 2017
44e9b64
Fixing search scope
RobStand Aug 5, 2017
20d2a36
Release 08-04-2017 (#221)
RobStand Aug 5, 2017
1a9969c
Merge branch 'live' into master
RobStand Aug 5, 2017
83cbd9c
# 17767: shorten titles to 80 chars for SEO (#220)
Aug 5, 2017
722d5a5
Community content (#223)
RobStand Aug 7, 2017
159b9b1
Configure PDF builds.
Aug 7, 2017
e74c9e5
Update .openpublishing.publish.config.json
Aug 7, 2017
a3b598a
Merge pull request #225 from MicrosoftDocs/master
Aug 7, 2017
91332fb
Merge branch 'live' into live-sync-work
RobStand Aug 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Scorable review (#203)
  • Loading branch information
Kamran Iqbal authored and RobStand committed Aug 1, 2017
commit 229e7ef411211e2acfb87e6208741c0433f2019c
2 changes: 1 addition & 1 deletion articles/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#### [Dialogs overview](~/dotnet/bot-builder-dotnet-dialogs.md)
#### [Manage conversation flow](~/dotnet/bot-builder-dotnet-manage-conversation-flow.md)
#### [Enable language understanding](~/dotnet/bot-builder-dotnet-luis-dialogs.md)
#### [Global message handlers](~/dotnet/bot-builder-dotnet-scorable-dialogs.md)
#### [Scorable dialogs](~/dotnet/bot-builder-dotnet-scorable-dialogs.md)
### FormFlow
#### [Basic features of FormFlow](~/dotnet/bot-builder-dotnet-formflow.md)
#### [Advanced features of FormFlow](~/dotnet/bot-builder-dotnet-formflow-advanced.md)
Expand Down
78 changes: 45 additions & 33 deletions articles/dotnet/bot-builder-dotnet-scorable-dialogs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Global message handlers using Scorables
title: Global message handlers using scorables
description: Create more flexible dialogs using scorables within the Bot Builder SDK for .NET.
author: matthewshim-ms
ms.author: v-shimma
Expand All @@ -8,22 +8,17 @@ ms.topic: article
ms.prod: bot-framework
ms.date: 07/12/2017
---
# Global message handlers using Scorables
# Global message handlers using scorables

Within the Bot Framework .NET SDK, `Scorables` allow you to create dialogs as flexible components which act as global message handlers, in lieu of the traditional dialog model.
Users attempt to access certain functionality within a bot by using words like "help," "cancel," or "start over" in the middle of a conversation when the bot is expecting a different response. You can design your bot to gracefully handle such requests using scorable dialogs.

Scorable dialogs within a bot monitor all incoming messages, and determine wether or not that message is actionable in some way. Messages that are scorable are assigned a score between 0 - 1 (one being the highest) by each scorable dialog in the bot. The scorable dialog which determines the highest score then handles the response to the user.
Scorable dialogs monitor all incoming messages and determine whether a message is actionable in some way. Messages that are scorable are assigned a score between [0 – 1] by each scorable dialog. The scorable dialog that determines the highest score is added to the top of the dialog stack and then hands the response to the user. After the scorable dialog completes execution, the conversation continues from where it left off.

When a user triggers a scorable dialog, that dialogue is then added to the top of the [dialog stack](../bot-design-conversation-flow.md#dialog-stack). After the scorable dialog is resolved, the conversation will continue from where it left off. This allows you to create more flexible conversations by allowing your users to 'interrupt' the normal hierarchal dialog structure.
Scorables enable you to create more flexible conversations by allowing your users to 'interrupt' the normal conversation flow you find in regular dialogs.

>[!NOTE]
> Scorables is one of the ways that the .NET SDK uses [AutoFac](https://autofac.org/). AutoFac is used in the .NET BotBuilder SDK
> for [inversion of control and dependency injection](https://martinfowler.com/articles/injection.html). You can learn more about
> Autofac in this [quick start guide](http://autofac.readthedocs.io/en/latest/getting-started/index.html).
## Create a scorable dialog

## Creating a Scorable dialog

First, you can define a new [dialog](bot-builder-dotnet-dialogs.md). If you've created a bot before, the following example will look very familiar, it is a typical dialog which uses the `IDialog` interface.
First, define a new [dialog](bot-builder-dotnet-dialogs.md). The following code uses a dialog that is derived from the `IDialog` interface.

```cs
public class SampleDialog : IDialog<object>
Expand All @@ -50,7 +45,7 @@ public class SampleDialog : IDialog<object>
}
}
```
To make a dialog scorable, you create a class which provides implementation of the abstract `ScorableBase` class. The `ScorableBase` class implements the `IScorable` interface that's defined in the Scorables class in the Bot Builder SDK for .NET.
To make a scorable dialog, create a class that inherits from the `ScorableBase` abstract class. The following code shows a `SampleScorable` class.

```cs
using Microsoft.Bot.Builder.Dialogs;
Expand All @@ -68,36 +63,55 @@ public class SampleScorable : ScorableBase<IActivity, string, double>
}
}
```
The `ScorableBase` abstract class inherits from the `IScorable` interface. You will need to implement the following `IScorable` methods in your class:

The **ScorableBase** abstract class uses the **IScorable** interface which requires that this class must include the following methods:
- `PrepareAsync` is the first method that is called in the scorable instance. It accepts incoming message activity, analyzes and sets the dialog's state, which is passed to all the other methods of the `IScorable` interface.

```cs
public interface IScorable<in Item, out Score>
protected override async Task<string> PrepareAsync(IActivity item, CancellationToken token)
{
Task<object> PrepareAsync(Item item, CancellationToken token);
// TODO: insert your code here
}
```

bool HasScore(Item item, object state);
- The `HasScore` method checks the state property to determine if the scorable dialog should provide a score for the message. If it returns false, the message will be ignored by the scorable dialog.

Score GetScore(Item item, object state);
```cs
protected override bool HasScore(IActivity item, string state)
{
// TODO: insert your code here
}
```

Task PostAsync(Item item, object state, CancellationToken token);
- `GetScore` will only trigger if `HasScore` returns true. You’ll provision the logic in this method to determine the score for a message between 0 - 1.

Task DoneAsync(Item item, object state, CancellationToken token);
```cs
protected override double GetScore(IActivity item, string state)
{
// TODO: insert your code here
}
```
* **PrepareAsync**: This first method in the scorable instance accepts incoming message activity, analyzes and sets the dialog's `state`, which is passed to all the other methods in the interface.

* **HasScore**: This boolean method checks the state property to determine if the Scorable Dialog should provide a score for the message. If it returns false, the message will be ignored by the Scorable dialog.
- In the `PostAsync` method, define core actions to be performed for the scorable class. All scorable dialogs will monitor incoming messages, and assign scores to valid messages based on the scorables' GetScore method. The scorable class which determines the highest score (between 0 - 1.0) will then trigger that scorable's `PostAsync` method.

* **GetScore**: Will only trigger if `HasScore` returns true, provision the logic here to determine the score for a message between 0 - 1.0
```cs
protected override Task PostAsync(IActivity item, string state, CancellationToken token)
{
//TODO: insert your code here
}
```

* **PostAsync**: In this method you define core actions to be performed for the scorable class. All scorable dialogs will monitor all incoming messages, and assign scores to valid messages based on the scorables' `GetScore` method. The scorable class which determines the highest score (between 0 - 1.0) will then trigger that scorable's `PostAsync` method.
- `DoneAsync` is called after the scoring process is complete. Use this method to dispose of any scoped resources.

* **DoneAsync**: Here you should dispose of any scoped resources as it is called when the scoring process has completed.
```cs
protected override Task DoneAsync(IActivity item, string state, CancellationToken token)
{
//TODO: insert your code here
}
```

## Create a module to register the IScorable service
## Create a module to register the IScorable service

Define a `Module` which will register the `SampleScorable` as a component which provisions the `IScorable` service.
Next, define a `Module` that will register the `SampleScorable` class as a component. This will provision the `IScorable` service.

```cs
public class GlobalMessageHandlersBotModule : Module
Expand All @@ -113,11 +127,9 @@ public class GlobalMessageHandlersBotModule : Module
}
}
```
## Register the module with

Lastly, you need to apply the `SampleScorable` to the bot's Conversation Container. This will register the scorable service within the bot builder framework's message handling pipeline.
## Register the module

Simply update the `Conversation.Container` as shown below within the bot app's initialization in **Global.asax.cs** as shown:
The last step in the process is to apply the `SampleScorable` to the bot's Conversation Container. This will register the scorable service within the Bot Framework's message handling pipeline. The following code shows to update the `Conversation.Container` within the bot app's initialization in **Global.asax.cs**:

```cs
public class WebApiApplication : System.Web.HttpApplication
Expand All @@ -133,7 +145,7 @@ public class WebApiApplication : System.Web.HttpApplication
var builder = new ContainerBuilder();
builder.RegisterModule(new ReflectionSurrogateModule());

//Register the module within the Conversation container
//Register the module within the Conversation container
builder.RegisterModule<GlobalMessageHandlersBotModule>();

builder.Update(Conversation.Container);
Expand Down