How to enable your Bot Framework bot on Skype for Business (and how I finally got it working!)
Recently at Build 2017, Microsoft announced a new Channel for Bot Framework which would allow bots to communicate on the Skype for Business network.
So, how do you take your existing Bot Framework bot and enable it to work on Skype for Business?
Firstly, this only works for Skype for Business Online. There’s no support yet for hybrid or on-premise environments.
Secondly, you’ll need to have a Bot Framework bot that you want to use. If you’ve never built a bot before, watch my Channel 9 video Getting started with bot development using Microsoft Bot Framework.
For this blog post I’m going to use a bot I have called WhatsHappeningBot. It will tell you what’s hot on the internet, based on some cool work done by the Cognitive Services team (Project Cuzco). I’ve combined this with Luis.ai to allow questions like “what’s happening today”, “what happened last tuesday, “what happened 3 days ago” etc. This is how it looks in Teams:
If you’d like to play with it first before reading on, you can do so below. Try asking it things like ‘whats happening today’, ‘what happened yesterday’, what happened last wednesday’:
Firstly, head over to your Bot Framework dashboard. You’ll notice it looks different – it’s just undergone a visual revamp and so things have moved around a bit. You can see that the channels are now represented as large blocks. You can also see the Skype for Business channel:
Clicking on the Skype for Business icon enables the bot so that it can be used with Skype for Business. There’s nothing to configure, no options to set. On the Bot Framework side we are all done:
However it’s not quite time to party just yet. We have to do some work on the Skype for Business side. Clicking the Learn how link takes you to a dedicated landing page for registering Skype for Business bots. Your bot’s ID is passed as well so that the examples shown are relevant.
Basically you need to register your bot as an endpoint in your Skype for Business online environment. You do this with PowerShell as a tenant admin, using the Skype for Business Online Connector module.
Firstly, authorise to your Skype for Business Online instance (remember you need to login as a tenant administrator):
Import-PSSession (New-CsOnlineSession -Credential (Get-Credential))
Then, to add the new endpoint for your bot, run the New-CsOnlineApplicationEndpoint cmdlet:
New-CsOnlineApplicationEndpoint -ApplicationId 98c256bc-f056-4906-a199-a8c6107c9e58 -Name NameOfTheBot -Uri sip:[email protected]
The -ApplicationId is the Application ID of your bot (when you created a Microsoft App during bot registration) and will be the same as the MicrosoftAppId value in your bot’s web.config
The -Name is the display name shown in the Skype for Business client. The -Uri can be any unused SIP address, and the domain can be any domain you have set up in your tenant, but nothing else (you can’t just choose a @microsoft.com domain for instance!). Also, don’t use capitals or mixed case – it has to be all lower case otherwise you’ll get an error.
If everything goes as planned you’ll see this. It can take a little while for this command to run (like, 30-60 seconds):
It can take a while for this endpoint registration to propagate, so don’t worry if it doesn’t immediately work. During the registration and propagation process, you might see some odd behaviour, such as this, where something is receiving the instant messages but it’s not my bot:
I left it for around 24 hours to allow the propagation process to complete. The first indication that this has happened comes the display name is correctly shown when searching for the SIP address:
However, things still don’t work:
Diagnosing and Fixing the Problem
We’re definitely now in the realm of things that should be working, not working. Rather than just get it working and show screenshots, I think it would be useful to chart what I do next, in case you have a similar issue.
The first thing I did was head over to the Bot Framework Dashboard, and immediately it’s clear that there is a problem:
Clicking on the issues shows me that the requests I’m making are all reaching the framework OK, but are all suffering from the same problem:
I double-checked that the bot still worked using the Test window in the Bot Framework Dashboard. Then, just to make sure, I fired up Application Insights for that Web App. This lets me see the actual requests being made to my service, and indeed I can see that I am returning 401 Unauthorized messages:
But why? The only reason I can think of is that Skype for Business doesn’t have the Bot ID and Secret Key and so doesn’t pass it.
To test this out, I commented out the [BotAuthentication] decorator from the MessagesController class and re-published. This is just for testing and opens up your bot to being accessed by anyone who has the URL – it means that the bot’s Application ID and Secret are not checked. This did however fix the problem and suddenly my messages were being correctly shown in Skype for Business:
There’s a couple of things to note here:
- The situation with the authentication code is clearly not optimal. I will raise this with Microsoft and update once I know more. It might well be something I’m doing wrong and need to configure.
- The presence never changes from ‘Presence Unknown’. This is going to be confusing to users. At a bare minimum, really it should show Available.
- Although the Bot Framework supports Markdown, this is not translated into formatting which Skype for Business understands. You can see how the Markdown code is shown.
- However, HTML links are correctly formatted, which is nice.
So, there you go. This is a very new channel, and there are some hoops to jump through still. However, I think we’ll get those sorted out soon. In the meantime, if you want to use this channel today then make sure you fully understand the risks of disabling the authentication process. If any of this changes, I’ll be sure to update with a new blog post. Edit: I did this here. Also see StackOverflow and GitHub
Try it out yourself – use my bot!
If you’ve read this far, you deserve a prize! I noticed (in testing with Tom Arbuthnot) that although it’s assumed that you would add YOUR bot to YOUR Skype for Business tenant, this isn’t enforced. This means that anyone can add a bot to their Skype for Business tenant.
That’s pretty cool, and means that I can offer you my WhatsHappening bot for you to use in your Skype for Business tenant, simply by running these PowerShell commands as a Skype for Business tenant admin:
Import-PSSession (New-CsOnlineSession -Credential (Get-Credential)) New-CsOnlineApplicationEndpoint -ApplicationId 98c256bc-f056-4906-a199-a8c6107c9e58 -Name WhatsHappening-Uri sip:[email protected]
Just remember to change the -URI value to a lowercase, unused SIP address that’s valid for your domain.
Things you can ask it:
“Whats happening?” (for some reason it doesn’t like apostrophes, still working on that!)
“What happened yesterday?”
“What happened 3 days ago?”
“What happened last friday?”
I’ll keep this running for as long as I can, subject to how quickly it burns through my Azure credit!