Pages Menu
TwitterRssFacebook

Posted by on May 21, 2017 in Bot Framework, Skype for Business® (Lync®)

How to enable your Bot Framework bot on Skype for Business (and how I finally got it working!)

How to enable your Bot Framework bot on Skype for Business (and how I finally got it working!)

There’s a part 2 of this blog post, which fixes the authentication problems described below.

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?

Spoiler: if you just want to run a bot, any bot, on your Skype for Business network to see what it looks like, jump right to bottom of the post, you can use my bot for free!

Prerequisites

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’:

Configuration

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

Depreciated blog content! This issue is now fixed and described in part 2 of this blog article. However, I’m leaving the original here in case someone stumbles across it and it’s useful in 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!

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

12 Comments

  1. Thanks for posting this and share the experience. One possible reason is that the SFB channel need bot builder SDK >= 3.5 so you will be able to fetch the cert for oauth signature validation.
    Please contact me at below email address for further discussion on this issue.

  2. Thanks a ton for sharing this!

    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.

    This helped me to progress. Especially lowercase tip.

  3. Hey! Thank you very much for this post!
    It’s 1000% better than the MS explanations!
    Right now, I’ve just added the endpoint to my SFB, so… I have to wait to see if everything goes well.
    I’ll let you know

  4. hi Tom thanks for sharing this. i was trying to redo what you have done.
    but when i run this command “New-CsOnlineApplicationEndpoint -ApplicationId 98c256bc-f056-4906-a199-a8c6107c9e58 -Name NameOfTheBot -Uri sip:[email protected]

    i got an error. and i couldn’t figure out what’ wrong with this.
    by the way I have bought the O365 Package service i don’t think there is anything which i don’t have.

    Below is the error i got.please refer.

    Enterprise voice directory service failed.
    + CategoryInfo : NotSpecified: (Microsoft.Rtc.M…Directory service discovery failed. Please try again later.:PlatformServiceCmdletException) [New-CsOnlineApplicationEndpoint], BvdCmdletException
    + FullyQualifiedErrorId : Could not instantiate TrustedApplicationEndpointManager,Microsoft.Rtc.Management.Hosted.PlatformService.NewPlatformServiceAppEndpointConfigCmdlet
    + PSComputerName : admin0g.online.partner.lync.cn

  5. Hello Tom! this is well documented .. I was able to add the SFB channel after much struggle ..I still have an issue why I don’t see the bot online? it works perfectly it would be great if I can change the status online.

  6. What is meant by an ‘unused’ SIP address? That is where my confusion is coming from. I am at the point to run the command that adds the bot to SFB and am giving a -Uri of a new user I created. The user has not setup their own password or anything. Any guidance would be so appreciated!

  7. Hi Tom,
    i try to register my bot and i receive an inner error while the registration works if i try to use your bot. My question is: when it register the bot in skype for business it do a sort of “ping” for the bot to verify it’s alive? In that case how you register the azure function that act as outbound message in your other example?
    Thanks Ugo

  8. Hi Tom,
    I try to register my bot using the procedure but it doesn’t work and it receive an error while it works perfeclty using your bot. The only difference is in the app id. My question is: the registration procedure do any check to verify if the bot is alive? If so how do you register the azure function bot that you use in an other example for outbound messages?
    Thanks Ugo

  9. How can i change name of bot after sometimes
    in your case it’s now ‘WhatsHappening’ but after sometime, i have to change it to ‘WhatshappeningNow’
    How do you change it?

  10. Hi Tom, great post, thanks for sharing this! I have two questions though:

    1. Did the bot automatically appear among your contacts once you added it through the console? Or did you still have to search for the bot in Skype for business?

    2. It looks that the status and the avatar do not update? Is it normal that the bot status is “presence unknown” rather than “Online”? Is there anything we can do about it?

  11. i am trying to add bot to the existing users in office 365.but it does not work.for only newly created users,bot was added to that user in office 365.can i overcome this problem?

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.