{"id":20628657,"url":"https://github.com/thoemmi/skypeforbusinesssample","last_synced_at":"2025-10-15T19:06:54.598Z","repository":{"id":138005735,"uuid":"87235755","full_name":"thoemmi/SkypeForBusinessSample","owner":"thoemmi","description":"This repository demonstrates why the Lync Client SDK is NOT suitable for writing bots for Lync/Skype for Business.","archived":false,"fork":false,"pushed_at":"2017-04-04T21:14:52.000Z","size":1827,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-23T10:32:38.036Z","etag":null,"topics":["bot","lync","skype-for-business","topshelf","windows-service"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thoemmi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-04T21:14:20.000Z","updated_at":"2018-07-19T03:50:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"2b3638e1-6d22-4232-8ea3-e2f4f2fd5186","html_url":"https://github.com/thoemmi/SkypeForBusinessSample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thoemmi/SkypeForBusinessSample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoemmi%2FSkypeForBusinessSample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoemmi%2FSkypeForBusinessSample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoemmi%2FSkypeForBusinessSample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoemmi%2FSkypeForBusinessSample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoemmi","download_url":"https://codeload.github.com/thoemmi/SkypeForBusinessSample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoemmi%2FSkypeForBusinessSample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279103969,"owners_count":26104404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","lync","skype-for-business","topshelf","windows-service"],"created_at":"2024-11-16T13:22:05.231Z","updated_at":"2025-10-15T19:06:54.582Z","avatar_url":"https://github.com/thoemmi.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SkypeForBusinessSample\n\nThis repository demonstrates why the [Lync Client SDK](https://msdn.microsoft.com/de-de/library/office/jj933180.aspx)\nis **not** suitable for writing bots for Lync/Skype for Business.\n\n## Introduction\n\nWe tried to create a bot for Lync/Skype for Business. First we planned to use\nthe server-side interface UCMA ([Unified Communications Managed API](https://msdn.microsoft.com/de-de/library/office/dn465943.aspx)), but the\nconfiguration is far from trivial: you have to call several PowerShell\nscripts, create certificates to get a trusted connection from the Lync\nServer to the API endpoint, and so on. While this would be feasible\nin-house, it's not something we want to bother our customers with. (I can\nonly imagine the amount of calls our support would have to deal with).\n\nHowever, we were recommended to use the [Lync Client SDK](https://msdn.microsoft.com/de-de/library/office/jj933180.aspx)\ninstead. Using the [UI Suppression Mode](https://msdn.microsoft.com/en-us/library/office/jj933224.aspx)\nyou can even run Lync headless, i.e. suppressing its own UI.\n\n## Issues\n\nHowever, it turned out that this approach does not fulfil our needs for\ntwo reasons:\n\n### Size limit of transferred images\n\nIf you use the UI Suppression Mode, you cannot use [`LyncClient.GetAutomation()`](https://msdn.microsoft.com/de-de/library/office/microsoft.lync.model.lyncclient.getautomation_di_3_uc_ocs14mreflyncwpf.aspx).\nInstead you have to encode the image as base64 and send it as a message:\n\n```csharp\npublic static void SendImage(this InstantMessageModality modality, string filepath) {\n    byte[] bytes;\n    if (Path.GetExtension(filepath).ToLowerInvariant() == \"gif\") {\n        bytes = File.ReadAllBytes(filepath);\n    } else {\n        // convert image to GIF\n        using (var image = Image.FromFile(filepath)) {\n            using (var memStream = new MemoryStream()) {\n                image.Save(memStream, ImageFormat.Gif);\n                bytes = memStream.ToArray();\n            }\n        }\n    }\n\n    var data = \"base64:\" + Convert.ToBase64String(bytes);\n\n    var formattedMessage = new Dictionary\u003cInstantMessageContentType, string\u003e {\n        { InstantMessageContentType.Gif, data }\n    };\n\n\n    modality.BeginSendMessage(formattedMessage, modality.EndSendMessage, null);\n}\n```\n\nHowever, messages are strings and as such limited to 64K characters. Because of\nthe base64 encoding, this results in a maximum image size of approx. 50 kB.\n\nUnfortunately, we haven't found any other method in the SDK, which is capable of\nsending larger images. One solution is scale down an image until its base64 \nrepresentation is less than 64 KB, but your image would get blurry, which is\nnot an option for us.\n\n### The Windows account running the bot must be logged in\n\nOur bot is not an desktop application, but should run on a server, unattended.\nIts purpose is to reply to other user's requests. That's what bots are doing.\n\nTherefore we want to run our bot as a Windows service. It all went well using\nthe Lync Client SDK as long as we developed the bot on our machines. However,\nwhen running it on a server without a user being logged on, the bot went\noffline too.\n\nFurther investigation showed this behaviour: The Lync Client SDK does not take\nto the Lync Server directly, but relies on a running `lync.exe` client. And\nthat client in turn relies that the account, in which session the executable\nis running, must have a desktop.\n\nLet me give you an example: the Windows service is running as `DOMAIN\\BotAccount`.\nThe service spawns a `lync.exe`, running as `DOMAIN\\BotAccount` too. That Lync\nclient's presence is online only if `DOMAIN\\BotAccount` has a desktop, i.e.\nis logged on on that machine. As soon as the user `BotAccount` lgs out, the\nLync client changes its state to offline.\n\nThat's another reason why we cannot use the Lync Client SDK: we cannot demand\nour customers to have the bot's account always being logged on. That contradicts\nthe purpose of a server application without any UI.\n\n## Sample application\n\nThe sample application in this repository demonstrates the issues described\nabove.\n\n### Image issue\n\nStart it without any parameter just runs the bot in a console, using the\ncurrent user's account. From another account on another machine send\n`small` to the bot, and it will reply with a small image (6 KB), which\nwill work. If you send `big`, the bot will try to send a large image (1.5 MB),\nwhich will fail. Instead, the bot will behave weird, like constantly changing\nits state from offline to uninitialized and back.\n\n### Session issue\n\nThe application uses [TopShelf](http://topshelf-project.com/) to run as a service.\nFollowing commands are necessary (with elevated privileges):\n\n* `SkypeForBusinessSample.exe install --interactive` to install the Windows\n  service, it will ask for the desired Windows account to run the service as.\n* `SkypeForBusinessSample.exe start` to start the service\n* `SkypeForBusinessSample.exe stop` to stop the service\n* `SkypeForBusinessSample.exe uninstall` for uninstallation\n\n(see TopShelf's [documentation](https://topshelf.readthedocs.io/en/latest/overview/commandline.html)\nfor all command line options)\n\nSo install the service with your own credentials and start it. Test from another\nmachine with a different account to talk to the bot (it will echo any message).\nThen log off from the machine where the bot is running. The bot will go offline\nimmediately and not respond to any message anymore.\n\n## Conclusion\n\nBecause of the limitation described above, the Lync Client SDK is not suitable\nfor writing bots. The Bot Framework SDK does not support Lync/Skype for Business\n(yet), so it seems the only option at the moment is to use the UCMA.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoemmi%2Fskypeforbusinesssample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoemmi%2Fskypeforbusinesssample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoemmi%2Fskypeforbusinesssample/lists"}