# Monday, October 1, 2018
Monday, October 1, 2018 6:55:44 AM (GMT Daylight Time, UTC+01:00)
# Thursday, September 27, 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, September 27, 2018 9:42:00 AM (GMT Daylight Time, UTC+01:00)
# Monday, September 24, 2018
Monday, September 24, 2018 9:38:00 AM (GMT Daylight Time, UTC+01:00)
# Sunday, September 23, 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.

Fig. 1

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

Fig. 2

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

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.

Fig. 4

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

Fig. 5

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

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:

		'directLine': { 'secret': 'DirectLineSecretKey' },
		'user': { id: 'UserId' },
		'bot': { id: 'MicrosoftAppId' },
		'resize': 'detect'
	}, document.getElementById("mybot"));


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

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

Fig. 8

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

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, September 23, 2018 6:25:43 PM (GMT Daylight Time, UTC+01:00)
# Saturday, September 22, 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, September 22, 2018 9:24:00 AM (GMT Daylight Time, UTC+01:00)
# Friday, September 21, 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, September 21, 2018 1:54:00 PM (GMT Daylight Time, UTC+01:00)
# Thursday, September 20, 2018

GCast 14:

Creating an Azure Storage Account

Learn how to create a new Azure Storage account.

Azure | GCast | Screencast | Video
Thursday, September 20, 2018 9:58:00 AM (GMT Daylight Time, UTC+01:00)
# Wednesday, September 19, 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

Fig. 1

The URL takes the following form:


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

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


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

The Kudu page displays as shown in Fig. 2

Fig. 2

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

Fig. 3

Fig. 4

The debug console displays, as shown in Fig. 5

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

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, September 19, 2018 9:47:00 AM (GMT Daylight Time, UTC+01:00)
# Tuesday, September 18, 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

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.

Fig. 2

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

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.

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

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.

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, September 18, 2018 9:34:00 AM (GMT Daylight Time, UTC+01:00)
# Monday, September 17, 2018
Monday, September 17, 2018 9:50:00 AM (GMT Daylight Time, UTC+01:00)