# Thursday, 27 September 2018

GCast 15:

Creating an Azure Web App

Azure Web Apps allow you to host your web sites and applications in the cloud. I walk through the steps of setting up an Azure Web App.

Azure | GCast | Screencast | Video | Web
Thursday, 27 September 2018 09:42:00 (GMT Daylight Time, UTC+01:00)
# Monday, 24 September 2018
Monday, 24 September 2018 09:38:00 (GMT Daylight Time, UTC+01:00)
# Sunday, 23 September 2018

The Microsoft Bot Framework makes it easier to create a chatbot. But a chatbot is only good if your users have a way of calling it. Microsoft bots can be accessed via a number of channels, including Facebook Messenger, Microsoft Teams, Skype, Slack, and Twilio.

Bot Settings

Once you have deployed a bot to Azure, you can view its properties in the Azure Portal, as shown in Fig. 1.

Fig01-BotProperties
Fig. 1

Click "Settings" to display the "Settings" blade, as shown in Fig. 2.

Fig02-BotSettingsBlade
Fig. 2

You will need the "Microsoft App ID" value (Fig. 3)

Fig03-MicrosoftAppId
Fig. 3

Copy this value and save it somewhere, such as in a text file. You will need it later.

Bot Channel

Next, create a Channel for your bot. To do this, do the following:

Click "Channels" to display the "Connect to Channels" blade, as shown in Fig. 4.

Fig04-ChannelsBlade
Fig. 4

Click the "Configure Direct Line Channel" icon (Fig. 5) to display the "Configure Direct Line" dialog (Fig. 6)

Fig05-DirectLineChannelIcon
Fig. 5

Fig06-ConfigureDirectLine
Fig. 6

The Secret Keys are hidden by default. Click the "Show" link next to one of them to display this key, as shown in Fig. 7

Fig07-ShowSecretKey
Fig. 7

Copy this value and save it somewhere, such as in a text file. You will need it later.

Click the [Done] button to close the "Configure Direct Line Channel" dialog.

Create Web Page

Now, you are ready to create a web page to allow users to use your chatbot.

The chat functionality is exposed through web services; but you can simplify calling these by using the Web Chat control. The source code for this open source project is here; but you don't need the source code unless you plan to modify or extend it.

Instead, you can link to the JavaScript file from your HTML with the following tag:

<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
  

Add a div to your web page with the id "mybot", as shown below

<div id="mybot"></div>

Then, add the following JavaScript to configure the WebChat client:

<script>
	BotChat.App({
		'directLine': { 'secret': 'DirectLineSecretKey' },
		'user': { id: 'UserId' },
		'bot': { id: 'MicrosoftAppId' },
		'resize': 'detect'
	}, document.getElementById("mybot"));
</script>
  

where:

  • DirectLineSecretKey is from one of the 'Secret Keys' fields of the Bot's Direct Line channel blade, that you copied earlier.
  • MicrosoftAppId is from the 'Microsoft App Id' field of the bot's 'Settings' blade, that you copied earlier.
  • UserId can be any string you like. These will display in the UI next to text submitted by the user.

The WebChat project also provides a stylesheet that you can use by adding the following tag within the <HEAD> tag:

<link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
  

Below is the full HTML and JavaScript with some dummy values for DirectLineSecretKey, user, and MicrosoftAppId.

<!DOCTYPE html>
<html>
<head>
    <title>Cubic Chatbot</title>
    <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
</head>
<body>
    <div id="mybot"></div>
    <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
    <script>
        BotChat.App({
            'directLine': { 'secret': 'pdWb0xfE48M.wcA.dQI.YQgum240I2x9dVGc6S28u5Xik2Xt3A_TakzR24uGgjs' },
            'user': { id: 'Customer01' },
            'bot': { id: 'ac0438dc-a820-40fb-ae87-6448403ed1ad' },
            'resize': 'detect'
        }, document.getElementById("mybot"));
    </script>
</body>
</html>
  

In a browser, this page renders as shown in Fig. 8.

Fig08-BotClient
Fig. 8

Fig. 9 shows how it looks when you connect to a bot that echoes back what the user sends.

Fig09-BotClient
Fig. 9

If you want this control to be displayed within another web page, you can add an iframe to that other page, as below.

<iframe src="botclientpage.html"></iframe>
  

In this article, I showed you how to create a web page that communicates with a Microsoft Bot.

Sunday, 23 September 2018 18:25:43 (GMT Daylight Time, UTC+01:00)
# Saturday, 22 September 2018

TheTwoTowersI wonder if we shall ever be put into songs or tales. We’re in one, of course; but I mean: put into words, you know, told by the fireside, or read out of a great big book with red and black letters, years and years afterwards. And people will say: "Let’s hear about Frodo and the Ring!" And they’ll say: "Yes, that’s one of my favourite stories."
-Samwise Gamgee

The Fellowship formed in the first book has broken. Frodo and Sam are on their way to Mordor to destroy the evil ring, so that the evil Sauron cannot use its power to conquer Middle Earth; Gandalf is presumed dead after falling into an abyss while battling the Balrog; Merry and Pippin have been kidnapped by Orcs - the same Orcs who killed Boromir; and Legolas, Gimli, and Aragorn traverse the land, seeking allies and battling Sauron's forces.

The first half of The Two Towers follows Legolas, Gimli, Aragorn, Merry, and Pippin until they are united. It is filled with epic battles between mighty armies. The second half of the volume chronicles the journey of Frodo and Sam, as they travel across perilous country to Mordor, guided by the twisted Gollom. The dangers they encounter are smaller, but no less perilous. They are attacked by Gollom and by Orcs and by a giant spider.

The theme of this middle volume of The Lord of the Rings trilogy seems to largely deal with decisions in the face of adversity. Boromir wrestles with his loyalty to the Fellowship and his desire to use the powerful ring to defend his country. Gollom literally argues with himself when debating whether to keep promises he made to Frodo or betray him and seize the ring for himself.

The leaders of Middle Earth know that a war is coming, but many of them need to be convinced to take sides. They delay because they wish to remain neutral, which gives an advantage to the aggressor Sauron and his minion Saruman. Since Tolkien lived through World War II, it's hard to imagine he wasn't thinking of all the countries who hesitated to take on Hitler during his pre-war efforts to expand his power.

The Two Towers is a classic adventure story that keeps the reader in suspense throughout. But, like its predecessors The Fellowship of the Ring, it is best read as part of the trilogy. It is parts 3 and 4 of a 6-part series and each of these parts ends with much unresolved. The characters are wonderful, the world is amazing, and the storytelling is epic.

I am enjoying this journey.

Saturday, 22 September 2018 09:24:00 (GMT Daylight Time, UTC+01:00)
# Friday, 21 September 2018

FellowshipOfTheRingOn his eleventy-first birthday, hobbit Bilbo Baggins decided to leave Hobbiton. He did so in dramatic fashion, literally disappearing while giving a speech at his birthday party. Bilbo left most of his belongings to his nephew Frodo, including a magic ring he discovered on a journey years earlier.

Neither Bilbo nor Frodo nor the wizard Gandalf knew that the magic ring was cursed. It was created by the evil Sauron, who has returned to take over all of Middle Earth and who desires the ring's power, which will virtually guarantee his success. When Sauron's minions The Ring Wraiths arrive in the Shire seeking the ring, Frodo and his friends flee, traveling across Middle Earth to Rivendell - a city of elves, where Bilbo has been living. At Rivendell, the wise elves decide that the only way to prevent the ring from falling into Sauron's hands is to destroy it. Sadly, the only way to do this is to throw it into the fiery pits of Mount Doom, located far away in the Mordor - home to Sauron.

So, Frodo sets out for Mordor with his 3 hobbit friends, Gandalf, Gimli the Dwarf, Legolas the elf, and two men: Aragorn and Boromir. Along the way, this "fellowship" is beset by treacherous terrain, fierce monsters, and the betrayal of a friend.

The Fellowship of the Ring begins J.R.R. Tolkien's classic Lord of the Rings trilogy.

It takes place a few years after The Hobbit, in the same world with many of the same characters. But it is much darker in tone.

Tolkien is at his best when he is building a world. By the end of the story, we know the beings who populate Middle Earth, the lands in which they live, the languages they speak, and much of their history. Fellowship is an adventure story, but the action is often interrupted by detailed descriptions of the environment. Those who know the story only through Peter Jackson's excellent movie may be disappointed that the book does not advance as fast.

But the depth of detail provided by Tolkien more than makes up for any pacing issues. The reader feels that he knows this world and these characters and why the ring is so important.

I love Tolkien's writing style, which can be at turns ominous and humorous. At his birthday party speech, Bilbo announces: "I don’t know half of you half as well as I should like; and I like less than half of you half as well as you deserve.", which leaves his guests trying to figure out if this was a compliment.

He mixes in much poetry or songs with his work, some of which is quite good. The prophecy of the Ring is told with the following poem:

"All that is gold does not glitter,
Not all those who wander are lost;
The old that is strong does not wither,
Deep roots are not reached by the frost.
From the ashes a fire shall be woken,
A light from the shadows shall spring;
Renewed shall be blade that was broken,
The crownless again shall be king."

And some of Tolkien's writing just sounds epic in its prose: "One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them."

Although listed as volume 1, this is not as much a first book in a trilogy as it is the first chapters in a very long novel, published in 3 volumes to make it easier to consume and market. You should read this volume knowing full well that it is not a complete story: You are committing to the entire series.

And a wonderful story it is.

Friday, 21 September 2018 13:54:00 (GMT Daylight Time, UTC+01:00)
# Thursday, 20 September 2018

GCast 14:

Creating an Azure Storage Account

Learn how to create a new Azure Storage account.

Azure | GCast | Screencast | Video
Thursday, 20 September 2018 09:58:00 (GMT Daylight Time, UTC+01:00)
# Wednesday, 19 September 2018

An Azure Function App is a good way to deploy code when you don't want the trouble of managing the server on which that code is running. But sometimes, you do want to do something on the server. One example I ran into recently was that I needed to install a node package (in my case, it was azure-storage) for a Function App I had deployed.

Azure provides a way to do this.

Navigate to the Azure Portal and open your Function App. Note the URL of the Function App, as shown in Fig. 1

Fig01-FunctionApp
Fig. 1

The URL takes the following form:

https://functionappname.azurewebsites.net

where functionappname is the name you assigned to the Azure Function App.

Open a new browser tab and navigate to the following URL:

https://functionappname.scm.azurewebsites.net.

where functionappname is the name you assigned to the Azure Function App.

The Kudu page displays as shown in Fig. 2

Fig02-Kudu
Fig. 2

Click the Debug console menu (Fig. 3) and click the CMD menu item (Fig. 4).

Fig03-DebugConsole
Fig. 3

Fig04-DebuigConsoleMenu
Fig. 4

The debug console displays, as shown in Fig. 5

Fig05-CommandConsole
Fig. 5

By default, you should find yourself in the "D:\home" folder. Navigate to the D:\home\site\wwwroot folder, using the following commands as shown in Fig. 6.

cd site
cd wwwroot
  

Listing 1

Fig06-ChangeFolder
Fig. 6

Here you can install node packages required by your functions.

To install azure-storage, I entered the following command:

npm install azure-storage
  

It took a minute or two for the package to install. But when it finished, my functions were able to use code in this package. 

Azure | node
Wednesday, 19 September 2018 09:47:00 (GMT Daylight Time, UTC+01:00)
# Tuesday, 18 September 2018

The Microsoft Bot framework provides the IBotDataStore interface as a mechanism for storing stateful data. When you create a new Bot in Visual Studio, your application is configured by default to store data in memory using the InMemoryDataStore class.

You can see this setup in the following line of the Application_Start() method of  Global.asax.cs :

var store = new InMemoryDataStore();
  

This is fine for testing, but memory is fragile and temporary; so, you will want a more persistent way to store stateful data in production. You can see this by running the app we created in this article.

If we run the bot described in that article, we can connect to it with the Bot Framework Emulator; then, stop and re-start the app and connect again, as shown in Fig. 1

Fig01-StartStopInMemory
Fig. 1

Notice that all the stateful information is reset after the app restarts, because the app memory is flushed.

We can modify the app so that it saves stateful data to something more persistent, like Azure Storage. To do this, we must first create a new Azure storage account.

In the Azure Portal, create a new Storage account (Fig. 2). If you have never created an Azure storage account, you can find instructions here.

Fig02-StorageAccount
Fig. 2

Once the account is created, open the "Access keys" blade, as shown in Fig. 3.

Fig03-StorageAccessKeys
Fig. 3

Copy either of the connection strings and save it. You will need to add it to your application.

In the Bot application, open the web.config file and paste the following anywhere directly inside the <configuration> tag.

<connectionStrings> 
 <add name="BotAzureStorage" connectionString="StorageConnectionString" /> 
</connectionStrings> 
  

where StorageConnectionString is the connection string you copied from the Azure portal.

Open the Global.asax.cs file and find the following line:

var store = new InMemoryDataStore();
  

Replace this line with the following code:

var azureStorageConnectionString 
  = System.Configuration.ConfigurationManager.ConnectionStrings["BotAzureStorage"].ConnectionString; 
var store = new TableBotDataStore(azureStorageConnectionString);
  

Now, compile and run the application.

Use the Bot Emulator to connect to it. Stateful information will now be saved to a Microsoft Azure Storage table named "botdata".

Notice that as you start and stop the app, the stateful data remains the same, as shown in Fig. 4.

Fig04-StartStopAzureTable
Fig. 4

In this article, I showed you how to save stateful data to an Azure Storage table.

You can find this code in the SavingStateToAzureDemo folder of the Bot-Framework-Demos on my GitHub page.  

Tuesday, 18 September 2018 09:34:00 (GMT Daylight Time, UTC+01:00)
# Monday, 17 September 2018
Monday, 17 September 2018 09:50:00 (GMT Daylight Time, UTC+01:00)
# Sunday, 16 September 2018
Altan2018-45 Altan2018-50
Altan2018-52       Altan2018-55

People filled every seat and stood in the back on the 4th floor of the Irish American Heritage Center in Chicago. Some were fans, some musicians, and some were just curious to see and hear Altan.

For over 30 years, Altan has been performing and recording traditional Celtic music and Thursday evening the quartet performed a free concert as part of the World Music Festival.

For over 2 hours, they delighted the audience with music and stories; originals and traditional folk songs; reels, jigs, and ballads.

Each of the musicians - Mairéad Ní Mhaonaigh (lead vocals and fiddle), Ciarán Curran (bouzouki), Dáithí Sproule (guitar and vocals), and Martin Tourish (accordion) - were masterful in their own right. But it was Ni Mhaonaigh who stole the show with her fiery fiddle playing and angelic voice.

The audience clapped along and some danced up the center aisle, Riverdance-style. By the end, we were all smiling. Those who did not know Altan and those who did not know this type of music and those who did not understand the Gaelic lyrics had been won over. And so had I. It may have been the Guinness served in the back of the room, but more likely it was the excellence of the musicians.

More photos

Sunday, 16 September 2018 09:23:00 (GMT Daylight Time, UTC+01:00)
# Saturday, 15 September 2018

IMG_2199Stereophonics are Kelly Jones, Richard Jones, Adam Zindani, and Jamie Morrison. But mostly Kelly Jones. Jones is the lead singer, front man, plays many guitar solos, and writes most of the band's music. This is not to say the rest of the band doesn't contribute. They provided excellent musicianship when the band took the stage at Chicago's Vic Theatre Tuesday night.

IMG_2237Tuesday night, thanks to my friend David, I got my first experience at the Vic and my first experience seeing Stereophonics.

Ramona's Flowers opened with a brief set, playing some solid melodies reminiscent of late 80s alternative rock.

IMG_2250But the theatre was full, and they came to see Stereophonics. The crowd did not just listen. They sang along to almost every song, making their voices heard above the amplification. From my vantage point near the stage, it sounded like Jones had brought a choral along to accompany him.  Stereophonics has a much larger following in the UK than in the US and I heard many British accents in the crowd.

The concert did not disappoint. From their high-energy opening "C'est La Vie" through their 6 encores, the crowd was on its feet most of the night.

IMG_2268They played original songs all night until the very end, when they closed with a rousing rendition of "Sweet Home Chicago", delighting the locals and immigrants in the audience alike.

It was a good experience for me and for the thousands of British expats who packed the theater.

Saturday, 15 September 2018 09:21:00 (GMT Daylight Time, UTC+01:00)
# Friday, 14 September 2018

A chatbot provides an electronic exchange between a user and a computer. For example, each exchange might consist of a question from the user and an answer from the computer or a question from the computer and an answer from the user.

As with most interactions that take place across the Internet, a chatbot is, by default, stateless - meaning it remembers nothing from one exchange to the next.

Often, we would like to remember answers from one question to the next or even from one conversation to the next. If the bot asks a person's name, that name could be used to respond to a question asked later in the same conversation; or even in a different conversation.

This is why we implement State in our bots.

There are two key issues when managing state:

  • What is the scope of the data?
  • Where is stateful information stored?

In this article, we will focus on the first question and store all state data in memory.

What is the scope of the data?

The first question we ask ourselves is: When we save the data, when and where will it be seen?

We have 3 options, corresponding to 3 properties of the context (IDialogContext Interface)

  • ConversationData. Data stored here is available to anyone within the current conversation.
  • PrivateConversationData. Data stored here is available to the current user within the current conversation.
  • UserData. Data stored here is available to the current user in any conversation. This means he/she can come back the next day and the bot will remember his/her data.

Each of the 3 options above is a property of the IDialogContext interface. The context object, which is passed into the MessageReceivedAsync, implements this interface, so we can read and write to the appropriate storage by reading and writing to objects stored in context.

Below is a simple example that reads to and writes from the three different storage options.

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
	var message = await result;
	var channelId = message.ChannelId;
	var conversationId = message.Conversation.Id;
	var userId = message.From.Id;

	var currentTime = DateTime.Now;

	DateTime firstLoginTimeThisConversationAnyUser = DateTime.MinValue;

	context.ConversationData.TryGetValue<DateTime>("FirstLoginTime", out firstLoginTimeThisConversationAnyUser);
	if (firstLoginTimeThisConversationAnyUser == System.DateTime.MinValue)
	{
		firstLoginTimeThisConversationAnyUser = System.DateTime.Now;
		context.ConversationData.SetValue<DateTime>("FirstLoginTime", firstLoginTimeThisConversationAnyUser);
	}

	DateTime firstLoginTimeEverForCurrentUser = DateTime.MinValue;
	context.UserData.TryGetValue<DateTime>("FirstLoginTime", out firstLoginTimeEverForCurrentUser);
	if (firstLoginTimeEverForCurrentUser == System.DateTime.MinValue)
	{
		firstLoginTimeEverForCurrentUser = currentTime;
		context.UserData.SetValue<DateTime>("FirstLoginTime", firstLoginTimeEverForCurrentUser);
	}

	DateTime firstLoginTimeCurrentConversationCurrentUser = DateTime.MinValue;
	context.PrivateConversationData.TryGetValue<DateTime>("FirstLoginTime", out firstLoginTimeCurrentConversationCurrentUser);
	if (firstLoginTimeCurrentConversationCurrentUser == System.DateTime.MinValue)
	{
		firstLoginTimeCurrentConversationCurrentUser = currentTime;
		context.PrivateConversationData.SetValue<DateTime>("FirstLoginTime", firstLoginTimeCurrentConversationCurrentUser);
	}

	var output = $"User: {userId}\nConversation: {conversationId}\nChannel: {channelId}\n\n";
	output += $"A user logged into this converstaion at {firstLoginTimeThisConversationAnyUser}.\n";
	output += $"You first logged into any conversation at {firstLoginTimeEverForCurrentUser}.\n";
	output += $"You first logged into this conversation at {firstLoginTimeCurrentConversationCurrentUser}.";
	await context.PostAsync(output);

	context.Wait(MessageReceivedAsync);
}
  

  Listing 1

Notice that we are checking each time to see if any new data is returned from a name-value pair ("FirstLoginTime"). If nothing is stored in a value, it will return DateTime.MinValue, which signifies an empty date. In this case, we set the value to the current time.

You can test this with the Bot Framework Emulator (available here and described here).

You can download a Visual Studio Solution that uses the code in Listing 1 from the SavingStateDemo of the Bot-Framework-Demos on my GitHub page.

Launch your bot from Visual Studio and connect to it with the Emulator. Type any message into the textbox and press [ENTER], as shown in Fig. 1.

Fig01-BotEmulator1
Fig. 1

You should see information about the user, channel, and conversation; along with the value just stored for the when users (including you) logged into this (or another) conversation. Notice all 3 values are the same because this is your first conversation and you are the first user in this conversation.

Again, type any message in the textbox and press [ENTER]. The values have not changed because they were set as stateful data last time (Fig. 2)

Fig02-BotEmulator2
Fig. 2

You can start a new conversation by clicking the ENPOINT on the left, opening a new tab. Type something into this tab's textbox and press [ENTER] (Fig. 3)

Fig03-BotEmulatorNewConversation
Fig. 3

Notice that the user is the same, but the Conversation ID is different.

Therefore, the bot updated the ConversationData and the PrivateConversationData values, but not the UserData value.

In this article, I showed you how to save stateful data from a conversation using the Microsoft Bot Framework.

Friday, 14 September 2018 09:42:00 (GMT Daylight Time, UTC+01:00)
# Thursday, 13 September 2018

GCast 13:

Azure Media Services: Closed Captioning

Generate and add closed captioning to your video with Microsoft Azure Media Services.

Thursday, 13 September 2018 07:11:00 (GMT Daylight Time, UTC+01:00)
# Wednesday, 12 September 2018

In the previous articles, I showed how to create a new chatbot using the Microsoft Bot Framework and I explained the relevant code in the sample chatbot you created.

In this article, I will show how to extend your bot by adding a new dialog.

Launch Visual Studio and create a new project based on the "Bot Builder Echo Bot", as shown in Fig. 1

Fig01-NewBotProject
Fig. 1

From the Visual Studio menu, select Build | Rebuild Solution.

In the Visual Studio Solution Explorer, right-click the "Dialogs" folder and select Add | Class from the context menu, as shown in Fig. 2.

Fig02-AddClassMenu
Fig. 2

A dialog displays, allowing you to name and add a new class, as shown in Fig. 4.

Fig03-AddClass
Fig. 3

Enter a name for this dialog class. I chose "TimeDialog.cs", because I plan to add code to display the current time. Click the [Add] button to create this class.

An editor with the default code in it displays. The default code is in Listing 1.

namespace MyBotWithDialog.Dialogs
{
    public class TimeDialog
    {
    }
}
  

Listing 1

Above the class declaration, add the [Serializable] tag.

After the class name, add the following to derive from the IDialog interface.

: IDialog<object>

The IDialog interface requires one method: StartAsync. Add this method as shown in Listing 2.

        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }
  

Listing 2

Notice that StartAsync asynchronously calls MessageReceivedAsync, so you will have to add this method, as shown in Listing 3.

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            // Calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // Return our reply to the user
            await context.PostAsync($"The time is now {System.DateTime.Now}!");

            context.Wait(MessageReceivedAsync);
        }
  

Listing 3

Note that the output sent back to the channel is a string containing the current time.

Finally, you will need to add using statements at the top to resolve any errors. Add the following to the top of the file.

using Microsoft.Bot.Builder.Dialogs;

using Microsoft.Bot.Connector;

Listing 4

When you are finished, the class should look like Listing 5 below.

using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;

namespace MyBotWithDialog.Dialogs
{
    [Serializable]
    public class RootDialog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            // Calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // Return our reply to the user
            await context.PostAsync($"The current time is {System.DateTime.Now}!");

            context.Wait(MessageReceivedAsync);
        }
    }
}
  

Listing 5

Next, modify the controller to point to your new Dialog. Open MessageController.cs and find the following line of code.

await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());

Replace this line with the following:

await Conversation.SendAsync(activity, () => new Dialogs.TimeDialog());

Now, build and run your bot. When it loads, use the Bot Framework Emulator (available here and described here) to test it.

Connect to your Bot from the Emulator and enter any text in the "Type your message" textbox and press ENTER.

The bot should respond by displaying the current date and time, as shown in Fig. 3.

Fig04-BotFrameworkEmulator
Fig. 4

In this article, I showed how to create and use a new Dialog class to an Bot Builder Echo Bot project. You can find this code in the NewDialogDemo of the Bot-Framework-Demos on my GitHub page.

Wednesday, 12 September 2018 09:41:00 (GMT Daylight Time, UTC+01:00)
# Tuesday, 11 September 2018

An Azure storage account gives you the ability to create, store, and manage tables, queues, blobs, and files.

Azure Storage Services

Available Azure storage services are:

Blobs

A blob is any unstructured or semi-structured object that you want to store. Examples include videos, images, and text files. Blob storage is flexible for storing an object without the system having to know much about the object.

Files

Azure Files allow you to store files to Azure and access them as a file share using the standard SMB protocol. Files are built on top of Azure Blob Storage.

Tables

Azure Table Storage provides a simple NoSQL database for your application. Data in an Azure Table is stored as rows. Each row contains a key and one or more properties. You do not need to pre-define these properties beforehand and you can define different properties for different rows in the same table.

Queues

A queue is a popular mechanism for designing asynchronous applications. One application can drop a message onto a queue and another application can pick up that message later and process it. This decoupling allows for scalability, flexibility, and faster response times.

Creating an Azure Storage Account

To create a new Azure Storage Account, navigate to the https://portal.azure.com.

Click the [Create a resource] button; then select Storage | Storage account - blob, file, table, queue from the menu, as shown in Fig. 1

Fig01-NewResource
Fig. 1

The New Storage Account blade displays, as shown in Fig. 2.

Fig02-NewStorage
Fig. 2

At the "name" field, enter a unique name for your storage account. You will be able to access this account through a REST API by sending requests to

https://accountname.core.windows.net

where accountname is the name you enter for your account.

At the "Deployment model" radio button, select "Resource manager".

At the "Account kind" dropdown, select "Storage (general purpose)"

At the "Location" dropdown, select a location in which to create your account. To minimize latency, you should create an account either near you or near the users and applications that will access the data in this account.

At the "Resource Group" field, click the "Create new" link to display the "Create Resource Group" dialog, as shown in Fig. 3.

Fig03-NewResourceGroup
Fig. 3

Enter a unique name for your new resource group and click the [OK] button to close the dialog and return to the previous blade.

Review your Storage Account settings and click the [Create] button to create your new storage account.

After a few seconds, you will be able to access the properties of your Storage Account, manage the account, and connect to the account.

The "Overview" tab (Fig. 4) displays information about the account, along with links to create and manage Blobs, Files, Tables, and Queues.

Fig04-StorageOverview
Fig. 4

Click the "Blobs" link in the "Services" section of the "Overview" tab to create and manage blobs and containers, as shown in Fig. 5.

Fig05-BlobsBlade
Fig. 5

Click the "Files" link in the "Services" section of the "Overview" tab to create and manage files, as shown in Fig. 6.

Fig06-FilesBlade
Fig. 6

Click the "Tables" link in the "Services" section of the "Overview" tab to create and manage tables , as shown in Fig. 7.

Fig07-TablesBlade
Fig. 7

Click the "Queues" link in the "Services" section of the "Overview" tab to create and manage queues, as shown in Fig. 8.

Fig08-QueuesBlade
Fig. 8

Azure Storage gives you many option for storing data in the cloud.

Tuesday, 11 September 2018 09:37:00 (GMT Daylight Time, UTC+01:00)
# Monday, 10 September 2018
Monday, 10 September 2018 09:29:00 (GMT Daylight Time, UTC+01:00)
# Sunday, 09 September 2018

I may be the last person in America to see Billy Joel in concert. Despite not releasing an album in over two decades, Joel tours almost constantly, routinely filling stadiums and arenas. Recently, he performed a record 100th time at Madison Square Garden alone.

And Friday night, he performed for the seventh time at Wrigley Field in Chicago - also a concert record for this venue.

And I was there.

IMG_2164I bought my first Billy Joel album ("The Stranger") in 1977 and played it until the grooves ran out. It was one of the first albums I bout and I memorized every song. Joel must have known I was coming because he played six songs ("Movin' Out (Anthony's Song)", "Scenes from an Italian Restaurant", "Vienna", "Only the Good Die Young", and "She's Always a Woman") from "The Stranger". Interestingly, he did not play "Just the Way You Are", one of the biggest hits of the year.

In fact, he drew from nearly every one of his 12 studio albums. With 33 Top 40 hits and 23 Grammy nominations, he could not play all his hits; but he did play for two and a half hours, delighting a full crowd at the baseball stadium. He combined big hits like

and a surprising aria written by Puccini and sung by his guitarist Mike DelGuidice. Joel also brought background singer Crystal Taliefero to the front to sing "RESPECT" an Otis Redding composition made famous by the late Aretha Franklin.

He left the audience feeling appreciated by not only mentioning Chicago, but by playing parts of Sinatra's "Chicago (My Kind of Town)" twice during his set. His drummer wore a Cubs jersey and shouted "Good luck in the playoffs!" as he left the stage.

For me, the highlights were a moving rendition of "New York State of Mind", a song I've always believed that Joel never got enough credit for; and "River of Dreams" featuring its complex rhythms - a song Joel surprised us with after a series of pop songs in the 1980s.

Everyone sang along and rocked back and forth as the piano man sang his classic "Piano Man" before bowing and waving Good Night. But, of course he returned to the stage and delivered 4(!) upbeat songs for his encore.

Two and a half hours is a long time for anyone to play, particular for a singer in his 60's; but Billy Joel's voice sounds as strong as ever. And his piano playing is still outstanding. And with a solid group of musicians behind him, the crowd left satisfied.

And now that I've seen Billy Joel, I suppose that everyone has.

Sunday, 09 September 2018 07:01:00 (GMT Daylight Time, UTC+01:00)
# Saturday, 08 September 2018

The Microsoft Bot Framework provides a template that creates a simple bot: The "Bot Builder Echo Bot". It is named this because it echoes back any text you send it, along with the length of that text.

The bot is simply an ASP.NET Web API application that exposes web services to Channel clients. As such, it uses the default routing for Web API applications of "api/controllername"

where controllername is the name of the Controller class with the word “Controller” removed.

A channel will submit an HTTP POST to a URL containing "api/message", which will call the Post method in the MessagesController class. Let's take a look at this class.

    [BotAuthentication]
    public class MessagesController : ApiController
    {
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
        {
            if (activity.GetActivityType() == ActivityTypes.Message)
            {
                await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }

        private Activity HandleSystemMessage(Activity message)
        {
            string messageType = message.GetActivityType();
            if (messageType == ActivityTypes.DeleteUserData)
            {
                // Implement user deletion here
                // If we handle user deletion, return a real message
            }
            else if (messageType == ActivityTypes.ConversationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels
            }
            else if (messageType == ActivityTypes.ContactRelationUpdate)
            {
                // Handle add/remove from contact lists
                // Activity.From + Activity.Action represent what happened
            }
            else if (messageType == ActivityTypes.Typing)
            {
                // Handle knowing that the user is typing
            }
            else if (messageType == ActivityTypes.Ping)
            {
            }

            return null;
        }
  

Listing 1

A channel posts an activity to the service. If the activity type is anything other than "Message", it calls the HandleSystemMessage method. Notice that nothing is actually implemented in this method. You will have to write this yourself.

However, if the activity type is "Message", the Post method asynchronously calls the Dialogs.RootDialog class. Here is that class:

    [Serializable]
    public class RootDialog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            // Calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // Return our reply to the user
            await context.PostAsync($"You sent {activity.Text} which was {length} characters");

            context.Wait(MessageReceivedAsync);
        }
    }
  

Listing 2

The StartAsync method is called first, which waits for a message to be completely received; then, calls the MessageReceivedAsync method.

This method reads the text of the activity and forms a string that contains the original message text and the length of that text. It then Posts this back to the channel with the line below:

await context.PostAsync($"You sent {activity.Text} which was {length} characters");

Finally, it waits for the next message to come in via the following line

context.Wait(MessageReceivedAsync);

The rest of this project is Web API plumbing, setting up things like routing and where to store state information.

As you can see, this is a fairly simple architecture built on an established framework (Web API). This makes it easier to understand and to modify.

This simple bot is a good starting place that demonstrates the structure of a bot. You can modify this dialog, add new dialogs, or modify the logic as suits your purposes.

Saturday, 08 September 2018 09:15:00 (GMT Daylight Time, UTC+01:00)
# Friday, 07 September 2018

Microsoft Visual Studio makes it very simple to create a new bot with the Microsoft Bot Framework.

Launch Visual Studio 2017 (You can download a free version here)

From the menu, select File | New | Project.

The "New Project" dialog displays, as shown in Fig. 1.

Fig01-NewProjectDialog
Fig. 1

Create a new "Bot Builder Echo Bot" project. From this dialog, you find this template by either expanding Visual C# | Bot Framework in the navigation tree on the left; or by entering "Bot Builder" in the search box at the top right.

Enter a name and location for your project and click the [OK] button.

When the project loads, select Build | Rebuild Solution from the menu to compile the solution and validate all references.

This simple bot receives a message and echoes back the same message, along with the length of that message. The relevant code is in the MessageReceivedAsync method of the RootDialog class, which is shown in Listing 1.

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
  var activity = await result as Activity;

  // Calculate something for us to return
  int length = (activity.Text ?? string.Empty).Length;

  // Return our reply to the user
  await context.PostAsync($"You sent {activity.Text} which was {length} characters");

  context.Wait(MessageReceivedAsync);
}
  

Listing 1

After the solution is rebuilt, select Debug | Start Debugging from the menu to launch the bot. This will host a web service and a web page on your local machine. The web page will display in your browser, as shown in Fig. 2.

Fig02-BotRunning
Fig. 2

Note the URL of this page, which will look something like

http://localhost:nnnn/

where nnnn is the port number on which this web application is running.

You can call the bot's web service from many sources; but the easiest way to test it is with the Bot Framework emulator. You can find detailed information on this emulator here. You can download the latest version of the emulator from here, as shown in Fig. 3.

Fig03-DownloadBotFramework
Fig. 3

Download and run the most recent EXE file from this site to install the emulator on your local PC.

Launch the emulator to view the form shown in Fig. 4.

Fig04-BotFrameworkEmulator
Fig. 4

Click the [Open Bot] button on the "Welcome" tab of the emulator. A JSON file containing configuration about your bot was created for you and saved in the Visual Studio project folder. Its root name will be the same as the project, but it will have a ".bot" extension. Select this file and click the [Choose file] button, as shown in Fig. 5.

Fig05-OpenBotConfiguration
Fig. 5

The format of this file looks like the sample in Listing 1.

{
  "name": "MyBot",
  "secretKey": "",
  "services": [
    {
      "appId": "",
      "id": "http://localhost:3978/api/messages",
      "type": "endpoint",
      "appPassword": "",
      "endpoint": "http://localhost:3978/api/messages",
      "name": "MyBot"
    }
  ]
}
  

Listing 2

NOTE: When you return to the emulator, you can click the [Open Bot] button or click a shortcut link below the button to re-load the configuration.

After you save (or open) a configuration file, a "Live Chat" tab displays in the emulator, as shown in Fig. 6

Fig06-BotEmulatorRunning
Fig. 6

To test the bot, type a message into the "Type your message" textbox and press [ENTER]. Your message will display. A short time later, a response will display with your message, followed by the number of characters.

You can find this code in the SimpleBotDemo project of the Bot-Framework-Demos on my GitHub page.

In future articles, I will show you how to enhance your bot, deploy it to a public site, such as Azure, and call it from a variety of clients. But this is the simplest way to create, run, and test a bot.

Friday, 07 September 2018 09:05:00 (GMT Daylight Time, UTC+01:00)
# Thursday, 06 September 2018

GCast 12:

Azure Media Services: Live Streaming

Learn how to Upload, Encode, and Share a Video using Azure Media Services.

Thursday, 06 September 2018 09:22:00 (GMT Daylight Time, UTC+01:00)
# Wednesday, 05 September 2018

The Bots are taking over.

A chatbot is an automated process that can respond to questions or commands via voice or text. They are useful for simulating a conversation and handling some of the tasks that would ordinarily require a call center staffed with people. Uses include processing orders, checking status, and answering questions. If you can understand the question and figure out the answer, you can probably write a chatbot to handle it.

Advantages of Chatbots

Chatbots have some advantages over human interactions.

Operating Cost. Labor costs tend to be among the highest cost of any business and operators in a call center can be expensive. Once deployed, a chatbot's cost tends to be a fraction of the cost of paying a person.

Availability. Chatbots can scale up to increase demand, so that users, customers, and potential customers do not need to wait for the next available operator. If activity rises unexpectedly, it is far easier and faster to deploy new resources to support a chatbot than it is to bring in more people to answer calls.

Speed. A computer can often look up information much faster than a human can.

Flexibility. A chatbot can be wired up to a variety of communication channels, allowing you to use the same code base to connect to different clients in different ways. For example, you can write a chatbot and connect to users via Facebook, SMS, a web page, or any number of other platforms.

Disadvantages of Chatbots

Of course, chatbots will not solve all your problems. Here are some disadvantages.

Startup cost. There tends to be a larger startup costs for chatbots. They must be programmed, tested, and deployed. This cost is only justified if they will yield sufficient savings over the lifetime the chatbot is deployed. Tools like the Microsoft Bot Framework can reduce development time; but that early cost still exists.

Impersonal. Chatbots are not people and some customers prefer talking to a human being over talking to a machine. The cost of human interaction is worth it when you wish to cultivate a personal relationship with your customer or partner. 

Too human. With advances in natural language processing, it can be difficult for people to determine whether they are interacting with a person or a computer. Some people are turned off by this ambiguity. They feel cheated when a computer represents itself as a person.

Real-time flexibility. For many interactions, it is impossible to anticipate every potential question or command from your customers. Humans can react to these very well. Generally, you need to program a chatbot to anticipate each question or command.

Finally

There is no question that chatbots are becoming more and more important as companies interact with their customers. But how your company uses them can determine how successful your chatbot strategy is.

Some scenarios call for starting an interaction with a chatbot; then bringing in a person only if the chatbot cannot adequately help the customer.

Understanding the needs of your customer and the problem you are trying to solve is a key to effective use of chatbots.

Wednesday, 05 September 2018 09:02:00 (GMT Daylight Time, UTC+01:00)
# Tuesday, 04 September 2018

BraveNewWorldThroughout history, many societies have enforced a caste system, kept in place by either top-down authority or socialization that convinces people it is the proper order.

In Aldous Huxley's dystopian future, the caste system is maintained by defining each individual's level prior to his or her birth and conditioning that person to accept that level. The conditioning begins immediately after birth with repeated messages and chemicals to influence what environmental conditions they will like or detest. Some conditioning even occurs before birth. Embryos destined to perform menial labor are poisoned enough to stunt their mental capacities, so they will not aspire to more.

The casts are labeled with the first 5 letters of the Greek alphabet: Alpha, Beta, Gamma, Delta, and Epsilon. At the top of the system are the Alphas, who enjoy a relatively large amount freedom. At the bottom are the Epsilons, who perform the most menial tasks.

All the people are kept distracted by mindless entertainment; by the encouragement of promiscuity; and by the consumption of euphoria-inducing drugs.

Everyone in this Brave New World accepts their level, because they have been conditioned since birth to do so. Well, almost everyone.

Alpha citizen Bernard Marx recognizes that humans have sacrificed elements of their humanity for a general feeling of contentment. He resents the shallowness of everyone around him. Of course, he is shunned by his peers for this.

When Bernard travels to an Indian reservation (now called a "Savage Reservation"), he finds a society outside the drug-numbed control of the government. He also finds Linda - a former Beta woman trapped in the reservation years ago when she was separated from her Alpha companion. Linda now has a son John, the offspring of her and her Alpha. John who knows he is different from the other reservation children, but he has nothing to which he can compare his life. Linda and John are ostracized by the people of the reservation. Linda's promiscuity is at odds with the beliefs of the locals. The women hate her for sleeping with their husbands and the men ridicule her, but still have sex with her.

Bernard brings Linda and John back to his world, where conflict results almost immediately. Linda retreats into the escapism of the freely-available drugs; John falls in love with a woman but is repulsed by her aggressive sexual advances.

For such a short novel, Huxley packs a great deal.

Religion and God have been abolished; yet, people revere Henry Ford as a god-like figure. He is given credit for the technological advances that brought society to its current state. People have common expressions like "Our Ford" and "His Fordship", and they long ago converted all crosses into T's in honor of Ford's famous Model T car. They have even convinced themselves that Sigmund Freud was a pseudonym for Henry Ford, giving him credit for all of Freud's psychology writings.

Henry Ford's influence is obvious in this world. The ultra-efficient in-vitro birthing center resemble the assembly lines of Ford's automobile factories.

It's not surprising the government has encouraged the worship of science over worship of God. All science is controlled by the government and released or manipulated to maintain contentment among the populace.

And that is what Brave New World is about. The people have chosen contentment and happiness over liberty, freedom, individualism, free will - anything that would make them human and allow them control over their own lives. Those in power support this to maintain their power. Authority is maintained by distraction, rather than by force.

In this world, people and entertainment are mass-produced. People seek contentment, but never challenge themselves and the government likes it that way. Citizens question nothing because they are distracted by sex and drugs and mindless media.

There is no love; No marriage; No families; No commitment. There is only a seeking of pleasure and most have accepted that. Art, literature, and philosophy, and religion are gone. Even science is stunted by the goals of those in power. Labor saving devices are suppressed if they would provide too much leisure to the working class.

We see some of this today. People ignore abuses of the government if the stock market rises.
Mind-numbing reality shows and situation comedies and other recreations fill our free time and distract us from thinking about the real problems of the world.

It is this idea of the struggle between individual liberty and acceptance of society and its rules that form the focus of this book. It is about how the state can influence us without our knowledge.

The characters and the story are simply a mechanism for driving home this concept. The reader expects that Bernard will be the story's hero, because he questions the morality of the order of this world early in the book. But eventually, Bernard embraces society's mores when his fellow Alphas finally praise him for bringing John the savage for them to ogle. In the end, it is John who provides an outside perspective on the dominant society of Brave New World.

Brave New World is often compared with 1984, written by Huxley's contemporary George Orwell, who also predicted a dystopian society controlled by the state. But Orwell's government ruled through fear, while Huxley's overlords ruled by keeping the people happy and distracted.

I found Brave New World a chilling parable of society that could exist - a world that in many ways we are heading toward now.

"And that," put in the Director sententiously, "that is the secret of happiness and virtue–liking what you've got to do. All conditioning aims at that: making people like their unescapable social destiny."

Tuesday, 04 September 2018 20:54:00 (GMT Daylight Time, UTC+01:00)
# Monday, 03 September 2018
# Sunday, 02 September 2018

9/2
Today I am grateful to John for loaning me a necktie when I forgot to bring one.

9/1
Today I am grateful I was able to celebrate Kara and Christian's wedding with them  yesterday.

8/31
Today I am grateful to the bank employee, who unlocked the door when she saw me walking up yesterday, even though it was a minute after closing time.


8/30
Today I am grateful to have Nick visit for a few days.

8/29
Today I am grateful for lunch with Donovan yesterday.

8/28
Today I am grateful to visit the Adler Planetarium for the first time yesterday.

8/27
Today I am grateful my coffee machine is fixed after a weeklong nightmare.

8/26
Today I am grateful for:
-Lunch with Dan and his friends yesterday
-My first visit to the Irish American Heritage Center last night

8/25
Today I am grateful for 24 hours in southwest Michigan.

8/24
Today I am grateful for a walk around North Lake Park in Stevensville yesterday.

8/23
Today I am grateful for a long bike ride yesterday.

8/22
Today I am grateful my son saw me speak at a user group for the first time.

8/21
Today I am grateful for dinner and drinks last night with Suzanna and Paul.

8/20
Today I am grateful for lunch with Tim yesterday.

8/19
Today I am grateful to attend the Evanston Art & Fork Festival last night.

8/18
Today I am grateful for breakfast yesterday with Debbie and Diane.

8/17
Today I am grateful to see Electric Light Orchestra in concert last night and to reconnect with old friends.

8/16
Today I am grateful to present at a user group last night for the first time in 5 months.

8/15
Today I am grateful to see Stacy Keach at the Goodman Theatre last night.

8/14
Today I am grateful that a bunch of people responded yesterday to the emails I sent last week.

8/13
Today I am grateful for a walk along Loyola Beach yesterday.

8/12
Today I am grateful for a visit from Doug and Sherree and Sterling and Dylan this weekend.

8/11
Today I am grateful to attend an exciting Cubs-Nationals game yesterday.

8/10
Today I am grateful for late-night beers with Ondrej

8/9
Today I am grateful to attend Sarah's Going-Away party last night.

8/8
Today I am grateful for an annual physical exam yesterday.

8/7
Today I am grateful to attend a celebration last night for Girl Develop It - Chicago.

8/6
Today I am grateful for my new Echo Dot.

Sunday, 02 September 2018 16:33:59 (GMT Daylight Time, UTC+01:00)